diff --git a/ptests/ptests.ml b/ptests/ptests.ml index 226880e6fa4d3e127c358cf6c08a5657b6c43be2..0ce12ee2f3eaf0e458387973e083989719c5fb40 100644 --- a/ptests/ptests.ml +++ b/ptests/ptests.ml @@ -31,6 +31,7 @@ let system = else fun f -> Unix.system f + module Filename = struct include Filename let concat = @@ -56,6 +57,8 @@ module Filename = struct cygpath r else fun a b -> temp_file a b + + let robust f = String.escaped f end let string_del_suffix suffix s = @@ -963,7 +966,7 @@ let get_macros cmd = "PTEST_DIR", SubDir.get cmd.directory; "PTEST_RESULT", SubDir.get cmd.directory ^ "/" ^ redefine_name "result"; - "PTEST_FILE", ptest_file; + "PTEST_FILE", Filename.robust ptest_file; "PTEST_NAME", ptest_name; "PTEST_NUMBER", string_of_int cmd.n; ] @@ -971,14 +974,16 @@ let get_macros cmd = Macros.add_list macros cmd.macros let basic_command_string = - let contains_toplevel_or_frama_c = + let contains_toplevel_or_frama_c = Str.regexp "[^( ]*\\(\\(toplevel\\)\\|\\(viewer\\)\\|\\(frama-c\\)\\).*" in fun command -> let macros = get_macros command in let logfiles = List.map (Macros.expand macros) command.log_files in command.log_files <- logfiles; - let has_ptest_file_t, toplevel = Macros.does_expand macros command.toplevel in + let has_ptest_file_t, toplevel = + Macros.does_expand macros command.toplevel + in let has_ptest_file_o, options = Macros.does_expand macros command.options in let toplevel = if !use_byte then opt_to_byte toplevel else toplevel in let options = @@ -994,8 +999,10 @@ let basic_command_string = let options = if !use_byte then opt_to_byte_options options else options in if has_ptest_file_t || has_ptest_file_o || command.execnow then toplevel ^ " " ^ options - else - toplevel ^ " " ^ get_ptest_file command ^ " " ^ options + else begin + let file = Filename.robust @@ get_ptest_file command in + toplevel ^ " " ^ file ^ " " ^ options + end (* Searches for executable [s] in the directories contained in the PATH environment variable. Returns [None] if not found, or @@ -1073,18 +1080,23 @@ let command_string command = in let command_string = basic_command_string command in let command_string = - command_string ^ " 2>" ^ stderr + command_string ^ " 2>" ^ (Filename.robust stderr) in let command_string = match filter with | None -> command_string | Some filter -> command_string ^ " | " ^ filter in - let command_string = command_string ^ " >" ^ log_prefix ^ ".res.log" in + let res = Filename.robust (log_prefix ^ ".res.log") in + let command_string = command_string ^ " >" ^ res in let command_string = match filter with | None -> command_string | Some filter -> Printf.sprintf "%s && %s < %s >%s && rm -f %s" - command_string filter stderr errlog stderr + command_string + filter + (Filename.robust stderr) + (Filename.robust errlog) + (Filename.robust stderr) in command_string @@ -1367,8 +1379,8 @@ let compare_one_file cmp log_prefix oracle_prefix log_kind = -1 end else let ext = log_ext log_kind in - let log_file = log_prefix ^ ext ^ ".log" in - let oracle_file = oracle_prefix ^ ext ^ ".oracle" in + let log_file = Filename.robust (log_prefix ^ ext ^ ".log") in + let oracle_file = Filename.robust (oracle_prefix ^ ext ^ ".oracle") in if log_kind = Err && not (Sys.file_exists oracle_file) then check_file_is_empty_or_nonexisting (Command_error (cmp,log_kind)) ~log_file else begin @@ -1391,8 +1403,8 @@ let compare_one_log_file dir file = Condition.signal shared.diff_available; unlock() end else - let log_file = SubDir.make_result_file dir file in - let oracle_file = SubDir.make_oracle_file dir file in + let log_file = Filename.robust (SubDir.make_result_file dir file) in + let oracle_file = Filename.robust (SubDir.make_oracle_file dir file) in let cmp_string = !do_cmp ^ " " ^ log_file ^ " " ^ oracle_file ^ " > /dev/null 2> /dev/null" in if !verbosity >= 2 then lock_printf "%% cmplog: %s / %s@." (SubDir.get dir) file; ignore (launch_and_check_compare_file (Log_error (dir,file)) @@ -1465,28 +1477,33 @@ let do_diff = function | Command_error (diff, kind) -> let log_prefix = log_prefix diff in let log_ext = log_ext kind in + let log_file = Filename.robust (log_prefix ^ log_ext ^ ".log") in let command_string = command_string diff in lock_printf "%tCommand:@\n%s@." print_default_env command_string; if !behavior = Show - then ignore (launch ("cat " ^ log_prefix ^ log_ext ^ ".log")) + then ignore (launch ("cat " ^ log_file)) else let oracle_prefix = oracle_prefix diff in - let diff_string = - !do_diffs ^ " " ^ - oracle_prefix ^ log_ext ^ ".oracle " ^ - log_prefix ^ log_ext ^ ".log" + let oracle_file = + Filename.robust (oracle_prefix ^ log_ext ^ ".oracle") in + let diff_string = !do_diffs ^ " " ^ oracle_file ^ " " ^ log_file in ignore (launch diff_string) | Target_error execnow -> lock_printf "Custom command failed: %s@\n" execnow.ex_cmd | Log_error(dir, file) -> - let result_file = SubDir.make_result_file dir file in + let result_file = + Filename.robust (SubDir.make_result_file dir file) + in lock_printf "Log of %s:@." result_file; if !behavior = Show then ignore (launch ("cat " ^ result_file)) else + let oracle_file = + Filename.robust (SubDir.make_oracle_file dir file) + in let diff_string = - !do_diffs ^ " " ^ SubDir.make_oracle_file dir file ^ " " ^ result_file + !do_diffs ^ " " ^ oracle_file ^ " " ^ result_file in ignore (launch diff_string) @@ -1519,7 +1536,10 @@ let default_config () = if Sys.file_exists general_config_file then begin let scan_buffer = Scanf.Scanning.from_file general_config_file in - scan_options (SubDir.create ~with_subdir:false Filename.current_dir_name) scan_buffer (default_config ()) + scan_options + (SubDir.create ~with_subdir:false Filename.current_dir_name) + scan_buffer + (default_config ()) end else default_config () diff --git "a/tests/syntax/foo\".c" "b/tests/syntax/foo\".c" new file mode 100644 index 0000000000000000000000000000000000000000..fa4ba0ab9ae9b4f51247cc78b369db0154bdfa9a --- /dev/null +++ "b/tests/syntax/foo\".c" @@ -0,0 +1,7 @@ +#include "share/libc/assert.h" + +int test = 1; + +int main () { + assert(test); +} diff --git "a/tests/syntax/oracle/foo\".res.oracle" "b/tests/syntax/oracle/foo\".res.oracle" new file mode 100644 index 0000000000000000000000000000000000000000..ad66d6d1d2a99d868ff98d09a19696fe20ac787c --- /dev/null +++ "b/tests/syntax/oracle/foo\".res.oracle" @@ -0,0 +1,13 @@ +[kernel] Parsing tests/syntax/foo".c (with preprocessing) +/* Generated by Frama-C */ +#include "assert.h" +int test = 1; +int main(void) +{ + int __retres; + __FC_assert(test != 0,"tests/syntax/foo\".c",6,"test"); + __retres = 0; + return __retres; +} + +