From 1e6cca23038c32250fe954a98ce7c646d0800aa3 Mon Sep 17 00:00:00 2001 From: Etienne Millon Date: Tue, 19 Nov 2019 11:44:35 +0100 Subject: [PATCH] Partially revert #1126 Test generators are a bit heavy, but running processes through ocaml is a bit limited when we want to set a working directory or environment. So, let's use a middle ground solution: run ocamlformat through dune, but write the rules by hand. --- CHANGES.md | 2 +- test/cli/.ocamlformat | 6 - test/cli/dune | 254 +++++++++++++++++- test/cli/err_default_several_file.expected | 1 + test/cli/err_inplace_and_check.expected | 1 + test/cli/err_inplace_and_output.expected | 1 + test/cli/err_no_arg.expected | 1 + test/cli/err_output_and_check.expected | 1 + test/cli/err_output_several_files.expected | 1 + test/cli/err_several_files_and_kind.expected | 1 + ...rr_several_files_and_kind_inplace.expected | 1 + test/cli/err_several_files_and_name.expected | 1 + ...rr_several_files_and_name_inplace.expected | 1 + test/cli/err_stdin_and_file.expected | 1 + test/cli/err_stdin_and_inplace.expected | 1 + test/cli/err_stdin_name_unknown_ext.expected | 1 + test/cli/err_stdin_no_kind.expected | 1 + test/cli/fmterr_file_and_name.expected | 3 + .../fmterr_file_and_name_bad_kind.expected | 3 + test/cli/fmterr_file_bad_kind.expected | 3 + test/cli/fmterr_stdin_and_name.expected | 3 + .../fmterr_stdin_and_name_bad_kind.expected | 3 + test/cli/fmterr_stdin_bad_kind.expected | 3 + test/cli/name_unknown_ext.expected | 1 + test/cli/stdin_and_impl.expected | 1 + test/cli/stdin_and_intf.expected | 4 + test/cli/stdin_and_name.expected | 1 + test/cli/test_cli.expected | 159 ----------- test/cli/test_cli.ml | 56 ---- 29 files changed, 289 insertions(+), 227 deletions(-) delete mode 100644 test/cli/.ocamlformat create mode 100644 test/cli/err_default_several_file.expected create mode 100644 test/cli/err_inplace_and_check.expected create mode 100644 test/cli/err_inplace_and_output.expected create mode 100644 test/cli/err_no_arg.expected create mode 100644 test/cli/err_output_and_check.expected create mode 100644 test/cli/err_output_several_files.expected create mode 100644 test/cli/err_several_files_and_kind.expected create mode 100644 test/cli/err_several_files_and_kind_inplace.expected create mode 100644 test/cli/err_several_files_and_name.expected create mode 100644 test/cli/err_several_files_and_name_inplace.expected create mode 100644 test/cli/err_stdin_and_file.expected create mode 100644 test/cli/err_stdin_and_inplace.expected create mode 100644 test/cli/err_stdin_name_unknown_ext.expected create mode 100644 test/cli/err_stdin_no_kind.expected create mode 100644 test/cli/fmterr_file_and_name.expected create mode 100644 test/cli/fmterr_file_and_name_bad_kind.expected create mode 100644 test/cli/fmterr_file_bad_kind.expected create mode 100644 test/cli/fmterr_stdin_and_name.expected create mode 100644 test/cli/fmterr_stdin_and_name_bad_kind.expected create mode 100644 test/cli/fmterr_stdin_bad_kind.expected create mode 100644 test/cli/name_unknown_ext.expected create mode 100644 test/cli/stdin_and_impl.expected create mode 100644 test/cli/stdin_and_intf.expected create mode 100644 test/cli/stdin_and_name.expected delete mode 100644 test/cli/test_cli.expected delete mode 100644 test/cli/test_cli.ml diff --git a/CHANGES.md b/CHANGES.md index 81bb3e0884..b185b1856d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -23,7 +23,7 @@ + Refactor code that interprets CLI options (#1127, #1156) (Jules Aguillon) + Testing interactions between break-infix and break-infix-before-func (#1136) (Guillaume Petiot) + Add dune to repositories checked for regressions (#1129) (Jules Aguillon) - + Use an expect test for cli tests (#1126) (Etienne Millon) + + Remove the test generator for cli tests (#1126, #1157) (Etienne Millon) + Factor out a private library (#1134, #1148) (Etienne Millon) + Remove global reference `Cmts.remove` (#1142) (Etienne Millon) + Remove symbol strings in `Cmts` (#1146) (Etienne Millon) diff --git a/test/cli/.ocamlformat b/test/cli/.ocamlformat deleted file mode 100644 index 6016ca6f35..0000000000 --- a/test/cli/.ocamlformat +++ /dev/null @@ -1,6 +0,0 @@ -profile = ocamlformat -break-cases = fit -margin = 77 -parse-docstrings = true -wrap-comments = true -max-iters = 2 diff --git a/test/cli/dune b/test/cli/dune index e75f98380c..0d28ffa99c 100644 --- a/test/cli/dune +++ b/test/cli/dune @@ -1,5 +1,249 @@ -(test - (name test_cli) - (libraries unix stdio) - (deps .ocamlformat (glob_files sample/*)) - (action (run %{test} %{bin:ocamlformat}))) +(rule + (with-outputs-to + err_default_several_file.output + (system "! %{bin:ocamlformat} %{dep:sample/a.ml} %{dep:sample/b.ml}"))) + +(alias + (name runtest) + (action + (diff err_default_several_file.expected err_default_several_file.output))) + +(rule + (with-outputs-to + err_inplace_and_check.output + (system "! %{bin:ocamlformat} --inplace --check %{dep:sample/a.ml}"))) + +(alias + (name runtest) + (action + (diff err_inplace_and_check.expected err_inplace_and_check.output))) + +(rule + (with-outputs-to + err_inplace_and_output.output + (system "! %{bin:ocamlformat} --inplace --output o.ml %{dep:sample/a.ml}"))) + +(alias + (name runtest) + (action + (diff err_inplace_and_output.expected err_inplace_and_output.output))) + +(rule + (with-outputs-to + err_no_arg.output + (system "! %{bin:ocamlformat}"))) + +(alias + (name runtest) + (action + (diff err_no_arg.expected err_no_arg.output))) + +(rule + (with-outputs-to + err_output_and_check.output + (system "! %{bin:ocamlformat} --output x.ml --check %{dep:sample/a.ml}"))) + +(alias + (name runtest) + (action + (diff err_output_and_check.expected err_output_and_check.output))) + +(rule + (with-outputs-to + err_output_several_files.output + (system + "! %{bin:ocamlformat} --output x.ml %{dep:sample/a.ml} %{dep:sample/b.ml}"))) + +(alias + (name runtest) + (action + (diff err_output_several_files.expected err_output_several_files.output))) + +(rule + (with-outputs-to + err_stdin_and_file.output + (system "! %{bin:ocamlformat} %{dep:sample/a.ml} -"))) + +(alias + (name runtest) + (action + (diff err_stdin_and_file.expected err_stdin_and_file.output))) + +(rule + (with-outputs-to + err_stdin_and_inplace.output + (system "! %{bin:ocamlformat} --inplace -"))) + +(alias + (name runtest) + (action + (diff err_stdin_and_inplace.expected err_stdin_and_inplace.output))) + +(rule + (with-outputs-to + err_stdin_no_kind.output + (system "! %{bin:ocamlformat} -"))) + +(alias + (name runtest) + (action + (diff err_stdin_no_kind.expected err_stdin_no_kind.output))) + +(rule + (with-outputs-to + stdin_and_impl.output + (system "%{bin:ocamlformat} --impl - < %{dep:sample/b.ml}"))) + +(alias + (name runtest) + (action + (diff stdin_and_impl.expected stdin_and_impl.output))) + +(rule + (with-outputs-to + stdin_and_intf.output + (system "%{bin:ocamlformat} --intf - < %{dep:sample/a.mli}"))) + +(alias + (name runtest) + (action + (diff stdin_and_intf.expected stdin_and_intf.output))) + +(rule + (with-outputs-to + stdin_and_name.output + (system "%{bin:ocamlformat} --name a.ml - < %{dep:sample/b.ml}"))) + +(alias + (name runtest) + (action + (diff stdin_and_name.expected stdin_and_name.output))) + +(rule + (with-outputs-to + name_unknown_ext.output + (system "%{bin:ocamlformat} --name b.cpp %{dep:sample/b.ml}"))) + +(alias + (name runtest) + (action + (diff name_unknown_ext.expected name_unknown_ext.output))) + +(rule + (with-outputs-to + err_stdin_name_unknown_ext.output + (system "! %{bin:ocamlformat} --name b.cpp - < %{dep:sample/b.ml}"))) + +(alias + (name runtest) + (action + (diff err_stdin_name_unknown_ext.expected err_stdin_name_unknown_ext.output))) + +(rule + (with-outputs-to + err_several_files_and_kind.output + (system + "! %{bin:ocamlformat} --impl --check %{dep:sample/a.mli} %{dep:sample/b.ml}"))) + +(alias + (name runtest) + (action + (diff err_several_files_and_kind.expected err_several_files_and_kind.output))) + +(rule + (with-outputs-to + err_several_files_and_name.output + (system + "! %{bin:ocamlformat} --name foo.ml --check %{dep:sample/a.mli} %{dep:sample/b.ml}"))) + +(alias + (name runtest) + (action + (diff err_several_files_and_name.expected err_several_files_and_name.output))) + +(rule + (with-outputs-to + err_several_files_and_kind_inplace.output + (system + "! %{bin:ocamlformat} --impl --check %{dep:sample/a.mli} %{dep:sample/b.ml}"))) + +(alias + (name runtest) + (action + (diff err_several_files_and_kind_inplace.expected + err_several_files_and_kind_inplace.output))) + +(rule + (with-outputs-to + err_several_files_and_name_inplace.output + (system + "! %{bin:ocamlformat} --name foo.ml --check %{dep:sample/a.mli} %{dep:sample/b.ml}"))) + +(alias + (name runtest) + (action + (diff err_several_files_and_name_inplace.expected + err_several_files_and_name_inplace.output))) + +(rule + (with-outputs-to + fmterr_file_and_name.output + (system "! %{bin:ocamlformat} --name foo.ml %{dep:sample/syntax_error.ml}"))) + +(alias + (name runtest) + (action + (diff fmterr_file_and_name.expected fmterr_file_and_name.output))) + +(rule + (with-outputs-to + fmterr_stdin_and_name.output + (system + "! %{bin:ocamlformat} --name foo.ml - < %{dep:sample/syntax_error.ml}"))) + +(alias + (name runtest) + (action + (diff fmterr_stdin_and_name.expected fmterr_stdin_and_name.output))) + +(rule + (with-outputs-to + fmterr_file_bad_kind.output + (system "! %{bin:ocamlformat} --impl %{dep:sample/a.mli}"))) + +(alias + (name runtest) + (action + (diff fmterr_file_bad_kind.expected fmterr_file_bad_kind.output))) + +(rule + (with-outputs-to + fmterr_stdin_bad_kind.output + (system "! %{bin:ocamlformat} --impl - < %{dep:sample/a.mli}"))) + +(alias + (name runtest) + (action + (diff fmterr_stdin_bad_kind.expected fmterr_stdin_bad_kind.output))) + +(rule + (with-outputs-to + fmterr_file_and_name_bad_kind.output + (system "! %{bin:ocamlformat} --name foo.ml %{dep:sample/a.mli}"))) + +(alias + (name runtest) + (action + (diff fmterr_file_and_name_bad_kind.expected + fmterr_file_and_name_bad_kind.output))) + +(rule + (with-outputs-to + fmterr_stdin_and_name_bad_kind.output + (system "! %{bin:ocamlformat} --name foo.ml - < %{dep:sample/a.mli}"))) + +(alias + (name runtest) + (action + (diff fmterr_stdin_and_name_bad_kind.expected + fmterr_stdin_and_name_bad_kind.output))) diff --git a/test/cli/err_default_several_file.expected b/test/cli/err_default_several_file.expected new file mode 100644 index 0000000000..8231c3424e --- /dev/null +++ b/test/cli/err_default_several_file.expected @@ -0,0 +1 @@ +ocamlformat: Must specify exactly one input file without --inplace or --check diff --git a/test/cli/err_inplace_and_check.expected b/test/cli/err_inplace_and_check.expected new file mode 100644 index 0000000000..d02df733fc --- /dev/null +++ b/test/cli/err_inplace_and_check.expected @@ -0,0 +1 @@ +ocamlformat: Cannot specify --inplace with --check diff --git a/test/cli/err_inplace_and_output.expected b/test/cli/err_inplace_and_output.expected new file mode 100644 index 0000000000..eab3df1da6 --- /dev/null +++ b/test/cli/err_inplace_and_output.expected @@ -0,0 +1 @@ +ocamlformat: Cannot specify --output with --inplace diff --git a/test/cli/err_no_arg.expected b/test/cli/err_no_arg.expected new file mode 100644 index 0000000000..4bc1d3b5e1 --- /dev/null +++ b/test/cli/err_no_arg.expected @@ -0,0 +1 @@ +ocamlformat: Must specify at least one input file, or `-` for stdin diff --git a/test/cli/err_output_and_check.expected b/test/cli/err_output_and_check.expected new file mode 100644 index 0000000000..d5ddb63fd2 --- /dev/null +++ b/test/cli/err_output_and_check.expected @@ -0,0 +1 @@ +ocamlformat: Cannot specify --output with --check diff --git a/test/cli/err_output_several_files.expected b/test/cli/err_output_several_files.expected new file mode 100644 index 0000000000..8231c3424e --- /dev/null +++ b/test/cli/err_output_several_files.expected @@ -0,0 +1 @@ +ocamlformat: Must specify exactly one input file without --inplace or --check diff --git a/test/cli/err_several_files_and_kind.expected b/test/cli/err_several_files_and_kind.expected new file mode 100644 index 0000000000..d97eb96b19 --- /dev/null +++ b/test/cli/err_several_files_and_kind.expected @@ -0,0 +1 @@ +ocamlformat: Cannot specify --impl or --intf with multiple inputs diff --git a/test/cli/err_several_files_and_kind_inplace.expected b/test/cli/err_several_files_and_kind_inplace.expected new file mode 100644 index 0000000000..d97eb96b19 --- /dev/null +++ b/test/cli/err_several_files_and_kind_inplace.expected @@ -0,0 +1 @@ +ocamlformat: Cannot specify --impl or --intf with multiple inputs diff --git a/test/cli/err_several_files_and_name.expected b/test/cli/err_several_files_and_name.expected new file mode 100644 index 0000000000..1badadf4e2 --- /dev/null +++ b/test/cli/err_several_files_and_name.expected @@ -0,0 +1 @@ +ocamlformat: Cannot specify --name with multiple inputs diff --git a/test/cli/err_several_files_and_name_inplace.expected b/test/cli/err_several_files_and_name_inplace.expected new file mode 100644 index 0000000000..1badadf4e2 --- /dev/null +++ b/test/cli/err_several_files_and_name_inplace.expected @@ -0,0 +1 @@ +ocamlformat: Cannot specify --name with multiple inputs diff --git a/test/cli/err_stdin_and_file.expected b/test/cli/err_stdin_and_file.expected new file mode 100644 index 0000000000..8e45bd830d --- /dev/null +++ b/test/cli/err_stdin_and_file.expected @@ -0,0 +1 @@ +ocamlformat: Cannot specify stdin together with other inputs diff --git a/test/cli/err_stdin_and_inplace.expected b/test/cli/err_stdin_and_inplace.expected new file mode 100644 index 0000000000..2f730f5204 --- /dev/null +++ b/test/cli/err_stdin_and_inplace.expected @@ -0,0 +1 @@ +ocamlformat: Must specify at least one of --name, --impl or --intf when reading from stdin diff --git a/test/cli/err_stdin_name_unknown_ext.expected b/test/cli/err_stdin_name_unknown_ext.expected new file mode 100644 index 0000000000..921eb3d10c --- /dev/null +++ b/test/cli/err_stdin_name_unknown_ext.expected @@ -0,0 +1 @@ +ocamlformat: Cannot deduce file kind from passed --name. Please specify --impl or --intf diff --git a/test/cli/err_stdin_no_kind.expected b/test/cli/err_stdin_no_kind.expected new file mode 100644 index 0000000000..2f730f5204 --- /dev/null +++ b/test/cli/err_stdin_no_kind.expected @@ -0,0 +1 @@ +ocamlformat: Must specify at least one of --name, --impl or --intf when reading from stdin diff --git a/test/cli/fmterr_file_and_name.expected b/test/cli/fmterr_file_and_name.expected new file mode 100644 index 0000000000..4d7ae9de9d --- /dev/null +++ b/test/cli/fmterr_file_and_name.expected @@ -0,0 +1,3 @@ +ocamlformat: ignoring "foo.ml" (syntax error) +File "foo.ml", line 2, characters 0-0: +Error: Syntax error diff --git a/test/cli/fmterr_file_and_name_bad_kind.expected b/test/cli/fmterr_file_and_name_bad_kind.expected new file mode 100644 index 0000000000..c342896846 --- /dev/null +++ b/test/cli/fmterr_file_and_name_bad_kind.expected @@ -0,0 +1,3 @@ +ocamlformat: ignoring "foo.ml" (syntax error) +File "foo.ml", line 5, characters 0-0: +Error: Syntax error diff --git a/test/cli/fmterr_file_bad_kind.expected b/test/cli/fmterr_file_bad_kind.expected new file mode 100644 index 0000000000..d624260b11 --- /dev/null +++ b/test/cli/fmterr_file_bad_kind.expected @@ -0,0 +1,3 @@ +ocamlformat: ignoring "sample/a.mli" (syntax error) +File "sample/a.mli", line 5, characters 0-0: +Error: Syntax error diff --git a/test/cli/fmterr_stdin_and_name.expected b/test/cli/fmterr_stdin_and_name.expected new file mode 100644 index 0000000000..4d7ae9de9d --- /dev/null +++ b/test/cli/fmterr_stdin_and_name.expected @@ -0,0 +1,3 @@ +ocamlformat: ignoring "foo.ml" (syntax error) +File "foo.ml", line 2, characters 0-0: +Error: Syntax error diff --git a/test/cli/fmterr_stdin_and_name_bad_kind.expected b/test/cli/fmterr_stdin_and_name_bad_kind.expected new file mode 100644 index 0000000000..c342896846 --- /dev/null +++ b/test/cli/fmterr_stdin_and_name_bad_kind.expected @@ -0,0 +1,3 @@ +ocamlformat: ignoring "foo.ml" (syntax error) +File "foo.ml", line 5, characters 0-0: +Error: Syntax error diff --git a/test/cli/fmterr_stdin_bad_kind.expected b/test/cli/fmterr_stdin_bad_kind.expected new file mode 100644 index 0000000000..be5a54b168 --- /dev/null +++ b/test/cli/fmterr_stdin_bad_kind.expected @@ -0,0 +1,3 @@ +ocamlformat: ignoring "" (syntax error) +File "", line 5, characters 0-0: +Error: Syntax error diff --git a/test/cli/name_unknown_ext.expected b/test/cli/name_unknown_ext.expected new file mode 100644 index 0000000000..7572c13af9 --- /dev/null +++ b/test/cli/name_unknown_ext.expected @@ -0,0 +1 @@ +let () = print_endline A.x diff --git a/test/cli/stdin_and_impl.expected b/test/cli/stdin_and_impl.expected new file mode 100644 index 0000000000..7572c13af9 --- /dev/null +++ b/test/cli/stdin_and_impl.expected @@ -0,0 +1 @@ +let () = print_endline A.x diff --git a/test/cli/stdin_and_intf.expected b/test/cli/stdin_and_intf.expected new file mode 100644 index 0000000000..eabfe49df0 --- /dev/null +++ b/test/cli/stdin_and_intf.expected @@ -0,0 +1,4 @@ +val x : string + +module X : S +(** Make sure this file cannot be parsed as an impl file *) diff --git a/test/cli/stdin_and_name.expected b/test/cli/stdin_and_name.expected new file mode 100644 index 0000000000..7572c13af9 --- /dev/null +++ b/test/cli/stdin_and_name.expected @@ -0,0 +1 @@ +let () = print_endline A.x diff --git a/test/cli/test_cli.expected b/test/cli/test_cli.expected deleted file mode 100644 index 62d5afcce6..0000000000 --- a/test/cli/test_cli.expected +++ /dev/null @@ -1,159 +0,0 @@ -err_default_several_file -======================== -args: sample/a.ml sample/b.ml -ocamlformat: Must specify exactly one input file without --inplace or --check -[1] - -err_inplace_and_check -===================== -args: --inplace --check sample/a.ml -ocamlformat: Cannot specify --inplace with --check -[1] - -err_inplace_and_output -====================== -args: --inplace --output o.ml sample/a.ml -ocamlformat: Cannot specify --output with --inplace -[1] - -err_no_arg -========== -args: -ocamlformat: Must specify at least one input file, or `-` for stdin -[1] - -err_output_and_check -==================== -args: --output x.ml --check sample/a.ml -ocamlformat: Cannot specify --output with --check -[1] - -err_output_several_files -======================== -args: --output x.ml sample/a.ml sample/b.ml -ocamlformat: Must specify exactly one input file without --inplace or --check -[1] - -err_stdin_and_file -================== -args: sample/a.ml - -ocamlformat: Cannot specify stdin together with other inputs -[1] - -err_stdin_and_inplace -===================== -args: --inplace - -ocamlformat: Must specify at least one of --name, --impl or --intf when reading from stdin -[1] - -err_stdin_no_kind -================= -args: - -ocamlformat: Must specify at least one of --name, --impl or --intf when reading from stdin -[1] - -stdin_and_impl -============== -args: --impl - -let () = print_endline A.x -[0] - -stdin_and_intf -============== -args: --intf - -val x : string - -module X : S -(** Make sure this file cannot be parsed as an impl file *) -[0] - -stdin_and_name -============== -args: --name a.ml - -let () = print_endline A.x -[0] - -name_unknown_ext -================ -args: --name b.cpp sample/b.ml -let () = print_endline A.x -[0] - -err_stdin_name_unknown_ext -========================== -args: --name b.cpp - -ocamlformat: Cannot deduce file kind from passed --name. Please specify --impl or --intf -[1] - -err_several_files_and_kind -========================== -args: --impl --check sample/a.mli sample/b.ml -ocamlformat: Cannot specify --impl or --intf with multiple inputs -[1] - -err_several_files_and_name -========================== -args: --name foo.ml --check sample/a.mli sample/b.ml -ocamlformat: Cannot specify --name with multiple inputs -[1] - -err_several_files_and_kind_inplace -================================== -args: --impl --check sample/a.mli sample/b.ml -ocamlformat: Cannot specify --impl or --intf with multiple inputs -[1] - -err_several_files_and_name_inplace -================================== -args: --name foo.ml --check sample/a.mli sample/b.ml -ocamlformat: Cannot specify --name with multiple inputs -[1] - -fmterr_file_and_name -==================== -args: --name foo.ml sample/syntax_error.ml -ocamlformat: ignoring "foo.ml" (syntax error) -File "foo.ml", line 2, characters 0-0: -Error: Syntax error -[1] - -fmterr_stdin_and_name -===================== -args: --name foo.ml - -ocamlformat: ignoring "foo.ml" (syntax error) -File "foo.ml", line 2, characters 0-0: -Error: Syntax error -[1] - -fmterr_file_bad_kind -==================== -args: --impl sample/a.mli -ocamlformat: ignoring "sample/a.mli" (syntax error) -File "sample/a.mli", line 5, characters 0-0: -Error: Syntax error -[1] - -fmterr_stdin_bad_kind -===================== -args: --impl - -ocamlformat: ignoring "" (syntax error) -File "", line 5, characters 0-0: -Error: Syntax error -[1] - -fmterr_file_and_name_bad_kind -============================= -args: --name foo.ml sample/a.mli -ocamlformat: ignoring "foo.ml" (syntax error) -File "foo.ml", line 5, characters 0-0: -Error: Syntax error -[1] - -fmterr_stdin_and_name_bad_kind -============================== -args: --name foo.ml - -ocamlformat: ignoring "foo.ml" (syntax error) -File "foo.ml", line 5, characters 0-0: -Error: Syntax error -[1] - diff --git a/test/cli/test_cli.ml b/test/cli/test_cli.ml deleted file mode 100644 index f49a54f8a6..0000000000 --- a/test/cli/test_cli.ml +++ /dev/null @@ -1,56 +0,0 @@ -let pp_banner ppf s = - let line = String.make (String.length s) '=' in - Format.fprintf ppf "%s\n%s\n" s line - -let pp_status ppf = function - | Unix.WEXITED n -> Format.fprintf ppf "[%d]" n - | WSIGNALED _ -> Format.fprintf ppf "WSIGNALED _" - | WSTOPPED _ -> Format.fprintf ppf "WSTOPPED _" - -let main ocamlformat = - let test ?(stdin = "") ~name ~args () = - let cmd = Printf.sprintf "%s %s 2>&1" ocamlformat args in - let proc = Unix.open_process cmd in - let proc_out, proc_in = proc in - Stdio.Out_channel.output_string proc_in stdin ; - Stdio.Out_channel.close proc_in ; - let out = Stdio.In_channel.input_all proc_out in - let stat = Unix.close_process proc in - Format.printf "%aargs: %s\n%s%a\n\n" pp_banner name args out pp_status stat - in - let impl_file = Stdio.In_channel.read_all "sample/b.ml" in - let intf_file = Stdio.In_channel.read_all "sample/a.mli" in - let syntax_error_file = Stdio.In_channel.read_all "sample/syntax_error.ml" in - test ~name:"err_default_several_file" ~args:"sample/a.ml sample/b.ml" () ; - test ~name:"err_inplace_and_check" ~args:"--inplace --check sample/a.ml" () ; - test ~name:"err_inplace_and_output" - ~args:"--inplace --output o.ml sample/a.ml" () ; - test ~name:"err_no_arg" ~args:"" () ; - test ~name:"err_output_and_check" ~args:"--output x.ml --check sample/a.ml" () ; - test ~name:"err_output_several_files" - ~args:"--output x.ml sample/a.ml sample/b.ml" () ; - test ~name:"err_stdin_and_file" ~args:"sample/a.ml -" () ; - test ~name:"err_stdin_and_inplace" ~args:"--inplace -" () ; - test ~name:"err_stdin_no_kind" ~args:"-" () ; - test ~name:"stdin_and_impl" ~stdin:impl_file ~args:"--impl -" () ; - test ~name:"stdin_and_intf" ~stdin:intf_file ~args:"--intf -" () ; - test ~name:"stdin_and_name" ~stdin:impl_file ~args:"--name a.ml -" () ; - test ~name:"name_unknown_ext" ~args:"--name b.cpp sample/b.ml" () ; - test ~name:"err_stdin_name_unknown_ext" ~stdin:impl_file - ~args:"--name b.cpp -" () ; - test ~name:"err_several_files_and_kind" ~args:"--impl --check sample/a.mli sample/b.ml" () ; - test ~name:"err_several_files_and_name" ~args:"--name foo.ml --check sample/a.mli sample/b.ml" () ; - test ~name:"err_several_files_and_kind_inplace" ~args:"--impl --check sample/a.mli sample/b.ml" () ; - test ~name:"err_several_files_and_name_inplace" ~args:"--name foo.ml --check sample/a.mli sample/b.ml" () ; - test ~name:"fmterr_file_and_name" ~args:"--name foo.ml sample/syntax_error.ml" () ; - test ~name:"fmterr_stdin_and_name" ~stdin:syntax_error_file ~args:"--name foo.ml -" () ; - test ~name:"fmterr_file_bad_kind" ~args:"--impl sample/a.mli" () ; - test ~name:"fmterr_stdin_bad_kind" ~stdin:intf_file ~args:"--impl -" () ; - test ~name:"fmterr_file_and_name_bad_kind" ~args:"--name foo.ml sample/a.mli" () ; - test ~name:"fmterr_stdin_and_name_bad_kind" ~stdin:intf_file ~args:"--name foo.ml -" () ; - () - -let () = - match Sys.argv with - | [|_; ocamlformat|] -> main ocamlformat - | _ -> assert false