From b33eb642b3ad76ad86be61fbfdcb506d7eaf0108 Mon Sep 17 00:00:00 2001 From: Emilio Jesus Gallego Arias Date: Wed, 20 May 2020 11:49:24 +0200 Subject: [PATCH] [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. --- lambdapi.opam | 2 ++ src/pure/dune | 2 ++ src/pure/foo.lp | 26 ++++++++++++++++++++++ src/pure/pure.ml | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+) create mode 100644 src/pure/foo.lp diff --git a/lambdapi.opam b/lambdapi.opam index d4010ac2e..0aca02221 100644 --- a/lambdapi.opam +++ b/lambdapi.opam @@ -62,6 +62,8 @@ depends: [ "cmdliner" {>= "1.1.0"} "stdlib-shims" {>= "0.1.0"} "odoc" {with-doc} + # tests + "ppx_inline_test" { with-test } ] build: [ ["dune" "subst"] {dev} diff --git a/src/pure/dune b/src/pure/dune index 82aca4a9a..6605e26ff 100644 --- a/src/pure/dune +++ b/src/pure/dune @@ -2,5 +2,7 @@ (name pure) (public_name lambdapi.pure) (modules :standard) + (inline_tests (deps foo.lp)) + (preprocess (pps ppx_inline_test)) (libraries camlp-streams lambdapi.handle lambdapi.core) (flags -w +3)) diff --git a/src/pure/foo.lp b/src/pure/foo.lp new file mode 100644 index 000000000..8cf280e41 --- /dev/null +++ b/src/pure/foo.lp @@ -0,0 +1,26 @@ +constant symbol B : TYPE + +constant symbol true : B +constant symbol false : B + +symbol neg : B ⇒ B + +rule neg true → false +rule neg false → true + +constant symbol Prop : TYPE + +injective symbol P : Prop ⇒ TYPE + +constant symbol eq : B ⇒ B ⇒ Prop +constant symbol refl b : P (eq b b) + +constant symbol case (p : B⇒Prop) : P (p true) ⇒ P (p false) ⇒ ∀b, P b + +theorem notK : ∀b, P (eq (neg (neg b)) b) +proof + assume b + apply case (λb, eq (neg (neg b)) b) + apply refl + apply refl +qed diff --git a/src/pure/pure.ml b/src/pure/pure.ml index 8668f4be7..b12b2c402 100644 --- a/src/pure/pure.ml +++ b/src/pure/pure.ml @@ -179,3 +179,59 @@ let end_proof : proof_state -> command_result = let get_symbols : state -> Term.sym Extra.StrMap.t = fun (_, ss) -> ss.in_scope + +(* Equality on *) +let test_file = "./foo.lp" + +let%test _ = + let st = initial_state test_file in + let (c,_) = parse_text st ~fname:test_file "constant symbol B : TYPE" in + List.equal Command.equal c c + +(* Equality not *) +let%test _ = + let st = initial_state test_file in + let (c,_) = parse_text st ~fname:test_file "constant symbol B : TYPE" in + let (d,_) = parse_text st ~fname:test_file "constant symbol C : TYPE" in + not (List.equal Command.equal c d) + +(* Equality is not sensitive to whitespace *) +let%test _ = + let st = initial_state test_file in + let (c,_) = parse_text st ~fname:test_file "constant symbol B : TYPE" in + let (d,_) = parse_text st ~fname:test_file " constant symbol B : TYPE " in + List.equal Command.equal c d + +(* More complex test stressing most commands *) +let%test _ = + let st = initial_state test_file in + let (c,_) = parse_text st ~fname:test_file + (* copied from tests/OK/foo.lp. keep in sync. *) +"constant symbol B : TYPE + +constant symbol true : B +constant symbol false : B + +symbol neg : B ⇒ B + +rule neg true → false +rule neg false → true + +constant symbol Prop : TYPE + +injective symbol P : Prop ⇒ TYPE + +constant symbol eq : B ⇒ B ⇒ Prop +constant symbol refl b : P (eq b b) + +constant symbol case (p : B⇒Prop) : P (p true) ⇒ P (p false) ⇒ ∀b, P b + +theorem notK : ∀b, P (eq (neg (neg b)) b) +proof + assume b + apply case (λb, eq (neg (neg b)) b) + apply refl + apply refl +qed +" in + List.equal Command.equal c c