diff --git a/test/blackbox-tests/jbuild b/test/blackbox-tests/jbuild index 9c142ad5..056475cc 100644 --- a/test/blackbox-tests/jbuild +++ b/test/blackbox-tests/jbuild @@ -141,3 +141,10 @@ (action (chdir test-cases/multiple-private-libs (setenv JBUILDER ${bin:jbuilder} (run ${exe:cram.exe} -ocamlv ${ocaml_version} -skip-versions 4.02.3 run.t)))))) + +(alias + ((name runtest) + (deps ((files_recursively_in test-cases/ppx-rewriter))) + (action + (chdir test-cases/ppx-rewriter + (setenv JBUILDER ${bin:jbuilder} (run ${exe:cram.exe} -ocamlv ${ocaml_version} -skip-versions 4.02.3 run.t)))))) diff --git a/test/blackbox-tests/test-cases/ppx-rewriter/jbuild b/test/blackbox-tests/test-cases/ppx-rewriter/jbuild new file mode 100644 index 00000000..9fd8d486 --- /dev/null +++ b/test/blackbox-tests/test-cases/ppx-rewriter/jbuild @@ -0,0 +1,16 @@ +(jbuild_version 1) + +(executable + ((name w_omp_driver) + (modules (w_omp_driver)) + (preprocess (pps (fooppx -flag (-arg omp)))))) + +(executable + ((name w_ppx_driver) + (modules (w_ppx_driver)) + (preprocess (pps (ppx_driver.runner))))) + +(executable + ((name w_ppx_driver_flags) + (modules (w_ppx_driver_flags)) + (preprocess (pps (fooppx -flag (-arg omp) ppx_driver.runner))))) diff --git a/test/blackbox-tests/test-cases/ppx-rewriter/ppx/fooppx.ml b/test/blackbox-tests/test-cases/ppx-rewriter/ppx/fooppx.ml new file mode 100644 index 00000000..d66308a9 --- /dev/null +++ b/test/blackbox-tests/test-cases/ppx-rewriter/ppx/fooppx.ml @@ -0,0 +1,21 @@ +let flag = ref false +let arg = ref "" + +let () = + Migrate_parsetree.Driver.register + ~name:"linter" + ~args:([ "-flag", Arg.Set flag, "" + ; "-arg", Arg.Set_string arg, "" + ]) + Migrate_parsetree.Versions.ocaml_405 + (fun _ cookies -> + if not !flag then ( + Format.eprintf "pass -flag to fooppx@.%!"; + exit 1 + ); + if !arg = "" then ( + Format.eprintf "pass -arg to fooppx@.%!" + ); + Format.eprintf "-arg: %s%@." !arg; + Migrate_parsetree.Ast_405.shallow_identity + ) diff --git a/test/blackbox-tests/test-cases/ppx-rewriter/ppx/jbuild b/test/blackbox-tests/test-cases/ppx-rewriter/ppx/jbuild new file mode 100644 index 00000000..692b397d --- /dev/null +++ b/test/blackbox-tests/test-cases/ppx-rewriter/ppx/jbuild @@ -0,0 +1,4 @@ +(library + ((name fooppx) + (kind ppx_rewriter) + (libraries (ocaml-migrate-parsetree)))) diff --git a/test/blackbox-tests/test-cases/ppx-rewriter/run.t b/test/blackbox-tests/test-cases/ppx-rewriter/run.t new file mode 100644 index 00000000..4fcd6fdf --- /dev/null +++ b/test/blackbox-tests/test-cases/ppx-rewriter/run.t @@ -0,0 +1,63 @@ + $ $JBUILDER build ./w_omp_driver.exe -j1 --root . + ocamldep ppx/fooppx.depends.ocamldep-output + ocamlc ppx/fooppx.{cmi,cmo,cmt} + ocamlopt ppx/fooppx.{cmx,o} + ocamlopt ppx/fooppx.{a,cmxa} + ocamlopt .ppx/fooppx/ppx.exe + ppx w_omp_driver.pp.ml + ocamldep w_omp_driver.depends.ocamldep-output + ocamlc w_omp_driver.{cmi,cmo,cmt} + ocamlopt w_omp_driver.{cmx,o} + ocamlopt w_omp_driver.exe + $ $JBUILDER build ./w_ppx_driver.exe -j1 --root . + ocamlopt .ppx/ppx_driver.runner/ppx.exe + ppx w_ppx_driver.pp.ml + ocamldep w_ppx_driver.depends.ocamldep-output + ocamlc w_ppx_driver.{cmi,cmo,cmt} + ocamlopt w_ppx_driver.{cmx,o} + ocamlopt w_ppx_driver.exe + $ $JBUILDER build ./w_ppx_driver_flags.exe -j1 --root . + ocamlopt .ppx/fooppx+ppx_driver.runner/ppx.exe + ppx w_ppx_driver_flags.pp.ml (exit 2) + (cd _build/default && ./.ppx/fooppx+ppx_driver.runner/ppx.exe -flag -arg omp --dump-ast -o w_ppx_driver_flags.pp.ml --impl w_ppx_driver_flags.ml) + ./.ppx/fooppx+ppx_driver.runner/ppx.exe: unknown option '-flag'. + ppx.exe [extra_args] [] + -loc-filename File name to use in locations + -reserve-namespace Mark the given namespace as reserved + -no-check Disable checks (unsafe) + -do-check Enable checks + -apply Apply these transformations in order (comma-separated list) + -dont-apply Exclude these transformations + -no-merge Do not merge context free transformations (better for debugging rewriters) + -as-ppx Run as a -ppx rewriter (must be the first argument) + --as-ppx Same as -as-ppx + -as-pp Shorthand for: -dump-ast -embed-errors + --as-pp Same as -as-pp + -o Output file (use '-' for stdout) + - Read input from stdin + -no-optcomp Do not use optcomp (default if the input or output of -pp is a binary AST) + -dump-ast Dump the marshaled ast to the output file instead of pretty-printing it + --dump-ast Same as -dump-ast + -dparsetree Print the parsetree (same as ocamlc -dparsetree) + -embed-errors Embed errors in the output AST (default: true when -dump-ast, false otherwise) + -null Produce no output, except for errors + -impl Treat the input as a .ml file + --impl Same as -impl + -intf Treat the input as a .mli file + --intf Same as -intf + -debug-attribute-drop Debug attribute dropping + -print-transformations Print linked-in code transformations, in the order they are applied + -print-passes Print the actual passes over the whole AST in the order they are applied + -ite-check Enforce that "complex" if branches are delimited (disabled if -pp is given) + -pp Pipe sources through preprocessor (incompatible with -as-ppx) + -reconcile (WIP) Pretty print the output using a mix of the input source and the generated code + -reconcile-with-comments (WIP) same as -reconcile but uses comments to enclose the generated code + -no-color Don't use colors when printing errors + -diff-cmd Diff command when using code expectations + -pretty Instruct code generators to improve the prettiness of the generated code + -styler Code styler + -cookie NAME=EXPR Set the cookie NAME to EXPR + --cookie Same as -cookie + -help Display this list of options + --help Display this list of options + [1] diff --git a/test/blackbox-tests/test-cases/ppx-rewriter/w_omp_driver.ml b/test/blackbox-tests/test-cases/ppx-rewriter/w_omp_driver.ml new file mode 100644 index 00000000..e69de29b diff --git a/test/blackbox-tests/test-cases/ppx-rewriter/w_ppx_driver.ml b/test/blackbox-tests/test-cases/ppx-rewriter/w_ppx_driver.ml new file mode 100644 index 00000000..e69de29b diff --git a/test/blackbox-tests/test-cases/ppx-rewriter/w_ppx_driver_flags.ml b/test/blackbox-tests/test-cases/ppx-rewriter/w_ppx_driver_flags.ml new file mode 100644 index 00000000..e69de29b