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 May 27, 2020
1 parent 79c49c0 commit 368e29a
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ env:
global:
- OPAMJOBS="2"
- OPAMYES="true"
- TEST_TARGETS="real_tests"
- TEST_TARGETS="real_tests unit-tests"
matrix:
- OCAML_VERSION=4.05.0
- OCAML_VERSION=4.06.0
Expand Down
6 changes: 5 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ LAMBDAPI = dune exec -- lambdapi check --lib-root lib
OK_TESTFILES = $(sort $(wildcard tests/OK/*.dk tests/OK/*.lp))
KO_TESTFILES = $(sort $(wildcard tests/KO/*.dk tests/KO/*.lp))

.PHONY: tests
.PHONY: tests unit-tests

unit-tests:
@dune build runtest

tests: bin
@printf "## OK tests ##\n"
@for file in $(OK_TESTFILES) ; do \
Expand Down
2 changes: 2 additions & 0 deletions src/pure/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
(name pure)
(public_name lambdapi.pure)
(modules pure)
(inline_tests (deps foo.lp))
(preprocess (pps ppx_inline_test))
(libraries stdlib-shims core))
Empty file added src/pure/foo.lp
Empty file.
56 changes: 56 additions & 0 deletions src/pure/pure.ml
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,59 @@ let end_proof : proof_state -> command_result = fun s ->
let get_symbols : state -> (Terms.sym * Pos.popt) StrMap.t = fun s ->
Time.restore (fst s);
!(Sign.((current_sign ()).sign_symbols))

(* Equality on *)
let test_file = "./foo.lp"

let%test _ =
let st = initial_state test_file in
let (c,_) = parse_text st 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 test_file "constant symbol B : TYPE" in
let (d,_) = parse_text st 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 test_file "constant symbol B : TYPE" in
let (d,_) = parse_text st 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 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 368e29a

Please sign in to comment.