diff --git a/test/jbuild b/test/jbuild index e41ab086..9e357692 100644 --- a/test/jbuild +++ b/test/jbuild @@ -1,48 +1,10 @@ -(rule - ((targets (stdout stderr)) - (action (with-stdout-to stdout - (with-stderr-to stderr - (progn - (system "echo toto") - (system "echo titi >&2"))))))) - -(rule - ((targets (both)) - (action (with-outputs-to both - (progn - (system "echo toto") - (system "echo titi >&2")))))) - -(rule - ((targets (stdout.expected)) - (action (with-stdout-to ${@} (echo "toto\n"))))) - -(rule - ((targets (stderr.expected)) - (action (with-stdout-to ${@} (echo "titi\n"))))) - -(rule - ((targets (both.expected)) - (action (with-stdout-to ${@} (echo "toto\ntiti\n"))))) +(executables + ((names (run)) + (libraries (unix)))) (alias ((name runtest) - (deps (stdout stdout.expected)) - (action (run diff -u stdout.expected stdout)))) - -(alias - ((name runtest) - (deps (stderr stderr.expected)) - (action (run diff -u stderr.expected stderr)))) - -(alias - ((name runtest) - (deps (both both.expected)) - (action (run diff -u both.expected both)))) - -(alias - ((name runtest) - (action (ignore-stdout (echo "\ -========================== -If you see this, something is wrong -"))))) + (deps ((files_recursively_in workspaces/redirections))) + (action + (chdir workspaces/redirections + (run ${exe:run.exe} ${bin:jbuilder} runtest --root .))))) diff --git a/test/jbuild-ignore b/test/jbuild-ignore new file mode 100644 index 00000000..343194f0 --- /dev/null +++ b/test/jbuild-ignore @@ -0,0 +1 @@ +workspaces diff --git a/test/run.ml b/test/run.ml new file mode 100644 index 00000000..07c656fa --- /dev/null +++ b/test/run.ml @@ -0,0 +1,14 @@ +let () = + let args = Array.sub Sys.argv 1 (Array.length Sys.argv - 1) in + let log = Unix.openfile "log" [O_WRONLY; O_CREAT; O_TRUNC] 0o666 in + let pid = Unix.create_process args.(0) args Unix.stdin log log in + Unix.close log; + match snd (Unix.waitpid [] pid) with + | WEXITED 0 -> () + | st -> + Printf.eprintf "Command failed, log saved in %s/log\n%!" + (Sys.getcwd ()); + exit (match st with + | WEXITED n -> n + | WSIGNALED n -> 128 + n + | WSTOPPED _ -> assert false) diff --git a/test/workspaces/redirections/jbuild b/test/workspaces/redirections/jbuild new file mode 100644 index 00000000..e41ab086 --- /dev/null +++ b/test/workspaces/redirections/jbuild @@ -0,0 +1,48 @@ +(rule + ((targets (stdout stderr)) + (action (with-stdout-to stdout + (with-stderr-to stderr + (progn + (system "echo toto") + (system "echo titi >&2"))))))) + +(rule + ((targets (both)) + (action (with-outputs-to both + (progn + (system "echo toto") + (system "echo titi >&2")))))) + +(rule + ((targets (stdout.expected)) + (action (with-stdout-to ${@} (echo "toto\n"))))) + +(rule + ((targets (stderr.expected)) + (action (with-stdout-to ${@} (echo "titi\n"))))) + +(rule + ((targets (both.expected)) + (action (with-stdout-to ${@} (echo "toto\ntiti\n"))))) + +(alias + ((name runtest) + (deps (stdout stdout.expected)) + (action (run diff -u stdout.expected stdout)))) + +(alias + ((name runtest) + (deps (stderr stderr.expected)) + (action (run diff -u stderr.expected stderr)))) + +(alias + ((name runtest) + (deps (both both.expected)) + (action (run diff -u both.expected both)))) + +(alias + ((name runtest) + (action (ignore-stdout (echo "\ +========================== +If you see this, something is wrong +")))))