Clerk: add more tests, and small fixes

This commit is contained in:
Louis Gesbert 2023-10-02 14:04:12 +02:00
parent a79acd1fa8
commit cc7c3fc18c
4 changed files with 72 additions and 8 deletions

View File

@ -243,7 +243,17 @@ module Poll = struct
fix your installation")
"command" ["-v"; "catala"])
let build_dir : File.t Lazy.t = lazy "_build"
let build_dir : File.t Lazy.t =
lazy
(let d = "_build" in
match Sys.is_directory d with
| exception Sys_error _ ->
Sys.mkdir d 0o770;
d
| true -> d
| false ->
Message.raise_error "Build directory %a exists but is not a directory"
File.format d)
(* Note: it could be safer here to use File.(Sys.getcwd () / "_build"), but
Ninja treats relative and absolute paths separately so that you wouldn't
then be able to build target _build/foo.ml but would have to write the full
@ -477,22 +487,20 @@ let gen_build_statements (item : Scan.item) : Nj.ninja =
in
let ml_file =
match item.module_def with
| Some m -> (src /../ m) ^ ".ml"
| None -> !Var.src ^ ".ml"
| Some m -> (!Var.builddir / src /../ m) ^ ".ml"
| None -> (!Var.builddir / !Var.src) ^ ".ml"
in
let ocaml =
Nj.build "catala-ocaml"
~inputs:[inc srcv]
~implicit_in:[!Var.catala_exe]
~outputs:[!Var.builddir / ml_file]
~implicit_in:[!Var.catala_exe] ~outputs:[ml_file]
in
let ocamlopt =
let implicit_out_exts = ["cmi"; "cmx"; "cmt"; "o"] in
match item.module_def with
| Some m ->
let target ext = (!Var.builddir / src /../ m) ^ "." ^ ext in
Nj.build "ocaml-module"
~inputs:[!Var.builddir / ml_file]
Nj.build "ocaml-module" ~inputs:[ml_file]
~implicit_in:
(List.map (fun m -> (!Var.builddir / src /../ m) ^ ".cmi") modules)
~outputs:[target "cmxs"]

View File

@ -814,7 +814,8 @@ let line_dir_arg_re =
Re.(compile @@ seq [
bos; char '>'; rep space; rep1 alpha;
alt [rep1 space; seq [rep space; char ':'; rep space]];
group (rep1 (diff any space))
group (rep1 (diff any space));
eol
])
let lex_line (lexbuf : lexbuf) : (string * L.line_token) option =

View File

@ -0,0 +1,23 @@
> Module Mod_middle
> Using Mod_def
```catala-metadata
declaration scope S:
input x content integer
output o1 content Mod_def.S
# context -- this should work
output o2 content money
```
```catala
scope S:
definition o1 equals output of Mod_def.S
# definition o2 equals o1.Mod_def.S.sr * 2 -- this should work ?
definition o2 equals $44 * (decimal of x)
```
```catala-test-inline
$ catala typecheck
[RESULT] Typechecking successful!
```

View File

@ -0,0 +1,32 @@
> Using Mod_middle
```catala
declaration scope T:
t1 scope Mod_middle.S
# input i content Enum1
output o1 content Mod_def.S
output o2 content money
scope T:
definition t1.x equals 3
definition o1 equals t1.o1
definition o2 equals t1.o2
```
```catala-test-inline
$ catala interpret -s T
[RESULT] Computation successful! Results:
[RESULT] o1 = Mod_def.S { -- sr: $1,000.00 -- e1: Maybe () }
[RESULT] o2 = $132.00
```
> Include: mod_use.catala_en
```catala-test-inline
$ catala interpret -s T2
[RESULT] Computation successful! Results:
[RESULT] o1 = No ()
[RESULT] o2 = Maybe ()
[RESULT] o3 = $1,000.00
[RESULT] o4 = 5.0
```