-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1117 from Julow/cli_tests
Add command line tests
- Loading branch information
Showing
40 changed files
with
216 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
(include dune.inc) | ||
|
||
(rule | ||
(targets dune.inc.gen) | ||
(deps (source_tree .)) | ||
(action (with-stdout-to %{targets} (run ./gen/gen.exe)))) | ||
|
||
(alias | ||
(name runtest) | ||
(action (diff dune.inc dune.inc.gen))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
|
||
(rule | ||
(targets err_default_several_file.output) | ||
(action | ||
(with-outputs-to %{targets} | ||
(system "! %{bin:ocamlformat} %{read-lines:err_default_several_file.opts}")))) | ||
|
||
(alias | ||
(name runtest) | ||
(action (diff err_default_several_file.ref err_default_several_file.output))) | ||
|
||
(rule | ||
(targets err_inplace_and_check.output) | ||
(action | ||
(with-outputs-to %{targets} | ||
(system "! %{bin:ocamlformat} %{read-lines:err_inplace_and_check.opts}")))) | ||
|
||
(alias | ||
(name runtest) | ||
(action (diff err_inplace_and_check.ref err_inplace_and_check.output))) | ||
|
||
(rule | ||
(targets err_inplace_and_output.output) | ||
(action | ||
(with-outputs-to %{targets} | ||
(system "! %{bin:ocamlformat} %{read-lines:err_inplace_and_output.opts}")))) | ||
|
||
(alias | ||
(name runtest) | ||
(action (diff err_inplace_and_output.ref err_inplace_and_output.output))) | ||
|
||
(rule | ||
(targets err_no_arg.output) | ||
(action | ||
(with-outputs-to %{targets} | ||
(system "! %{bin:ocamlformat} %{read-lines:err_no_arg.opts}")))) | ||
|
||
(alias | ||
(name runtest) | ||
(action (diff err_no_arg.ref err_no_arg.output))) | ||
|
||
(rule | ||
(targets err_output_and_check.output) | ||
(action | ||
(with-outputs-to %{targets} | ||
(system "! %{bin:ocamlformat} %{read-lines:err_output_and_check.opts}")))) | ||
|
||
(alias | ||
(name runtest) | ||
(action (diff err_output_and_check.ref err_output_and_check.output))) | ||
|
||
(rule | ||
(targets err_output_several_files.output) | ||
(action | ||
(with-outputs-to %{targets} | ||
(system "! %{bin:ocamlformat} %{read-lines:err_output_several_files.opts}")))) | ||
|
||
(alias | ||
(name runtest) | ||
(action (diff err_output_several_files.ref err_output_several_files.output))) | ||
|
||
(rule | ||
(targets err_stdin_and_file.output) | ||
(action | ||
(with-outputs-to %{targets} | ||
(system "! %{bin:ocamlformat} %{read-lines:err_stdin_and_file.opts}")))) | ||
|
||
(alias | ||
(name runtest) | ||
(action (diff err_stdin_and_file.ref err_stdin_and_file.output))) | ||
|
||
(rule | ||
(targets err_stdin_and_inplace.output) | ||
(action | ||
(with-outputs-to %{targets} | ||
(system "! %{bin:ocamlformat} %{read-lines:err_stdin_and_inplace.opts}")))) | ||
|
||
(alias | ||
(name runtest) | ||
(action (diff err_stdin_and_inplace.ref err_stdin_and_inplace.output))) | ||
|
||
(rule | ||
(targets err_stdin_no_kind.output) | ||
(action | ||
(with-outputs-to %{targets} | ||
(system "! %{bin:ocamlformat} %{read-lines:err_stdin_no_kind.opts}")))) | ||
|
||
(alias | ||
(name runtest) | ||
(action (diff err_stdin_no_kind.ref err_stdin_no_kind.output))) | ||
|
||
(rule | ||
(targets stdin_and_impl.output) | ||
(action | ||
(with-outputs-to %{targets} | ||
(system "%{bin:ocamlformat} %{read-lines:stdin_and_impl.opts} < stdin_and_impl.stdin")))) | ||
|
||
(alias | ||
(name runtest) | ||
(action (diff stdin_and_impl.ref stdin_and_impl.output))) | ||
|
||
(rule | ||
(targets stdin_and_intf.output) | ||
(action | ||
(with-outputs-to %{targets} | ||
(system "%{bin:ocamlformat} %{read-lines:stdin_and_intf.opts} < stdin_and_intf.stdin")))) | ||
|
||
(alias | ||
(name runtest) | ||
(action (diff stdin_and_intf.ref stdin_and_intf.output))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sample/a.ml sample/b.ml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ocamlformat: Must specify exactly one input file without --inplace or --check |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--inplace --check sample/a.ml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ocamlformat: Cannot specify --inplace with --check |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--inplace --output o.ml sample/a.ml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ocamlformat: Cannot specify --output with --inplace |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ocamlformat: Must specify at least one input file, or `-` for stdin |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--output x.ml --check sample/a.ml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ocamlformat: Cannot specify --output with --check |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--output x.ml sample/a.ml sample/b.ml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ocamlformat: Must specify exactly one input file without --inplace or --check |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sample/a.ml - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ocamlformat: Cannot specify stdin together with other inputs |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--inplace - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ocamlformat: Must specify at least one of --impl, --intf or --use-file when reading from stdin |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ocamlformat: Must specify at least one of --impl, --intf or --use-file when reading from stdin |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
(executable | ||
(name gen)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
module StringMap = Map.Make (String) | ||
|
||
type entry = { | ||
has_ref : bool; | ||
has_opts : bool; | ||
has_stdin : bool; | ||
should_fail : bool | ||
} | ||
|
||
let empty_entry = { | ||
has_ref = false; | ||
has_opts = false; | ||
has_stdin = false; | ||
should_fail = false; | ||
} | ||
|
||
let register_file entries fname = | ||
let update_or_add key ~f = | ||
StringMap.update key (function | ||
| Some entry -> Some (f entry) | ||
| None -> Some (f empty_entry)) entries | ||
in | ||
match String.split_on_char '.' fname with | ||
| [ test_name; "ref" ] -> | ||
update_or_add test_name ~f:(fun e -> { e with has_ref = true }) | ||
| [ test_name; "opts" ] -> | ||
update_or_add test_name ~f:(fun e -> { e with has_opts = true }) | ||
| [ test_name; "should-fail" ] -> | ||
update_or_add test_name ~f:(fun e -> { e with should_fail = true }) | ||
| [ test_name; "stdin" ] -> | ||
update_or_add test_name ~f:(fun e -> { e with has_stdin = true }) | ||
| _ -> | ||
entries | ||
|
||
let check_test test_name entry ok = | ||
let e ok b = | ||
if b then Format.kfprintf (fun _ -> false) Format.err_formatter | ||
else Format.ikfprintf (fun _ -> ok) Format.err_formatter | ||
in | ||
let ok = e ok (not entry.has_ref) "@{<error>Error@}: Missing file %s.ref\n" test_name in | ||
let ok = e ok (not entry.has_opts) "@{<error>Error@}: Missing file %s.opts\n" test_name in | ||
ok | ||
|
||
let emit_test test_name entry = | ||
let bang pf b = if b then Format.fprintf pf "! " else () in | ||
let redir_in pf b = if b then Format.fprintf pf " < %s.stdin" test_name else () in | ||
let run_action pf () = | ||
Format.fprintf pf "(with-outputs-to %%{targets}@\n (system \"%a%%{bin:ocamlformat} %%{read-lines:%s.opts}%a\"))" | ||
bang entry.should_fail test_name redir_in entry.has_stdin | ||
in | ||
Format.printf {| | ||
(rule@ | ||
(targets %s.output)@ | ||
(action@ | ||
@[%a@]))@ | ||
|} test_name run_action (); | ||
Format.printf {| | ||
(alias@ | ||
(name runtest)@ | ||
(action (diff %s.ref %s.output)))@ | ||
|} test_name test_name | ||
|
||
let () = | ||
let files = Sys.readdir "." in | ||
let tests = Array.fold_left register_file StringMap.empty files in | ||
if not (StringMap.fold check_test tests true) then | ||
exit 1; | ||
StringMap.iter emit_test tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
let x = "Hello World" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
val x : string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
let () = print_endline A.x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--impl - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
let () = print_endline A.x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sample/b.ml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--intf - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
val x : string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sample/a.mli |