Skip to content

Commit a0777ca

Browse files
authored
flambda-backend: Upstream port: new ocamltest language (#2444)
* Remove accidentally-ported TSan tests * Port upstream 12194: Check for syntax errors in test scripts instead of ignoring them. * Port upstream 12185: new ocamltest script language * Translate tests to new ocamltest script language
1 parent 337d4a0 commit a0777ca

File tree

1,497 files changed

+11574
-8425
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,497 files changed

+11574
-8425
lines changed

ocamltest/.depend

Lines changed: 19 additions & 1 deletion
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 : \

ocamltest/Makefile

Lines changed: 2 additions & 1 deletion
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 \

ocamltest/main.ml

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,46 +22,36 @@ type behavior =
2222
| Skip_all_tests
2323
| Run of Environments.t
2424

25-
(*
26-
let first_token filename =
27-
let input_channel = open_in filename in
28-
let lexbuf = Lexing.from_channel input_channel in
29-
Location.init lexbuf filename;
30-
let token =
31-
try Tsl_lexer.token lexbuf with e -> close_in input_channel; raise e
32-
in close_in input_channel; token
33-
34-
let is_test filename =
35-
match first_token filename with
36-
| exception _ -> false
37-
| Tsl_parser.TSL_BEGIN_C_STYLE | TSL_BEGIN_OCAML_STYLE -> true
38-
| _ -> false
39-
*)
40-
4125
(* this primitive announce should be used for tests
4226
that were aborted on system error before ocamltest
4327
could parse them *)
4428
let announce_test_error test_filename error =
4529
Printf.printf " ... testing '%s' => unexpected error (%s)\n%!"
4630
(Filename.basename test_filename) error
4731

48-
let tsl_block_of_file test_filename =
32+
exception Syntax_error of Lexing.position
33+
34+
let tsl_parse_file test_filename =
4935
let input_channel = open_in test_filename in
5036
let lexbuf = Lexing.from_channel input_channel in
5137
Location.init lexbuf test_filename;
52-
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)
5341
| exception e -> close_in input_channel; raise e
5442
| _ as tsl_block -> close_in input_channel; tsl_block
5543

56-
let tsl_block_of_file_safe test_filename =
57-
try tsl_block_of_file test_filename with
44+
let tsl_parse_file_safe test_filename =
45+
try tsl_parse_file test_filename with
5846
| Sys_error message ->
5947
Printf.eprintf "%s\n%!" message;
6048
announce_test_error test_filename message;
6149
exit 1
62-
| Parsing.Parse_error ->
63-
Printf.eprintf "Could not read test block in %s\n%!" test_filename;
64-
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";
6555
exit 1
6656

6757
let print_usage () =
@@ -131,8 +121,8 @@ let init_tests_to_skip () =
131121
let test_file test_filename =
132122
let start = if Options.show_timings then Unix.gettimeofday () else 0.0 in
133123
let skip_test = List.mem test_filename !tests_to_skip in
134-
let tsl_block = tsl_block_of_file_safe test_filename in
135-
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
136126
let test_trees = match test_trees with
137127
| [] ->
138128
let default_tests = Tests.default_tests() in
@@ -221,10 +211,12 @@ let test_file test_filename =
221211
Printf.eprintf "Wall clock: %s took %.02fs\n%!"
222212
test_filename wall_clock_duration
223213

224-
let is_test s =
225-
match tsl_block_of_file s with
226-
| _ -> true
227-
| exception _ -> false
214+
let is_test filename =
215+
let input_channel = open_in filename in
216+
let lexbuf = Lexing.from_channel input_channel in
217+
Fun.protect ~finally:(fun () -> close_in input_channel) begin fun () ->
218+
Tsl_lexer.is_test lexbuf
219+
end
228220

229221
let ignored s =
230222
s = "" || s.[0] = '_' || s.[0] = '.'
@@ -277,6 +269,12 @@ let () =
277269
let doit f x = work_done := true; f x in
278270
List.iter (doit find_test_dirs) Options.find_test_dirs;
279271
List.iter (doit list_tests) Options.list_tests;
280-
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;
281279
if not !work_done then print_usage();
282280
if !failed || not !work_done then exit 1

0 commit comments

Comments
 (0)