Skip to content

Commit 45e2468

Browse files
Replace shelling out to diff by helper program
This should be more portable since we don't depend on `diff` being installed or have an exit code of 1 when the files differ.
1 parent a83ced2 commit 45e2468

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
(* small helper to determine whether two files differ *)
2+
3+
let main () =
4+
let first = Sys.argv.(1) |> open_in in
5+
let second = Sys.argv.(2) |> open_in in
6+
let rec loop () =
7+
match input_line first with
8+
| first_line -> (
9+
match input_line second with
10+
| second_line ->
11+
match String.equal first_line second_line with
12+
| true -> loop ()
13+
| false ->
14+
(* we found a difference between the lines *)
15+
exit 0
16+
| exception End_of_file ->
17+
(* the second file ended before the first *)
18+
exit 0
19+
)
20+
| exception End_of_file ->
21+
(* the first file ended first *)
22+
match input_line second with
23+
| _ ->
24+
(* the second file continues: a difference *)
25+
exit 1
26+
| exception End_of_file ->
27+
(* the second file ended too *)
28+
()
29+
in
30+
loop ();
31+
close_in first;
32+
close_in second;
33+
(* we didn't find a difference, exit with a failure code *)
34+
prerr_endline "The files appear to be identical";
35+
exit 1
36+
37+
let () =
38+
main ()

test/bin/mdx-dune-gen/misc/non-deterministic/dune

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@
3030

3131
;; make sure the non-deterministic is different from the deterministic
3232

33+
(executable
34+
(name different)
35+
(modules different))
36+
3337
(rule
3438
(alias runtest)
3539
(action
36-
(with-accepted-exit-codes
37-
1
38-
(ignore-stdout
39-
(run diff %{dep:dune-mdx-nondeterministic.expected}
40-
%{dep:dune-mdx-nondeterministic.nondeterministic})))))
40+
(run ./different.exe %{dep:dune-mdx-nondeterministic.expected}
41+
%{dep:dune-mdx-nondeterministic.nondeterministic})))

0 commit comments

Comments
 (0)