-
Notifications
You must be signed in to change notification settings - Fork 48
Allow running non-deterministic MDX stanzas using dune-gen
#366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Leonidas-from-XIV
merged 6 commits into
realworldocaml:main
from
Leonidas-from-XIV:dune-gen-non-deterministic
Jan 28, 2022
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6ffa3bb
Test case to see whether non-deterministic mode is applied correctly
Leonidas-from-XIV cb283d1
Run non-deterministic tests depending on `MDX_RUN_NON_DETERMINISTIC`
Leonidas-from-XIV 3c8a9db
Add changelog entry
Leonidas-from-XIV a83ced2
Simplify test build
Leonidas-from-XIV 45e2468
Replace shelling out to `diff` by helper program
Leonidas-from-XIV 122e46b
Make the helper a bit simpler to read and close handles properly
Leonidas-from-XIV File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| (* small helper to determine whether two files differ *) | ||
|
|
||
| type comparison = Same | Different | ||
|
|
||
| let rec compare first second = | ||
| match input_line first with | ||
| | first_line -> ( | ||
| match input_line second with | ||
| | second_line -> | ||
| match String.equal first_line second_line with | ||
| | true -> compare first second | ||
| | false -> | ||
| (* we found a difference between the lines *) | ||
| Different | ||
| | exception End_of_file -> | ||
| (* the second file ended before the first *) | ||
| Different) | ||
| | exception End_of_file -> | ||
| (* the first file ended first *) | ||
| match input_line second with | ||
| | _ -> | ||
| (* the second file continues: a difference *) | ||
| Different | ||
| | exception End_of_file -> | ||
| (* the second file ended too *) | ||
| Same | ||
|
|
||
| let main () = | ||
| let first = Sys.argv.(1) |> open_in in | ||
| let second = Sys.argv.(2) |> open_in in | ||
| let comparison = compare first second in | ||
| close_in first; | ||
| close_in second; | ||
| match comparison with | ||
| | Same -> | ||
| prerr_endline "The files appear to be identical"; | ||
| (* we didn't find a difference, exit with a failure code *) | ||
| exit 1 | ||
| | Different -> () | ||
|
|
||
| let () = | ||
| main () |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| (rule | ||
| (with-stdout-to | ||
| dune_gen.ml | ||
| (run ocaml-mdx dune-gen))) | ||
|
|
||
| (executable | ||
| (name dune_gen) | ||
| (modules dune_gen) | ||
| (modes byte) | ||
| (libraries mdx.test)) | ||
|
|
||
| (rule | ||
| (with-stdout-to | ||
| dune-mdx-nondeterministic.deterministic | ||
| (run ./dune_gen.exe %{dep:dune-mdx-nondeterministic}))) | ||
|
|
||
| (rule | ||
| (setenv | ||
| MDX_RUN_NON_DETERMINISTIC | ||
| 1 | ||
| (with-stdout-to | ||
| dune-mdx-nondeterministic.nondeterministic | ||
| (run ./dune_gen.exe %{dep:dune-mdx-nondeterministic})))) | ||
|
|
||
| (rule | ||
| (alias runtest) | ||
| (action | ||
| (diff dune-mdx-nondeterministic.expected | ||
| dune-mdx-nondeterministic.deterministic))) | ||
|
|
||
| ;; make sure the non-deterministic is different from the deterministic | ||
|
|
||
| (executable | ||
| (name different) | ||
| (modules different)) | ||
|
|
||
| (rule | ||
| (alias runtest) | ||
| (action | ||
| (run ./different.exe %{dep:dune-mdx-nondeterministic.expected} | ||
| %{dep:dune-mdx-nondeterministic.nondeterministic}))) |
18 changes: 18 additions & 0 deletions
18
test/bin/mdx-dune-gen/misc/non-deterministic/dune-mdx-nondeterministic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| This test checks whether the non-deterministic mode works with the `dune` `mdx` | ||
| stanza. | ||
|
|
||
| Deterministic stanzas should get run and corrected, as for 1 plus one is not 3: | ||
|
|
||
| ```ocaml | ||
| # 1 + 1;; | ||
| - : int = 42 | ||
| ``` | ||
|
|
||
| Non-deterministic ones should not be updated, since whatever `Random` outputs | ||
| should be random: | ||
|
|
||
| <!-- $MDX non-deterministic=command --> | ||
| ```ocaml | ||
| # Random.int 1000;; | ||
| - : int = 42 | ||
| ``` |
18 changes: 18 additions & 0 deletions
18
test/bin/mdx-dune-gen/misc/non-deterministic/dune-mdx-nondeterministic.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| This test checks whether the non-deterministic mode works with the `dune` `mdx` | ||
| stanza. | ||
|
|
||
| Deterministic stanzas should get run and corrected, as for 1 plus one is not 3: | ||
|
|
||
| ```ocaml | ||
| # 1 + 1;; | ||
| - : int = 2 | ||
| ``` | ||
|
|
||
| Non-deterministic ones should not be updated, since whatever `Random` outputs | ||
| should be random: | ||
|
|
||
| <!-- $MDX non-deterministic=command --> | ||
| ```ocaml | ||
| # Random.int 1000;; | ||
| - : int = 42 | ||
| ``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.