diff --git a/test/502_pexpfun/check_locations_integrity.ml b/test/502_pexpfun/check_locations_integrity.ml deleted file mode 100644 index b3f7ae9c4..000000000 --- a/test/502_pexpfun/check_locations_integrity.ml +++ /dev/null @@ -1,49 +0,0 @@ -module To_before_502 = - Ppxlib_ast.Convert (Ppxlib_ast.Js) (Ppxlib_ast__.Versions.OCaml_501) - -module OCaml_501 = Ppxlib_ast__.Versions.OCaml_501.Ast - -let is_valid_location ~(parent : Location.t) ~(child : Location.t) = - parent.loc_start <= child.loc_start && parent.loc_end >= child.loc_end - -let string_of_loc (loc : Location.t) : string = - Printf.sprintf "File \"%s\", line %d, characters %d-%d" - loc.loc_start.pos_fname loc.loc_start.pos_lnum - (loc.loc_start.pos_cnum - loc.loc_start.pos_bol) - (loc.loc_end.pos_cnum - loc.loc_start.pos_bol) - -let rec check_locations (expr : OCaml_501.Parsetree.expression) = - match expr.pexp_desc with - | Pexp_newtype (_label, exp) -> - let parent = expr.pexp_loc in - let child = exp.pexp_loc in - if not (is_valid_location ~parent ~child) then - Location.raise_errorf ~loc:parent - "Function's location is not larger than its body\n\ - Parent location: %s\n\ - Child location: %s" (string_of_loc parent) (string_of_loc child); - check_locations exp - | Pexp_fun (_, _, _, body) -> - let parent = expr.pexp_loc in - let child = body.pexp_loc in - if not (is_valid_location ~parent ~child) then - Location.raise_errorf ~loc:parent - "Function's location is not larger than its body\n\ - Parent location: %s\n\ - Child location: %s" (string_of_loc parent) (string_of_loc child); - check_locations body - | _ -> () - -let check_stri_locations stri = - let open OCaml_501.Parsetree in - match stri.pstr_desc with - | Pstr_value (_rec_flag, [ { pvb_expr; _ } ]) -> check_locations pvb_expr - | _ -> () - -let impl _ctxt str = - let before_502_ast = To_before_502.copy_structure str in - List.iter check_stri_locations before_502_ast; - str - -let () = Ppxlib.Driver.V2.register_transformation ~impl "foo" -let () = Ppxlib.Driver.standalone () diff --git a/test/502_pexpfun/driver.ml b/test/502_pexpfun/driver.ml new file mode 100644 index 000000000..e3cba4049 --- /dev/null +++ b/test/502_pexpfun/driver.ml @@ -0,0 +1 @@ +let () = Ppxlib.Driver.standalone () diff --git a/test/502_pexpfun/dune b/test/502_pexpfun/dune index 1cfb1d44c..2987ccb2c 100644 --- a/test/502_pexpfun/dune +++ b/test/502_pexpfun/dune @@ -1,11 +1,10 @@ (executable - (name check_locations_integrity) + (name driver) (enabled_if (>= %{ocaml_version} "5.2")) - (libraries ppxlib ppxlib.ast ppxlib.astlib ocaml-compiler-libs.common - compiler-libs.common)) + (libraries ppxlib)) (cram (enabled_if (>= %{ocaml_version} "5.2")) - (deps check_locations_integrity.exe)) + (deps driver.exe)) diff --git a/test/502_pexpfun/run.t b/test/502_pexpfun/run.t index b07f33f98..e16c0d16c 100644 --- a/test/502_pexpfun/run.t +++ b/test/502_pexpfun/run.t @@ -9,11 +9,11 @@ We run a custom driver that will read our ast, migrate it back to 5.01, and check that the locations are valid (the parent range is larger than the child range). - $ ./check_locations_integrity.exe --impl test.ml -o ignore.ml + $ ./driver.exe -locations-check --impl test.ml -o ignore.ml Locations should also be well formed for Pparam_newtype $ cat > test.ml << EOF > let make (type t) (type u) foo = foo > EOF - $ ./check_locations_integrity.exe --impl test.ml -o ignore.ml + $ ./driver.exe -locations-check --impl test.ml -o ignore.ml