refactor(clerk): add test_file_* build to factorize all scope tests for one given file

This commit is contained in:
Emile Rolley 2022-02-08 14:29:12 +01:00
parent 1c1b3f0ec2
commit f5b9cd9794
3 changed files with 28 additions and 5 deletions

View File

@ -320,11 +320,12 @@ let collect_all_ninja_build (tested_file : string) (catala_exe : string) (_catal
(ninja_start catala_exe, "")
expected_outputs
in
let test_name = Printf.sprintf "test_file_%s" tested_file |> Nj.Build.unpath in
{
ninja with
builds =
Nj.BuildMap.add "test"
(Nj.Build.make_with_inputs ~outputs:[ Nj.Expr.Lit "test" ] ~rule:"phony"
Nj.BuildMap.add test_name
(Nj.Build.make_with_inputs ~outputs:[ Nj.Expr.Lit test_name ] ~rule:"phony"
~inputs:[ Nj.Expr.Lit test_names ])
ninja.builds;
}
@ -396,6 +397,26 @@ let driver (file_or_folder : string) (command : string) (catala_exe : string opt
| Some ninja ->
let out = open_out "build.ninja" in
Cli.debug_print "writing build.ninja...";
let re_test_file = Re.Pcre.regexp "^test_file_" in
let all_test_files =
Nj.BuildMap.bindings ninja.builds
|> List.filter_map (fun (name, _) ->
let len =
try Array.length (Re.Pcre.(extract ~rex:re_test_file) name) with _ -> 0
in
if 0 < len then Some name else None)
|> String.concat " "
in
let ninja =
{
ninja with
builds =
Nj.BuildMap.add "test"
(Nj.Build.make_with_inputs ~outputs:[ Nj.Expr.Lit "test" ] ~rule:"phony"
~inputs:[ Nj.Expr.Lit all_test_files ])
ninja.builds;
}
in
Nj.write out ninja;
close_out out;
Cli.debug_print "executing 'ninja test'...";

View File

@ -1,7 +1,7 @@
(** Expression containing variable references. *)
module Expr = struct
type t =
(* Sequence of expressions. *)
(* Sequence of sub-expressions. *)
| Seq of t list
(* Literal string. *)
| Lit of string
@ -11,7 +11,7 @@ module Expr = struct
let rec to_string = function
| Lit s -> s
| Var s -> "$" ^ s
| Seq ls -> List.fold_left (fun acc s -> acc ^ " " ^ to_string s) " " ls
| Seq ls -> List.fold_left (fun acc s -> acc ^ " " ^ to_string s) "" ls
let list_to_string ?(sep = " ") ls = ls |> List.map to_string |> String.concat sep
end

View File

@ -1,7 +1,7 @@
(** Expression containing variable references. *)
module Expr : sig
type t =
(* Sequence of expressions. *)
(* Sequence of sub-expressions. *)
| Seq of t list
(* Literal string. *)
| Lit of string
@ -24,6 +24,8 @@ end
module Build : sig
type t = {
outputs : Expr.t list;
(* NOTE: what's the difference between [Expr.t list] and [Expr.Seq]? => [Expr.Seq] is a unique
expression with possible variable references => no space in its string representation. *)
rule : string;
inputs : Expr.t list option;
vars : (string * Expr.t) list;