Skip to content

Commit

Permalink
Make the testsuite pass on Windows
Browse files Browse the repository at this point in the history
Thought it still requires `sh` and a few Unix tools
  • Loading branch information
jeremiedimino committed Sep 22, 2017
1 parent af52084 commit c71acbd
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 17 deletions.
2 changes: 1 addition & 1 deletion example/sample-projects/hello_world/test/jbuild
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

(alias
((name runtest)
(action (run diff -u ${path:hello_world.expected} ${path:hello_world.output}))))
(action (run diff -uw ${path:hello_world.expected} ${path:hello_world.output}))))
10 changes: 8 additions & 2 deletions test/blackbox-tests/cram.mll
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,21 @@ rule file = parse
let items = file lexbuf in
let temp_file = Filename.temp_file "jbuilder-test" ".output" in
at_exit (fun () -> Sys.remove temp_file);
let temp_file_quote = Filename.quote temp_file in
let buf = Buffer.create (String.length file_contents + 1024) in
List.iter items ~f:(function
| Output _ -> ()
| Comment s -> Buffer.add_string buf s; Buffer.add_char buf '\n'
| Command s ->
Printf.bprintf buf " $ %s\n" s;
let fd = Unix.openfile temp_file [O_WRONLY] 0 in
let pid =
Unix.create_process "sh" [|"sh"; "-c"; s|] Unix.stdin fd fd
in
Unix.close fd;
let n =
Printf.ksprintf Sys.command "%s > %s 2> %s" s temp_file_quote temp_file_quote
match snd (Unix.waitpid [] pid) with
| WEXITED n -> n
| _ -> 255
in
List.iter (Io.lines_of_file temp_file) ~f:(fun line ->
Printf.bprintf buf " %s\n" line);
Expand Down
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/lib-available/jbuild
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

(alias
((name runtest)
(action (system "! ${lib-available:library-that-surely-doesnt-exist}"))))
(action (system "${lib-available:library-that-surely-doesnt-exist} && exit 1 || exit 0"))))
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/lib-available/run.t
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
$ $JBUILDER build -j1 @runtest --root . --debug-dependency-path
$ $JBUILDER build -j1 @runtest --root . --debug-dependency-path 2>&1 | sed "s/ cmd / sh /"
sh alias runtest
sh alias runtest
6 changes: 3 additions & 3 deletions test/blackbox-tests/test-cases/redirections/jbuild
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@
(alias
((name runtest)
(deps (stdout stdout.expected))
(action (run diff -u stdout.expected stdout))))
(action (run diff -uw stdout.expected stdout))))

(alias
((name runtest)
(deps (stderr stderr.expected))
(action (run diff -u stderr.expected stderr))))
(action (run diff -uw stderr.expected stderr))))

(alias
((name runtest)
(deps (both both.expected))
(action (run diff -u both.expected both))))
(action (run diff -uw both.expected both))))

(alias
((name runtest)
Expand Down
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/redirections/run.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$ $JBUILDER runtest -j1 --root .
$ $JBUILDER runtest -j1 --root . 2>&1 | sed "s/ cmd / sh /"
sh stderr,stdout
sh both
sh stderr,stdout
Expand Down
17 changes: 13 additions & 4 deletions test/common/test_common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,19 @@ module Print_diff = struct
match diff_command with
| Some s -> ignore (exec s : bool)
| None ->
if exec (patdiff_cmd ~use_color) then (
Printf.eprintf "File \"%s\", line 1, characters 0-0:\n%!" file1;
ignore (exec "diff -u" : bool);
)
let has_patdiff =
let dev_null = if Sys.win32 then "nul" else "/dev/null" in
Printf.ksprintf Sys.command "patdiff -version > %s 2> %s"
dev_null dev_null = 0
in
if has_patdiff then begin
if exec (patdiff_cmd ~use_color) then begin
(* Use "diff" if "patdiff" reported no differences *)
Printf.eprintf "File \"%s\", line 1, characters 0-0:\n%!" file1;
ignore (exec "diff -u" : bool);
end
end else
ignore (exec "diff -u" : bool)
end

let read_file file =
Expand Down
9 changes: 5 additions & 4 deletions test/unit-tests/jbuild
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
((name expect_test)
(modules (expect_test))
(link_flags (-linkall))
(modes (byte))
(libraries (unix jbuilder compiler-libs.toplevel test_common))))

(ocamllex (expect_test))
Expand All @@ -14,25 +15,25 @@
(glob_files ${SCOPE_ROOT}/src/*.cmi)
(glob_files ${SCOPE_ROOT}/vendor/re/*.cmi)
(files_recursively_in findlib-db)))
(action (chdir ${SCOPE_ROOT} (run ${exe:expect_test.bc} ${<})))))
(action (chdir ${SCOPE_ROOT} (run ${exe:expect_test.exe} ${<})))))

(alias
((name runtest)
(deps (filename.mlt
(glob_files ${SCOPE_ROOT}/src/*.cmi)
(glob_files ${SCOPE_ROOT}/vendor/re/*.cmi)))
(action (chdir ${SCOPE_ROOT} (run ${exe:expect_test.bc} ${<})))))
(action (chdir ${SCOPE_ROOT} (run ${exe:expect_test.exe} ${<})))))

(alias
((name runtest)
(deps (import_dot_map.mlt
(glob_files ${SCOPE_ROOT}/src/*.cmi)
(glob_files ${SCOPE_ROOT}/vendor/re/*.cmi)))
(action (chdir ${SCOPE_ROOT} (run ${exe:expect_test.bc} ${<})))))
(action (chdir ${SCOPE_ROOT} (run ${exe:expect_test.exe} ${<})))))

(alias
((name runtest)
(deps (action.mlt
(glob_files ${SCOPE_ROOT}/src/*.cmi)
(glob_files ${SCOPE_ROOT}/vendor/re/*.cmi)))
(action (chdir ${SCOPE_ROOT} (run ${exe:expect_test.bc} ${<})))))
(action (chdir ${SCOPE_ROOT} (run ${exe:expect_test.exe} ${<})))))

0 comments on commit c71acbd

Please sign in to comment.