Make the testsuite pass on Windows

Thought it still requires `sh` and a few Unix tools
This commit is contained in:
Jeremie Dimino 2017-08-30 01:21:53 +01:00
parent af5208416f
commit c71acbd930
8 changed files with 33 additions and 17 deletions

View File

@ -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}))))

View File

@ -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);

View File

@ -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"))))

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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 =

View File

@ -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))
@ -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} ${<})))))