Skip to content

Commit bdbbd9c

Browse files
committed
[pure] [lsp] Try to recover unit testing of pure interface
PR #289 silently removed important unit tests in the Pure module. We try to recover them, but indeed, they don't work, as it seems the library handling API introduced in #289 is lacking in terms of how it can be used. There seem to be many problems with the new system in terms of what a language server needs, in particular regarding assumptions about the underlying file system.
1 parent 671f1e8 commit bdbbd9c

File tree

6 files changed

+151
-0
lines changed

6 files changed

+151
-0
lines changed

lambdapi.opam

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ depends: [
3939
"odoc" {with-doc}
4040
"lwt_ppx" {>= "1.0.0"}
4141
"dream" {>= "1.0.0~alpha3"}
42+
# tests
43+
"ppx_inline_test" { with-test }
4244
]
4345
build: [
4446
["dune" "subst"] {dev}

src/pure/dune

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22
(name pure)
33
(public_name lambdapi.pure)
44
(modules :standard)
5+
(inline_tests (deps tests/foo.lp tests/lambdapi.pkg))
6+
(preprocess (pps ppx_inline_test))
57
(libraries camlp-streams lambdapi.handle lambdapi.core)
68
(flags -w +3))

src/pure/foo.lp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
constant symbol B : TYPE;
2+
3+
constant symbol true : B;
4+
constant symbol false : B;
5+
6+
symbol neg : BB;
7+
8+
rule neg truefalse;
9+
rule neg falsetrue;
10+
11+
constant symbol Prop : TYPE;
12+
13+
injective symbol P : PropTYPE;
14+
15+
constant symbol eq : BBProp;
16+
constant symbol refl b : P (eq b b);
17+
18+
constant symbol case (p : BProp) : P (p true) → P (p false) → Π b, P b;
19+
20+
opaque symbol notK : Π b, P (eq (neg (neg b)) b)
21+
begin
22+
assume b;
23+
apply caseb, eq (neg (neg b)) b)
24+
{apply refl}
25+
{apply refl}
26+
end;

src/pure/pure.ml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,96 @@ let end_proof : proof_state -> command_result =
189189

190190
let get_symbols : state -> Term.sym Extra.StrMap.t =
191191
fun (_, ss) -> ss.in_scope
192+
193+
(* Equality on *)
194+
let test_file = "./tests/foo.lp"
195+
196+
(* Equality is reflexive *)
197+
let%test _ =
198+
let _st = initial_state test_file in
199+
let (c,_) = parse_text (* st *) ~fname:test_file "constant symbol B : TYPE;" in
200+
List.equal Command.equal c c
201+
202+
(* Equality not *)
203+
let%test _ =
204+
let _st = initial_state test_file in
205+
let (c,_) = parse_text (* st *) ~fname:test_file "constant symbol B : TYPE;" in
206+
let (d,_) = parse_text (* st *) ~fname:test_file "constant symbol C : TYPE;" in
207+
not (List.equal Command.equal c d)
208+
209+
(* Equality is not sensitive to whitespace *)
210+
let%test _ =
211+
let _st = initial_state test_file in
212+
let (c,_) = parse_text (* st *) ~fname:test_file "constant symbol B : TYPE;" in
213+
let (d,_) = parse_text (* st *) ~fname:test_file " constant symbol B : TYPE; " in
214+
List.equal Command.equal c d
215+
216+
(* More complex tests stressing most commands *)
217+
218+
(* Equality is reflexive *)
219+
let%test _ =
220+
let _st = initial_state test_file in
221+
let (c,_) = parse_text (* st *) ~fname:test_file
222+
(* copied from tests/OK/foo.lp. keep in sync. *)
223+
"constant symbol B : TYPE;
224+
225+
constant symbol true : B;
226+
constant symbol false : B;
227+
228+
symbol neg : B → B;
229+
230+
rule neg true ↪ false;
231+
rule neg false ↪ true;
232+
233+
constant symbol Prop : TYPE;
234+
235+
injective symbol P : Prop → TYPE;
236+
237+
constant symbol eq : B → B → Prop;
238+
constant symbol refl b : P (eq b b);
239+
240+
constant symbol case (p : B → Prop) : P (p true) → P (p false) → Π b, P b;
241+
242+
opaque symbol notK : Π b, P (eq (neg (neg b)) b)
243+
≔ begin
244+
assume b;
245+
apply case (λ b, eq (neg (neg b)) b)
246+
{apply refl}
247+
{apply refl}
248+
end;
249+
" in
250+
List.equal Command.equal c c
251+
252+
(* TODO *)
253+
254+
(* test: Check that parsing from the file is the same that parsing from string *)
255+
256+
(* test: Check that parsing commutes *)
257+
258+
let pp_pos fmt (c : Command.t) =
259+
Format.fprintf fmt "%a" Pos.pp (Command.get_pos c)
260+
261+
(* auxiliary function *)
262+
let parse_split input =
263+
let input_split = String.split_on_char ';' input in
264+
let input_split = List.map (fun s -> s ^ ";") input_split in
265+
let input_split = List.(take (length input_split - 1)) input_split in
266+
Format.eprintf "input_split: @[%a@]@\n" Format.(pp_print_list pp_print_string) input_split;
267+
let cmds_1, _ = parse_text ~fname:test_file input in
268+
let cmds_2, _ = List.map (parse_text ~fname:test_file) input_split |> List.unzip in
269+
let cmds_2 = List.flatten cmds_2 in
270+
Format.eprintf "pos for 1: @[%a@]@\n" Format.(pp_print_list pp_pos) cmds_1;
271+
Format.eprintf "pos for 2: @[%a@]@\n" Format.(pp_print_list pp_pos) cmds_2;
272+
List.equal Command.equal cmds_1 cmds_2
273+
274+
let%test _ =
275+
let input = "
276+
constant symbol B : TYPE;
277+
constant symbol C : TYPE;
278+
" in
279+
parse_split input
280+
281+
(* Test for notation: check that parsing with notation is correct and that fails when not present *)
282+
283+
(* Test for positions: check that the positions are correct, including when we
284+
resume parsing from the middle of the file *)

src/pure/tests/foo.lp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
constant symbol B : TYPE
2+
3+
constant symbol true : B
4+
constant symbol false : B
5+
6+
symbol neg : BB
7+
8+
rule neg truefalse
9+
rule neg falsetrue
10+
11+
constant symbol Prop : TYPE
12+
13+
injective symbol P : PropTYPE
14+
15+
constant symbol eq : BBProp
16+
constant symbol refl b : P (eq b b)
17+
18+
constant symbol case (p : BProp) : P (p true) ⇒ P (p false) ⇒ ∀b, P b
19+
20+
theorem notK : ∀b, P (eq (neg (neg b)) b)
21+
proof
22+
assume b
23+
apply caseb, eq (neg (neg b)) b)
24+
apply refl
25+
apply refl
26+
qed

src/pure/tests/lambdapi.pkg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package_name = tests
2+
root_path = tests

0 commit comments

Comments
 (0)