Skip to content

Commit

Permalink
Partially revert ocaml-ppx#1126 (ocaml-ppx#1157)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
emillon authored and bogdan2412 committed Mar 28, 2020
1 parent e9ddf1d commit aa6c896
Show file tree
Hide file tree
Showing 29 changed files with 289 additions and 227 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 0 additions & 6 deletions test/cli/.ocamlformat

This file was deleted.

254 changes: 249 additions & 5 deletions test/cli/dune
Original file line number Diff line number Diff line change
@@ -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)))
1 change: 1 addition & 0 deletions test/cli/err_default_several_file.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ocamlformat: Must specify exactly one input file without --inplace or --check
1 change: 1 addition & 0 deletions test/cli/err_inplace_and_check.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ocamlformat: Cannot specify --inplace with --check
1 change: 1 addition & 0 deletions test/cli/err_inplace_and_output.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ocamlformat: Cannot specify --output with --inplace
1 change: 1 addition & 0 deletions test/cli/err_no_arg.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ocamlformat: Must specify at least one input file, or `-` for stdin
1 change: 1 addition & 0 deletions test/cli/err_output_and_check.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ocamlformat: Cannot specify --output with --check
1 change: 1 addition & 0 deletions test/cli/err_output_several_files.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ocamlformat: Must specify exactly one input file without --inplace or --check
1 change: 1 addition & 0 deletions test/cli/err_several_files_and_kind.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ocamlformat: Cannot specify --impl or --intf with multiple inputs
1 change: 1 addition & 0 deletions test/cli/err_several_files_and_kind_inplace.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ocamlformat: Cannot specify --impl or --intf with multiple inputs
1 change: 1 addition & 0 deletions test/cli/err_several_files_and_name.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ocamlformat: Cannot specify --name with multiple inputs
1 change: 1 addition & 0 deletions test/cli/err_several_files_and_name_inplace.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ocamlformat: Cannot specify --name with multiple inputs
1 change: 1 addition & 0 deletions test/cli/err_stdin_and_file.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ocamlformat: Cannot specify stdin together with other inputs
1 change: 1 addition & 0 deletions test/cli/err_stdin_and_inplace.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ocamlformat: Must specify at least one of --name, --impl or --intf when reading from stdin
1 change: 1 addition & 0 deletions test/cli/err_stdin_name_unknown_ext.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ocamlformat: Cannot deduce file kind from passed --name. Please specify --impl or --intf
1 change: 1 addition & 0 deletions test/cli/err_stdin_no_kind.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ocamlformat: Must specify at least one of --name, --impl or --intf when reading from stdin
3 changes: 3 additions & 0 deletions test/cli/fmterr_file_and_name.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ocamlformat: ignoring "foo.ml" (syntax error)
File "foo.ml", line 2, characters 0-0:
Error: Syntax error
3 changes: 3 additions & 0 deletions test/cli/fmterr_file_and_name_bad_kind.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ocamlformat: ignoring "foo.ml" (syntax error)
File "foo.ml", line 5, characters 0-0:
Error: Syntax error
3 changes: 3 additions & 0 deletions test/cli/fmterr_file_bad_kind.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ocamlformat: ignoring "sample/a.mli" (syntax error)
File "sample/a.mli", line 5, characters 0-0:
Error: Syntax error
3 changes: 3 additions & 0 deletions test/cli/fmterr_stdin_and_name.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ocamlformat: ignoring "foo.ml" (syntax error)
File "foo.ml", line 2, characters 0-0:
Error: Syntax error
3 changes: 3 additions & 0 deletions test/cli/fmterr_stdin_and_name_bad_kind.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ocamlformat: ignoring "foo.ml" (syntax error)
File "foo.ml", line 5, characters 0-0:
Error: Syntax error
3 changes: 3 additions & 0 deletions test/cli/fmterr_stdin_bad_kind.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ocamlformat: ignoring "<standard input>" (syntax error)
File "<standard input>", line 5, characters 0-0:
Error: Syntax error
1 change: 1 addition & 0 deletions test/cli/name_unknown_ext.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let () = print_endline A.x
1 change: 1 addition & 0 deletions test/cli/stdin_and_impl.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let () = print_endline A.x
4 changes: 4 additions & 0 deletions test/cli/stdin_and_intf.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
val x : string

module X : S
(** Make sure this file cannot be parsed as an impl file *)
1 change: 1 addition & 0 deletions test/cli/stdin_and_name.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let () = print_endline A.x
Loading

0 comments on commit aa6c896

Please sign in to comment.