@@ -29,23 +29,29 @@ let announce_test_error test_filename error =
29
29
Printf. printf " ... testing '%s' => unexpected error (%s)\n %!"
30
30
(Filename. basename test_filename) error
31
31
32
- let tsl_block_of_file test_filename =
32
+ exception Syntax_error of Lexing. position
33
+
34
+ let tsl_parse_file test_filename =
33
35
let input_channel = open_in test_filename in
34
36
let lexbuf = Lexing. from_channel input_channel in
35
37
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)
37
41
| exception e -> close_in input_channel; raise e
38
42
| _ as tsl_block -> close_in input_channel; tsl_block
39
43
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
42
46
| Sys_error message ->
43
47
Printf. eprintf " %s\n %!" message;
44
48
announce_test_error test_filename message;
45
49
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" ;
49
55
exit 1
50
56
51
57
let print_usage () =
@@ -115,8 +121,8 @@ let init_tests_to_skip () =
115
121
let test_file test_filename =
116
122
let start = if Options. show_timings then Unix. gettimeofday () else 0.0 in
117
123
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
120
126
let test_trees = match test_trees with
121
127
| [] ->
122
128
let default_tests = Tests. default_tests() in
@@ -263,6 +269,12 @@ let () =
263
269
let doit f x = work_done := true ; f x in
264
270
List. iter (doit find_test_dirs) Options. find_test_dirs;
265
271
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;
267
279
if not ! work_done then print_usage() ;
268
280
if ! failed || not ! work_done then exit 1
0 commit comments