From c71acbd930328f569d1f98ac9a9379d56d74aa31 Mon Sep 17 00:00:00 2001 From: Jeremie Dimino Date: Wed, 30 Aug 2017 01:21:53 +0100 Subject: [PATCH] Make the testsuite pass on Windows Thought it still requires `sh` and a few Unix tools --- example/sample-projects/hello_world/test/jbuild | 2 +- test/blackbox-tests/cram.mll | 10 ++++++++-- .../test-cases/lib-available/jbuild | 2 +- .../test-cases/lib-available/run.t | 2 +- .../test-cases/redirections/jbuild | 6 +++--- .../test-cases/redirections/run.t | 2 +- test/common/test_common.ml | 17 +++++++++++++---- test/unit-tests/jbuild | 9 +++++---- 8 files changed, 33 insertions(+), 17 deletions(-) diff --git a/example/sample-projects/hello_world/test/jbuild b/example/sample-projects/hello_world/test/jbuild index 9bcfc37f..6edbe6f4 100644 --- a/example/sample-projects/hello_world/test/jbuild +++ b/example/sample-projects/hello_world/test/jbuild @@ -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})))) diff --git a/test/blackbox-tests/cram.mll b/test/blackbox-tests/cram.mll index 8fef69d5..5d1b88bf 100644 --- a/test/blackbox-tests/cram.mll +++ b/test/blackbox-tests/cram.mll @@ -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); diff --git a/test/blackbox-tests/test-cases/lib-available/jbuild b/test/blackbox-tests/test-cases/lib-available/jbuild index 1e04d9b8..c9baf8a0 100644 --- a/test/blackbox-tests/test-cases/lib-available/jbuild +++ b/test/blackbox-tests/test-cases/lib-available/jbuild @@ -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")))) diff --git a/test/blackbox-tests/test-cases/lib-available/run.t b/test/blackbox-tests/test-cases/lib-available/run.t index b90ceab4..e94d2bad 100644 --- a/test/blackbox-tests/test-cases/lib-available/run.t +++ b/test/blackbox-tests/test-cases/lib-available/run.t @@ -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 diff --git a/test/blackbox-tests/test-cases/redirections/jbuild b/test/blackbox-tests/test-cases/redirections/jbuild index e41ab086..769eaffb 100644 --- a/test/blackbox-tests/test-cases/redirections/jbuild +++ b/test/blackbox-tests/test-cases/redirections/jbuild @@ -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) diff --git a/test/blackbox-tests/test-cases/redirections/run.t b/test/blackbox-tests/test-cases/redirections/run.t index d25ff799..e5f6be8d 100644 --- a/test/blackbox-tests/test-cases/redirections/run.t +++ b/test/blackbox-tests/test-cases/redirections/run.t @@ -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 diff --git a/test/common/test_common.ml b/test/common/test_common.ml index 33c3a608..8a202d58 100644 --- a/test/common/test_common.ml +++ b/test/common/test_common.ml @@ -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 = diff --git a/test/unit-tests/jbuild b/test/unit-tests/jbuild index 59407ebc..5c16ecfa 100644 --- a/test/unit-tests/jbuild +++ b/test/unit-tests/jbuild @@ -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} ${<})))))