Skip to content

Commit

Permalink
[pure] [lsp] Try to recover unit testing of pure interface
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ejgallego committed Oct 18, 2022
1 parent d965df9 commit b33eb64
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lambdapi.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 2 additions & 0 deletions src/pure/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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))
26 changes: 26 additions & 0 deletions src/pure/foo.lp
Original file line number Diff line number Diff line change
@@ -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
56 changes: 56 additions & 0 deletions src/pure/pure.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b33eb64

Please sign in to comment.