mirror of
https://github.com/CatalaLang/catala.git
synced 2024-09-19 00:15:39 +03:00
Inline tests: add lightweight sanitisation of the command outputs
This commit is contained in:
parent
a94c5fe644
commit
d0998312eb
@ -548,8 +548,11 @@ let[@ocamlformat "disable"] static_base_rules =
|
|||||||
Nj.rule "out-test"
|
Nj.rule "out-test"
|
||||||
~command: [
|
~command: [
|
||||||
!catala_exe; !test_command; "--plugin-dir="; "-o -"; !catala_flags;
|
!catala_exe; !test_command; "--plugin-dir="; "-o -"; !catala_flags;
|
||||||
!input; ">"; !output; "2>&1";
|
!input; "2>&1";
|
||||||
"||"; "true";
|
"|"; "sed";
|
||||||
|
"'s/\"CM0|[a-zA-Z0-9|]*\"/\"CMX|XXXXXXXX|XXXXXXXX|XXXXXXXX\"/g'";
|
||||||
|
">"; !output;
|
||||||
|
"||"; "true"
|
||||||
]
|
]
|
||||||
~description:
|
~description:
|
||||||
["<catala>"; "test"; !test_id; "⇐"; !input; "(" ^ !test_command ^ ")"];
|
["<catala>"; "test"; !test_id; "⇐"; !input; "(" ^ !test_command ^ ")"];
|
||||||
|
@ -16,6 +16,27 @@
|
|||||||
|
|
||||||
open Catala_utils
|
open Catala_utils
|
||||||
|
|
||||||
|
let sanitize =
|
||||||
|
let re_endtest = Re.(compile @@ seq [bol; str "```"]) in
|
||||||
|
let re_modhash =
|
||||||
|
Re.(
|
||||||
|
compile
|
||||||
|
@@ seq
|
||||||
|
[
|
||||||
|
str "\"CM0|";
|
||||||
|
repn xdigit 8 (Some 8);
|
||||||
|
char '|';
|
||||||
|
repn xdigit 8 (Some 8);
|
||||||
|
char '|';
|
||||||
|
repn xdigit 8 (Some 8);
|
||||||
|
char '"';
|
||||||
|
])
|
||||||
|
in
|
||||||
|
fun str ->
|
||||||
|
str
|
||||||
|
|> Re.replace_string re_endtest ~by:"\\```"
|
||||||
|
|> Re.replace_string re_modhash ~by:"\"CMX|XXXXXXXX|XXXXXXXX|XXXXXXXX\""
|
||||||
|
|
||||||
let run_catala_test test_flags catala_exe catala_opts file program args oc =
|
let run_catala_test test_flags catala_exe catala_opts file program args oc =
|
||||||
let cmd_in_rd, cmd_in_wr = Unix.pipe ~cloexec:true () in
|
let cmd_in_rd, cmd_in_wr = Unix.pipe ~cloexec:true () in
|
||||||
let cmd_out_rd, cmd_out_wr = Unix.pipe ~cloexec:true () in
|
let cmd_out_rd, cmd_out_wr = Unix.pipe ~cloexec:true () in
|
||||||
@ -70,8 +91,9 @@ let run_catala_test test_flags catala_exe catala_opts file program args oc =
|
|||||||
let out_lines =
|
let out_lines =
|
||||||
Seq.of_dispenser (fun () -> In_channel.input_line command_ic)
|
Seq.of_dispenser (fun () -> In_channel.input_line command_ic)
|
||||||
in
|
in
|
||||||
Seq.iter (fun line ->
|
Seq.iter
|
||||||
output_string oc line;
|
(fun line ->
|
||||||
|
output_string oc (sanitize line);
|
||||||
output_char oc '\n')
|
output_char oc '\n')
|
||||||
out_lines;
|
out_lines;
|
||||||
let return_code =
|
let return_code =
|
||||||
|
Loading…
Reference in New Issue
Block a user