unit test infrastructure for optimization

This commit is contained in:
adelaett 2023-03-17 17:19:50 +01:00
parent 850a1fdb56
commit 61ad00f277
3 changed files with 25 additions and 3 deletions

View File

@ -4,11 +4,9 @@
, benchmark , benchmark
, bindlib , bindlib
, buildDunePackage , buildDunePackage
, calendar
, cmdliner , cmdliner
, cppo , cppo
, dates_calc , dates_calc
, fetchFromGitHub
, js_of_ocaml , js_of_ocaml
, js_of_ocaml-ppx , js_of_ocaml-ppx
, menhir , menhir
@ -26,6 +24,7 @@
, zarith , zarith
, zarith_stubs_js , zarith_stubs_js
, cohttp-lwt-unix , cohttp-lwt-unix
, ppx_expect
}: }:
buildDunePackage { buildDunePackage {
@ -63,6 +62,7 @@ buildDunePackage {
zarith zarith
zarith_stubs_js zarith_stubs_js
cohttp-lwt-unix cohttp-lwt-unix
ppx_expect
]; ];
# Currently there is no unit tests in catala and Cram tests are handled by clerk # Currently there is no unit tests in catala and Cram tests are handled by clerk

View File

@ -2,8 +2,9 @@
(name lcalc) (name lcalc)
(public_name catala.lcalc) (public_name catala.lcalc)
(libraries bindlib ubase dcalc scopelang catala.runtime_ocaml) (libraries bindlib ubase dcalc scopelang catala.runtime_ocaml)
(inline_tests)
(preprocess (preprocess
(pps visitors.ppx))) (pps visitors.ppx ppx_expect)))
(documentation (documentation
(package catala) (package catala)

View File

@ -222,3 +222,24 @@ let optimize_program (p : 'm program) : untyped program =
(* _beta_optimizations; *) (* _beta_optimizations; *)
peephole_optimizations; peephole_optimizations;
]) ])
let%expect_test _ =
Cli.call_unstyled (fun _ ->
let x = Var.make "x" in
let t = EnumName.fresh ("t", Pos.no_pos) in
let a = EnumConstructor.fresh ("A", Pos.no_pos) in
let b = EnumConstructor.fresh ("B", Pos.no_pos) in
let nomark = Untyped { pos = Pos.no_pos } in
let e1 = Expr.einj (Expr.evar x nomark) a t nomark in
let e2 = Expr.einj (Expr.evar x nomark) b t nomark in
Format.printf "e1=%a\n" (Print.expr_debug ~debug:false) (Expr.unbox e1);
Format.printf "e2=%a\n" (Print.expr_debug ~debug:false) (Expr.unbox e2);
[%expect {|
e1=A (x)
e2=B
(x) |}])