Improve reason tests
* Test that modules are actually built by running their code. * Make reasonlypp to also be a linter * Make the reason only pp double as linter When ran with the -lint flag
This commit is contained in:
parent
469079f9c6
commit
5dd8d028ae
|
@ -1,15 +1,52 @@
|
|||
let lint = ref false
|
||||
let fname = ref None
|
||||
let usage =
|
||||
Printf.sprintf "%s [-lint] file" (Filename.basename Sys.executable_name)
|
||||
let anon s =
|
||||
match !fname with
|
||||
| None -> fname := Some s
|
||||
| Some _ -> raise (Arg.Bad "file must only be given once")
|
||||
|
||||
let is_ascii s =
|
||||
try
|
||||
for i=0 to String.length s - 1 do
|
||||
if Char.code (s.[i]) > 127 then raise Exit
|
||||
done;
|
||||
true
|
||||
with Exit ->
|
||||
false
|
||||
|
||||
let () =
|
||||
let fname = Sys.argv.(1) in
|
||||
Arg.parse
|
||||
["-lint", Arg.Set lint, "lint instead of preprocessing"
|
||||
] anon usage;
|
||||
let fname =
|
||||
match !fname with
|
||||
| None -> raise (Arg.Bad "file must be provided")
|
||||
| Some f -> f in
|
||||
|
||||
if Filename.check_suffix fname ".re"
|
||||
|| Filename.check_suffix fname ".rei" then (
|
||||
if !lint && (Filename.check_suffix fname ".pp.re"
|
||||
|| Filename.check_suffix fname ".pp.rei") then (
|
||||
Format.eprintf "reason linter doesn't accept preprocessed file %s" fname;
|
||||
);
|
||||
let ch = open_in fname in
|
||||
let rec loop () =
|
||||
match input_line ch with
|
||||
| exception End_of_file -> ()
|
||||
| line -> print_endline line; loop () in
|
||||
| line when is_ascii line ->
|
||||
if not !lint then (
|
||||
print_endline line
|
||||
);
|
||||
loop ()
|
||||
| _ ->
|
||||
Format.eprintf "%s isn't source code@.%!" fname;
|
||||
exit 1
|
||||
in
|
||||
loop ();
|
||||
close_in ch
|
||||
close_in ch;
|
||||
exit 0
|
||||
) else (
|
||||
Format.eprintf "%s is not a reason source@.%!" fname;
|
||||
exit 1
|
||||
|
|
|
@ -3,4 +3,4 @@ open Rlib;
|
|||
Cppome.run();
|
||||
Hello.run();
|
||||
Bar.run();
|
||||
Foo.run();
|
||||
Foo.run();
|
||||
|
|
|
@ -86,9 +86,3 @@
|
|||
"_build/install/default/lib/rlib/rlib.a"
|
||||
"_build/install/default/lib/rlib/rlib.cmxs"
|
||||
]
|
||||
ocamlopt rbin.exe
|
||||
rbin alias runtest
|
||||
Cppome
|
||||
hello world
|
||||
Bar
|
||||
Foo
|
||||
|
|
Loading…
Reference in New Issue