Skip to content

Commit b87afe3

Browse files
committed
Port upstream 12185: new ocamltest script language
1 parent 7f72f40 commit b87afe3

18 files changed

+1886
-94
lines changed

ocaml/ocamltest/.depend

+19-1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ main.cmo : \
9494
tsl_semantics.cmi \
9595
tsl_parser.cmi \
9696
tsl_lexer.cmi \
97+
translate.cmi \
9798
tests.cmi \
9899
result.cmi \
99100
options.cmi \
@@ -107,6 +108,7 @@ main.cmx : \
107108
tsl_semantics.cmx \
108109
tsl_parser.cmx \
109110
tsl_lexer.cmx \
111+
translate.cmx \
110112
tests.cmx \
111113
result.cmx \
112114
options.cmx \
@@ -366,15 +368,18 @@ ocamltest_unix.cmx : \
366368
ocamltest_unix.cmi :
367369
options.cmo : \
368370
variables.cmi \
371+
translate.cmi \
369372
tests.cmi \
370373
actions.cmi \
371374
options.cmi
372375
options.cmx : \
373376
variables.cmx \
377+
translate.cmx \
374378
tests.cmx \
375379
actions.cmx \
376380
options.cmi
377-
options.cmi :
381+
options.cmi : \
382+
translate.cmi
378383
result.cmo : \
379384
result.cmi
380385
result.cmx : \
@@ -407,6 +412,19 @@ tests.cmi : \
407412
result.cmi \
408413
environments.cmi \
409414
actions.cmi
415+
translate.cmo : \
416+
tsl_semantics.cmi \
417+
tsl_parser.cmi \
418+
tsl_lexer.cmi \
419+
tsl_ast.cmi \
420+
translate.cmi
421+
translate.cmx : \
422+
tsl_semantics.cmx \
423+
tsl_parser.cmx \
424+
tsl_lexer.cmx \
425+
tsl_ast.cmx \
426+
translate.cmi
427+
translate.cmi :
410428
tsl_ast.cmo : \
411429
tsl_ast.cmi
412430
tsl_ast.cmx : \

ocaml/ocamltest/Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ core := \
4646
tsl_semantics.mli tsl_semantics.ml \
4747
builtin_variables.mli builtin_variables.ml \
4848
actions_helpers.mli actions_helpers.ml \
49-
builtin_actions.mli builtin_actions.ml
49+
builtin_actions.mli builtin_actions.ml \
50+
translate.mli translate.ml
5051

5152
ocaml_plugin := \
5253
ocaml_backends.mli ocaml_backends.ml \

ocaml/ocamltest/main.ml

+22-10
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,29 @@ let announce_test_error test_filename error =
2929
Printf.printf " ... testing '%s' => unexpected error (%s)\n%!"
3030
(Filename.basename test_filename) error
3131

32-
let tsl_block_of_file test_filename =
32+
exception Syntax_error of Lexing.position
33+
34+
let tsl_parse_file test_filename =
3335
let input_channel = open_in test_filename in
3436
let lexbuf = Lexing.from_channel input_channel in
3537
Location.init lexbuf test_filename;
36-
match Tsl_parser.tsl_block Tsl_lexer.token lexbuf with
38+
match Tsl_parser.tsl_script Tsl_lexer.token lexbuf with
39+
| exception Parsing.Parse_error ->
40+
raise (Syntax_error lexbuf.Lexing.lex_start_p)
3741
| exception e -> close_in input_channel; raise e
3842
| _ as tsl_block -> close_in input_channel; tsl_block
3943

40-
let tsl_block_of_file_safe test_filename =
41-
try tsl_block_of_file test_filename with
44+
let tsl_parse_file_safe test_filename =
45+
try tsl_parse_file test_filename with
4246
| Sys_error message ->
4347
Printf.eprintf "%s\n%!" message;
4448
announce_test_error test_filename message;
4549
exit 1
46-
| Parsing.Parse_error ->
47-
Printf.eprintf "Could not read test block in %s\n%!" test_filename;
48-
announce_test_error test_filename "could not read test block";
50+
| Syntax_error p ->
51+
let open Lexing in
52+
Printf.eprintf "%s:%d.%d: syntax error in test script\n%!"
53+
test_filename p.pos_lnum (p.pos_cnum - p.pos_bol);
54+
announce_test_error test_filename "could not read test script";
4955
exit 1
5056

5157
let print_usage () =
@@ -115,8 +121,8 @@ let init_tests_to_skip () =
115121
let test_file test_filename =
116122
let start = if Options.show_timings then Unix.gettimeofday () else 0.0 in
117123
let skip_test = List.mem test_filename !tests_to_skip in
118-
let tsl_block = tsl_block_of_file_safe test_filename in
119-
let (rootenv_statements, test_trees) = test_trees_of_tsl_block tsl_block in
124+
let tsl_ast = tsl_parse_file_safe test_filename in
125+
let (rootenv_statements, test_trees) = test_trees_of_tsl_ast tsl_ast in
120126
let test_trees = match test_trees with
121127
| [] ->
122128
let default_tests = Tests.default_tests() in
@@ -263,6 +269,12 @@ let () =
263269
let doit f x = work_done := true; f x in
264270
List.iter (doit find_test_dirs) Options.find_test_dirs;
265271
List.iter (doit list_tests) Options.list_tests;
266-
List.iter (doit test_file) Options.files_to_test;
272+
let do_file =
273+
if Options.translate then
274+
Translate.file ~style:Options.style ~compact:Options.compact
275+
else
276+
test_file
277+
in
278+
List.iter (doit do_file) Options.files_to_test;
267279
if not !work_done then print_usage();
268280
if !failed || not !work_done then exit 1

0 commit comments

Comments
 (0)