aboutsummaryrefslogtreecommitdiff
path: root/test-suite
diff options
context:
space:
mode:
Diffstat (limited to 'test-suite')
-rw-r--r--test-suite/Makefile4
-rw-r--r--test-suite/bugs/closed/2733.v15
-rw-r--r--test-suite/bugs/closed/7854.v10
-rw-r--r--test-suite/bugs/closed/8081.v4
-rw-r--r--test-suite/bugs/closed/8119.v46
-rw-r--r--test-suite/bugs/closed/8126.v13
-rw-r--r--test-suite/coqchk/include_primproj.v13
-rw-r--r--test-suite/output/BadOptionValueType.out8
-rw-r--r--test-suite/output/BadOptionValueType.v4
-rw-r--r--test-suite/output/Cases.out2
-rw-r--r--test-suite/output/Cases.v3
-rw-r--r--test-suite/output/Notations3.out6
-rw-r--r--test-suite/output/Notations3.v11
-rw-r--r--test-suite/output/RecordMissingField.out4
-rw-r--r--test-suite/output/RecordMissingField.v8
-rw-r--r--test-suite/success/LraTest.v (renamed from test-suite/success/Fourier.v)10
-rw-r--r--test-suite/success/primitiveproj.v9
-rw-r--r--test-suite/unit-tests/.merlin.in (renamed from test-suite/unit-tests/.merlin)0
-rw-r--r--test-suite/unit-tests/clib/inteq.ml4
-rw-r--r--test-suite/unit-tests/clib/unicode_tests.ml4
-rw-r--r--test-suite/unit-tests/printing/proof_diffs_test.ml333
-rw-r--r--test-suite/unit-tests/src/utest.ml8
-rw-r--r--test-suite/unit-tests/src/utest.mli8
23 files changed, 512 insertions, 15 deletions
diff --git a/test-suite/Makefile b/test-suite/Makefile
index 33b4023272..b8aac8b6f8 100644
--- a/test-suite/Makefile
+++ b/test-suite/Makefile
@@ -192,10 +192,6 @@ PRINT_LOGS?=
TRAVIS?= # special because we want to print travis_fold directives
ifdef APPVEYOR
PRINT_LOGS:=APPVEYOR
-else
-ifdef CIRCLECI
-PRINT_LOGS:=CIRCLECI
-endif #CIRCLECI
endif #APPVEYOR
report: summary.log
diff --git a/test-suite/bugs/closed/2733.v b/test-suite/bugs/closed/2733.v
index 832de4f913..24dd30b32e 100644
--- a/test-suite/bugs/closed/2733.v
+++ b/test-suite/bugs/closed/2733.v
@@ -16,6 +16,21 @@ match k,l with
|B,l' => Bcons true (Ncons 0 l')
end.
+(* At some time, the success of trullynul was dependent on the name of
+ the variables! *)
+
+Definition trullynul2 k {a} (l : alt_list k a) :=
+match k,l with
+ |N,l' => Ncons 0 (Bcons true l')
+ |B,l' => Bcons true (Ncons 0 l')
+end.
+
+Definition trullynul3 k {z} (l : alt_list k z) :=
+match k,l with
+ |N,l' => Ncons 0 (Bcons true l')
+ |B,l' => Bcons true (Ncons 0 l')
+end.
+
Fixpoint app (P : forall {k k'}, alt_list k k' -> alt_list k k') {t1 t2} (l : alt_list t1 t2) {struct l}: forall {t3}, alt_list t2 t3 ->
alt_list t1 t3 :=
match l with
diff --git a/test-suite/bugs/closed/7854.v b/test-suite/bugs/closed/7854.v
new file mode 100644
index 0000000000..ab1a29b632
--- /dev/null
+++ b/test-suite/bugs/closed/7854.v
@@ -0,0 +1,10 @@
+Set Primitive Projections.
+
+CoInductive stream (A : Type) := cons {
+ hd : A;
+ tl : stream A;
+}.
+
+CoFixpoint const {A} (x : A) := cons A x (const x).
+
+Check (@eq_refl _ (const tt) <<: tl unit (const tt) = const tt).
diff --git a/test-suite/bugs/closed/8081.v b/test-suite/bugs/closed/8081.v
new file mode 100644
index 0000000000..0f2501aaa8
--- /dev/null
+++ b/test-suite/bugs/closed/8081.v
@@ -0,0 +1,4 @@
+Section foo.
+End foo.
+Section foo.
+End foo.
diff --git a/test-suite/bugs/closed/8119.v b/test-suite/bugs/closed/8119.v
new file mode 100644
index 0000000000..c6329a7328
--- /dev/null
+++ b/test-suite/bugs/closed/8119.v
@@ -0,0 +1,46 @@
+Require Import Coq.Strings.String.
+
+Section T.
+ Eval vm_compute in let x := tt in _.
+(* Error: Anomaly "Uncaught exception Constr.DestKO." Please report at http://coq.inria.fr/bugs/. *)
+ Eval vm_compute in let _ := Set in _.
+(* Error: Anomaly "Uncaught exception Constr.DestKO." Please report at http://coq.inria.fr/bugs/. *)
+ Eval vm_compute in let _ := Prop in _.
+(* Error: Anomaly "Uncaught exception Constr.DestKO." Please report at http://coq.inria.fr/bugs/. *)
+End T.
+
+Section U0.
+ Let n : unit := tt.
+ Eval vm_compute in _.
+(* Error: Anomaly "Uncaught exception Constr.DestKO." Please report at http://coq.inria.fr/bugs/. *)
+ Goal exists tt : unit, tt = tt. eexists. vm_compute. Abort.
+(* Error: Anomaly "Uncaught exception Constr.DestKO." Please report at http://coq.inria.fr/bugs/. *)
+End U0.
+
+Section S0.
+ Let LF : string := String (Coq.Strings.Ascii.Ascii false true false true false false false false) "".
+ Eval vm_compute in _.
+(* Error: Anomaly "Uncaught exception Constr.DestKO." Please report at http://coq.inria.fr/bugs/. *)
+ Goal exists tt : unit, tt = tt. eexists. vm_compute. Abort.
+(* Error: Anomaly "Uncaught exception Constr.DestKO." Please report at http://coq.inria.fr/bugs/. *)
+End S0.
+
+Class T := { }.
+Section S1.
+ Context {p : T}.
+ Let LF : string := String (Coq.Strings.Ascii.Ascii false true false true false false false false) "".
+ Eval vm_compute in _.
+(* Error: Anomaly "Uncaught exception Not_found." Please report at http://coq.inria.fr/bugs/. *)
+ Goal exists tt : unit, tt = tt. eexists. vm_compute. Abort.
+(* Error: Anomaly "Uncaught exception Not_found." Please report at http://coq.inria.fr/bugs/. *)
+End S1.
+
+Class M := { m : Type }.
+Section S2.
+ Context {p : M}.
+ Let LF : string := String (Coq.Strings.Ascii.Ascii false true false true false false false false) "".
+ Eval vm_compute in _.
+(* Error: Anomaly "File "pretyping/vnorm.ml", line 60, characters 9-15: Assertion failed." *)
+ Goal exists tt : unit, tt = tt. eexists. vm_compute. Abort.
+(* Error: Anomaly "File "pretyping/vnorm.ml", line 60, characters 9-15: Assertion failed." *)
+End S2.
diff --git a/test-suite/bugs/closed/8126.v b/test-suite/bugs/closed/8126.v
new file mode 100644
index 0000000000..f52dfc6b47
--- /dev/null
+++ b/test-suite/bugs/closed/8126.v
@@ -0,0 +1,13 @@
+(* See also output test Notations4.v *)
+
+Inductive foo := tt.
+Bind Scope foo_scope with foo.
+Delimit Scope foo_scope with foo.
+Notation "'HI'" := tt : foo_scope.
+Definition myfoo (x : nat) (y : nat) (z : foo) := y.
+Notation myfoo0 := (@myfoo 0).
+Notation myfoo01 := (@myfoo0 1).
+Check myfoo 0 1 HI. (* prints [myfoo0 1 HI], but should print [myfoo01 HI] *)
+Check myfoo0 1 HI. (* prints [myfoo0 1 HI], but should print [myfoo01 HI] *)
+Check myfoo01 tt. (* prints [myfoo0 1 HI], but should print [myfoo01 HI] *)
+Check myfoo01 HI. (* was failing *)
diff --git a/test-suite/coqchk/include_primproj.v b/test-suite/coqchk/include_primproj.v
new file mode 100644
index 0000000000..804ba1d378
--- /dev/null
+++ b/test-suite/coqchk/include_primproj.v
@@ -0,0 +1,13 @@
+(* #7329 *)
+Set Primitive Projections.
+
+Module M.
+ Module Bar.
+ Record Box := box { unbox : Type }.
+
+ Axiom foo : Box.
+ Axiom baz : forall _ : unbox foo, unbox foo.
+ End Bar.
+End M.
+
+Include M.
diff --git a/test-suite/output/BadOptionValueType.out b/test-suite/output/BadOptionValueType.out
new file mode 100644
index 0000000000..34d8518a75
--- /dev/null
+++ b/test-suite/output/BadOptionValueType.out
@@ -0,0 +1,8 @@
+The command has indeed failed with message:
+Bad type of value for this option: expected int, got string.
+The command has indeed failed with message:
+Bad type of value for this option: expected bool, got string.
+The command has indeed failed with message:
+Bad type of value for this option: expected bool, got int.
+The command has indeed failed with message:
+Bad type of value for this option: expected bool, got int.
diff --git a/test-suite/output/BadOptionValueType.v b/test-suite/output/BadOptionValueType.v
new file mode 100644
index 0000000000..b61c3757ba
--- /dev/null
+++ b/test-suite/output/BadOptionValueType.v
@@ -0,0 +1,4 @@
+Fail Set Default Timeout "2".
+Fail Set Debug Eauto "yes".
+Fail Set Debug Eauto 1.
+Fail Set Implicit Arguments 1.
diff --git a/test-suite/output/Cases.out b/test-suite/output/Cases.out
index 419dcadb4c..dfab400baa 100644
--- a/test-suite/output/Cases.out
+++ b/test-suite/output/Cases.out
@@ -169,3 +169,5 @@ fun x : K => match x with
| _ => 2
end
: K -> nat
+The command has indeed failed with message:
+Pattern "S _, _" is redundant in this clause.
diff --git a/test-suite/output/Cases.v b/test-suite/output/Cases.v
index 4740c009a4..e4fa7044e7 100644
--- a/test-suite/output/Cases.v
+++ b/test-suite/output/Cases.v
@@ -217,3 +217,6 @@ Check fun x => match x with a3 | a4 => 3 | _ => 2 end.
Check fun x => match x with a3 => 3 | a2 | a1 => 4 | _ => 2 end.
Check fun x => match x with a4 => 3 | a2 | a1 => 4 | _ => 2 end.
Check fun x => match x with a3 | a4 | a1 => 3 | _ => 2 end.
+
+(* Test redundant clause within a disjunctive pattern *)
+Fail Check fun n m => match n, m with 0, 0 | _, S _ | S 0, _ | S (S _ | _), _ => false end.
diff --git a/test-suite/output/Notations3.out b/test-suite/output/Notations3.out
index 5ab616160a..d32cf67e28 100644
--- a/test-suite/output/Notations3.out
+++ b/test-suite/output/Notations3.out
@@ -246,3 +246,9 @@ Notation
============================
##@%
^^^
+myfoo01 tt
+ : nat
+myfoo01 tt
+ : nat
+myfoo01 tt
+ : nat
diff --git a/test-suite/output/Notations3.v b/test-suite/output/Notations3.v
index 876aaa3944..180e8d337e 100644
--- a/test-suite/output/Notations3.v
+++ b/test-suite/output/Notations3.v
@@ -399,3 +399,14 @@ Show.
Abort.
End Issue7731.
+
+Module Issue8126.
+
+Definition myfoo (x : nat) (y : nat) (z : unit) := y.
+Notation myfoo0 := (@myfoo 0).
+Notation myfoo01 := (@myfoo0 1).
+Check myfoo 0 1 tt. (* was printing [myfoo0 1 HI], but should print [myfoo01 HI] *)
+Check myfoo0 1 tt. (* was printing [myfoo0 1 HI], but should print [myfoo01 HI] *)
+Check myfoo01 tt. (* was printing [myfoo0 1 HI], but should print [myfoo01 HI] *)
+
+End Issue8126.
diff --git a/test-suite/output/RecordMissingField.out b/test-suite/output/RecordMissingField.out
new file mode 100644
index 0000000000..7c80a6065f
--- /dev/null
+++ b/test-suite/output/RecordMissingField.out
@@ -0,0 +1,4 @@
+File "stdin", line 8, characters 5-22:
+Error: Cannot infer field y2p of record point2d in environment:
+p : point2d
+
diff --git a/test-suite/output/RecordMissingField.v b/test-suite/output/RecordMissingField.v
new file mode 100644
index 0000000000..84f1748fa0
--- /dev/null
+++ b/test-suite/output/RecordMissingField.v
@@ -0,0 +1,8 @@
+(** Check for error message when missing a record field. Error message
+should contain missing field, and the inferred type of the record **)
+
+Record point2d := mkPoint { x2p: nat; y2p: nat }.
+
+
+Definition increment_x (p: point2d) : point2d :=
+ {| x2p := x2p p + 1; |}.
diff --git a/test-suite/success/Fourier.v b/test-suite/success/LraTest.v
index b63bead477..bf3a87da25 100644
--- a/test-suite/success/Fourier.v
+++ b/test-suite/success/LraTest.v
@@ -1,12 +1,14 @@
-Require Import Rfunctions.
-Require Import Fourier.
+Require Import Reals.
+Require Import Lra.
+
+Open Scope R_scope.
Lemma l1 : forall x y z : R, Rabs (x - z) <= Rabs (x - y) + Rabs (y - z).
-intros; split_Rabs; fourier.
+intros; split_Rabs; lra.
Qed.
Lemma l2 :
forall x y : R, x < Rabs y -> y < 1 -> x >= 0 -> - y <= 1 -> Rabs x <= 1.
intros.
-split_Rabs; fourier.
+split_Rabs; lra.
Qed.
diff --git a/test-suite/success/primitiveproj.v b/test-suite/success/primitiveproj.v
index 7ca2767a53..299b08bdd1 100644
--- a/test-suite/success/primitiveproj.v
+++ b/test-suite/success/primitiveproj.v
@@ -193,12 +193,13 @@ Set Primitive Projections.
Record s (x:nat) (y:=S x) := {c:=x; d:x=c}.
Lemma f : 0=1.
Proof.
-Fail apply d.
+ Fail apply d.
(*
split.
reflexivity.
Qed.
*)
+Abort.
(* Primitive projection match compilation *)
Require Import List.
@@ -220,3 +221,9 @@ Fixpoint split_at {A} (l : list A) (n : nat) : prod (list A) (list A) :=
Time Eval vm_compute in split_at (repeat 0 20) 10. (* Takes 0s *)
Time Eval vm_compute in split_at (repeat 0 40) 20. (* Takes 0.001s *)
Timeout 1 Time Eval vm_compute in split_at (repeat 0 60) 30. (* Used to take 60s, now takes 0.001s *)
+
+Check (@eq_refl _ 0 <: 0 = fst (pair 0 1)).
+Fail Check (@eq_refl _ 0 <: 0 = snd (pair 0 1)).
+
+Check (@eq_refl _ 0 <<: 0 = fst (pair 0 1)).
+Fail Check (@eq_refl _ 0 <<: 0 = snd (pair 0 1)).
diff --git a/test-suite/unit-tests/.merlin b/test-suite/unit-tests/.merlin.in
index b2279de74e..b2279de74e 100644
--- a/test-suite/unit-tests/.merlin
+++ b/test-suite/unit-tests/.merlin.in
diff --git a/test-suite/unit-tests/clib/inteq.ml b/test-suite/unit-tests/clib/inteq.ml
index c07ec293f0..89717c79d5 100644
--- a/test-suite/unit-tests/clib/inteq.ml
+++ b/test-suite/unit-tests/clib/inteq.ml
@@ -1,5 +1,7 @@
open Utest
+let log_out_ch = open_log_out_ch __FILE__
+
let eq0 = mk_bool_test "clib-inteq0"
"Int.equal on 0"
(Int.equal 0 0)
@@ -10,4 +12,4 @@ let eq42 = mk_bool_test "clib-inteq42"
let tests = [ eq0; eq42 ]
-let _ = run_tests __FILE__ tests
+let _ = run_tests __FILE__ log_out_ch tests
diff --git a/test-suite/unit-tests/clib/unicode_tests.ml b/test-suite/unit-tests/clib/unicode_tests.ml
index 9ae405977b..95316ad3aa 100644
--- a/test-suite/unit-tests/clib/unicode_tests.ml
+++ b/test-suite/unit-tests/clib/unicode_tests.ml
@@ -1,5 +1,7 @@
open Utest
+let log_out_ch = open_log_out_ch __FILE__
+
let unicode0 = mk_eq_test "clib-unicode0"
"split_at_first_letter, first letter is character"
None
@@ -12,4 +14,4 @@ let unicode1 = mk_eq_test "clib-unicode1"
let tests = [ unicode0; unicode1 ]
-let _ = run_tests __FILE__ tests
+let _ = run_tests __FILE__ log_out_ch tests
diff --git a/test-suite/unit-tests/printing/proof_diffs_test.ml b/test-suite/unit-tests/printing/proof_diffs_test.ml
new file mode 100644
index 0000000000..526cefec44
--- /dev/null
+++ b/test-suite/unit-tests/printing/proof_diffs_test.ml
@@ -0,0 +1,333 @@
+open OUnit
+open Utest
+open Pp_diff
+open Proof_diffs
+
+let tokenize_string = Proof_diffs.tokenize_string
+let diff_pp = diff_pp ~tokenize_string
+let diff_str = diff_str ~tokenize_string
+
+let tests = ref []
+let add_test name test = tests := (mk_test name (TestCase test)) :: !tests
+
+let log_out_ch = open_log_out_ch __FILE__
+let cfprintf oc = Printf.(kfprintf (fun oc -> fprintf oc "") oc)
+let cprintf s = cfprintf log_out_ch s
+let _ = Proof_diffs.log_out_ch := log_out_ch
+
+let string_of_string s : string = "\"" ^ s ^ "\""
+
+(* todo: OCaml: why can't the body of the test function be given in the add_test line? *)
+
+let t () =
+ let expected : diff_list = [] in
+ let diffs = diff_str "" " " in
+
+ assert_equal ~msg:"empty" ~printer:string_of_diffs expected diffs;
+ let (has_added, has_removed) = has_changes diffs in
+ assert_equal ~msg:"has `Added" ~printer:string_of_bool false has_added;
+ assert_equal ~msg:"has `Removed" ~printer:string_of_bool false has_removed
+let _ = add_test "diff_str empty" t
+
+
+let t () =
+ let expected : diff_list =
+ [ `Common (0, 0, "a"); `Common (1, 1, "b"); `Common (2, 2, "c")] in
+ let diffs = diff_str "a b c" " a b\t c\n" in
+
+ assert_equal ~msg:"white space" ~printer:string_of_diffs expected diffs;
+ let (has_added, has_removed) = has_changes diffs in
+ assert_equal ~msg:"no `Added" ~printer:string_of_bool false has_added;
+ assert_equal ~msg:"no `Removed" ~printer:string_of_bool false has_removed
+let _ = add_test "diff_str white space" t
+
+let t () =
+ let expected : diff_list = [ `Removed (0, "a"); `Added (0, "b")] in
+ let diffs = diff_str "a" "b" in
+
+ assert_equal ~msg:"add/remove" ~printer:string_of_diffs expected diffs;
+ let (has_added, has_removed) = has_changes diffs in
+ assert_equal ~msg:"has `Added" ~printer:string_of_bool true has_added;
+ assert_equal ~msg:"has `Removed" ~printer:string_of_bool true has_removed
+let _ = add_test "diff_str add/remove" t
+
+(* example of a limitation, not really a test *)
+let t () =
+ try
+ let _ = diff_str "a" "&gt;" in
+ assert_failure "unlexable string gives an exception"
+ with _ -> ()
+let _ = add_test "diff_str unlexable" t
+
+(* problematic examples for tokenize_string:
+ comments omitted
+ quoted string loses quote marks (are escapes supported/handled?)
+ char constant split into 2
+ *)
+let t () =
+ List.iter (fun x -> cprintf "'%s' " x) (tokenize_string "(* comment *) \"string\" 'c' xx");
+ cprintf "\n"
+let _ = add_test "tokenize_string examples" t
+
+open Pp
+
+(* note pp_to_string concatenates adjacent strings, could become one token,
+e.g. str " a" ++ str "b " will give a token "ab" *)
+(* checks background is present and correct *)
+let t () =
+ let o_pp = str "a" ++ str "!" ++ str "c" in
+ let n_pp = str "a" ++ str "?" ++ str "c" in
+ let (o_exp, n_exp) = (wrap_in_bg "diff.removed" (str "a" ++ (tag "diff.removed" (str "!")) ++ str "c"),
+ wrap_in_bg "diff.added" (str "a" ++ (tag "diff.added" (str "?")) ++ str "c")) in
+ let (o_diff, n_diff) = diff_pp o_pp n_pp in
+
+ assert_equal ~msg:"removed" ~printer:db_string_of_pp o_exp o_diff;
+ assert_equal ~msg:"added" ~printer:db_string_of_pp n_exp n_diff
+let _ = add_test "diff_pp/add_diff_tags add/remove" t
+
+let t () =
+ (*Printf.printf "%s\n" (string_of_diffs (diff_str "a d" "a b c d"));*)
+ let o_pp = str "a" ++ str " d" in
+ let n_pp = str "a" ++ str " b " ++ str " c " ++ str "d" ++ str " e " in
+ let n_exp = flatten (wrap_in_bg "diff.added" (seq [
+ str "a";
+ str " "; (tag "start.diff.added" (str "b "));
+ (tag "end.diff.added" (str " c")); str " ";
+ (str "d");
+ str " "; (tag "diff.added" (str "e")); str " "
+ ])) in
+ let (_, n_diff) = diff_pp o_pp n_pp in
+
+ assert_equal ~msg:"added" ~printer:db_string_of_pp n_exp (flatten n_diff);;
+let _ = add_test "diff_pp/add_diff_tags a span with spaces" t
+
+
+let t () =
+ let o_pp = str " " in
+ let n_pp = tag "sometag" (str "a") in
+ let n_exp = flatten (wrap_in_bg "diff.added" (tag "diff.added" (tag "sometag" (str "a")))) in
+ let (_, n_diff) = diff_pp o_pp n_pp in
+
+ assert_equal ~msg:"added" ~printer:db_string_of_pp n_exp (flatten n_diff)
+let _ = add_test "diff_pp/add_diff_tags diff tags outside existing tags" t
+
+let t () =
+ let o_pp = str " " in
+ let n_pp = seq [(tag "sometag" (str " a ")); str "b"] in
+ let n_exp = flatten (wrap_in_bg "diff.added"
+ (seq [tag "sometag" (str " "); (tag "start.diff.added" (tag "sometag" (str "a ")));
+ (tag "end.diff.added" (str "b"))]) ) in
+ let (_, n_diff) = diff_pp o_pp n_pp in
+
+ assert_equal ~msg:"added" ~printer:db_string_of_pp n_exp (flatten n_diff)
+let _ = add_test "diff_pp/add_diff_tags existing tagged values with spaces" t
+
+let t () =
+ let o_pp = str " " in
+ let n_pp = str " a b " in
+ let n_exp = flatten (wrap_in_bg "diff.added"
+ (seq [str " "; tag "diff.added" (str "a b"); str " "])) in
+ let (_, n_diff) = diff_pp o_pp n_pp in
+
+ assert_equal ~msg:"added" ~printer:db_string_of_pp n_exp (flatten n_diff)
+let _ = add_test "diff_pp/add_diff_tags multiple tokens in pp" t
+
+let t () =
+ let o_pp = str "a d" in
+ let n_pp = seq [str "a b"; str "c d"] in
+ let n_exp = flatten (wrap_in_bg "diff.added"
+ (seq [str "a "; tag "start.diff.added" (str "b");
+ tag "end.diff.added" (str "c"); str " d"])) in
+ let (_, n_diff) = diff_pp o_pp n_pp in
+
+ assert_equal ~msg:"added" ~printer:db_string_of_pp n_exp (flatten n_diff)
+let _ = add_test "diff_pp/add_diff_tags token spanning multiple Ppcmd_strs" t
+
+let t () =
+ let o_pp = seq [str ""; str "a"] in
+ let n_pp = seq [str ""; str "a b"] in
+ let n_exp = flatten (wrap_in_bg "diff.added"
+ (seq [str ""; str "a "; tag "diff.added" (str "b")])) in
+ let (_, n_diff) = diff_pp o_pp n_pp in
+
+ assert_equal ~msg:"added" ~printer:db_string_of_pp n_exp (flatten n_diff)
+let _ = add_test "diff_pp/add_diff_tags empty string preserved" t
+
+(* todo: awaiting a change in the lexer to return the quotes of the string token *)
+let t () =
+ let s = "\"a b\"" in
+ let o_pp = seq [str s] in
+ let n_pp = seq [str "\"a b\" "] in
+ cprintf "ppcmds: %s\n" (string_of_ppcmds n_pp);
+ let n_exp = flatten (wrap_in_bg "diff.added"
+ (seq [str ""; str "a "; tag "diff.added" (str "b")])) in
+ let (_, n_diff) = diff_pp o_pp n_pp in
+
+ assert_equal ~msg:"string" ~printer:string_of_string "a b" (List.hd (tokenize_string s));
+ assert_equal ~msg:"added" ~printer:db_string_of_pp n_exp (flatten n_diff)
+let _ = if false then add_test "diff_pp/add_diff_tags token containing white space" t
+
+let add_entries map idents rhs_pp =
+ let make_entry() = { idents; rhs_pp; done_ = false } in
+ List.iter (fun ident -> map := (StringMap.add ident (make_entry ()) !map); ()) idents;;
+
+let print_list hyps = List.iter (fun x -> cprintf "%s\n" (string_of_ppcmds (flatten x))) hyps
+let db_print_list hyps = List.iter (fun x -> cprintf "%s\n" (db_string_of_pp (flatten x))) hyps
+
+
+(* a : foo
+ b : bar car ->
+ b : car
+ a : foo bar *)
+let t () =
+ write_diffs_option "removed"; (* turn on "removed" option *)
+ let o_line_idents = [ ["a"]; ["b"]] in
+ let o_hyp_map = ref StringMap.empty in
+ add_entries o_hyp_map ["a"] (str " : foo");
+ add_entries o_hyp_map ["b"] (str " : bar car");
+ let n_line_idents = [ ["b"]; ["a"]] in
+ let n_hyp_map = ref StringMap.empty in
+ add_entries n_hyp_map ["b"] (str " : car");
+ add_entries n_hyp_map ["a"] (str " : foo bar");
+ let expected = [flatten (wrap_in_bg "diff.removed" (seq [str "b"; str " : "; (tag "diff.removed" (str "bar")); str " car" ]));
+ flatten (wrap_in_bg "diff.added" (seq [str "b"; str " : car" ]));
+ flatten (wrap_in_bg "diff.added" (seq [str "a"; str " : foo "; (tag "diff.added" (str "bar")) ]))
+ ] in
+
+ let hyps_diff_list = diff_hyps o_line_idents !o_hyp_map n_line_idents !n_hyp_map in
+
+ (*print_list hyps_diff_list;*)
+ (*db_print_list hyps_diff_list;*)
+
+ List.iter2 (fun exp act ->
+ assert_equal ~msg:"added" ~printer:db_string_of_pp exp (flatten act))
+ expected hyps_diff_list
+let _ = add_test "diff_hyps simple diffs" t
+
+(* a : nat
+ c, d : int ->
+ a, b : nat
+ d : int
+ and keeps old order *)
+let t () =
+ write_diffs_option "removed"; (* turn on "removed" option *)
+ let o_line_idents = [ ["a"]; ["c"; "d"]] in
+ let o_hyp_map = ref StringMap.empty in
+ add_entries o_hyp_map ["a"] (str " : nat");
+ add_entries o_hyp_map ["c"; "d"] (str " : int");
+ let n_line_idents = [ ["a"; "b"]; ["d"]] in
+ let n_hyp_map = ref StringMap.empty in
+ add_entries n_hyp_map ["a"; "b"] (str " : nat");
+ add_entries n_hyp_map ["d"] (str " : int");
+ let expected = [flatten (wrap_in_bg "diff.added" (seq [str "a"; (tag "start.diff.added" (str ", ")); (tag "end.diff.added" (str "b")); str " : nat" ]));
+ flatten (wrap_in_bg "diff.removed" (seq [(tag "start.diff.removed" (str "c")); (tag "end.diff.removed" (str ",")); str " "; str "d"; str " : int" ]));
+ flatten (wrap_in_bg "diff.added" (seq [str "d"; str " : int" ]))
+ ] in
+
+ let hyps_diff_list = diff_hyps o_line_idents !o_hyp_map n_line_idents !n_hyp_map in
+
+ (*print_list hyps_diff_list;*)
+ (*print_list expected;*)
+
+ (*db_print_list hyps_diff_list;*)
+ (*db_print_list expected;*)
+
+ List.iter2 (fun exp act ->
+ assert_equal ~msg:"added" ~printer:db_string_of_pp exp (flatten act))
+ expected hyps_diff_list
+let _ = add_test "diff_hyps compacted" t
+
+(* a : foo
+ b : bar
+ c : nat ->
+ b, a, c : nat
+DIFFS
+ b : bar (remove bar)
+ b : nat (add nat)
+ a : foo (remove foo)
+ a : nat (add nat)
+ c : nat
+ is this a realistic use case?
+*)
+let t () =
+ write_diffs_option "removed"; (* turn on "removed" option *)
+ let o_line_idents = [ ["a"]; ["b"]; ["c"]] in
+ let o_hyp_map = ref StringMap.empty in
+ add_entries o_hyp_map ["a"] (str " : foo");
+ add_entries o_hyp_map ["b"] (str " : bar");
+ add_entries o_hyp_map ["c"] (str " : nat");
+ let n_line_idents = [ ["b"; "a"; "c"] ] in
+ let n_hyp_map = ref StringMap.empty in
+ add_entries n_hyp_map ["b"; "a"; "c"] (str " : nat");
+ let expected = [flatten (wrap_in_bg "diff.removed" (seq [str "b"; str " : "; (tag "diff.removed" (str "bar"))]));
+ flatten (wrap_in_bg "diff.added" (seq [str "b"; str " : "; (tag "diff.added" (str "nat"))]));
+ flatten (wrap_in_bg "diff.removed" (seq [str "a"; str " : "; (tag "diff.removed" (str "foo"))]));
+ flatten (wrap_in_bg "diff.added" (seq [str "a"; str " : "; (tag "diff.added" (str "nat"))]));
+ flatten (seq [str "c"; str " : nat"])
+ ] in
+
+ let hyps_diff_list = diff_hyps o_line_idents !o_hyp_map n_line_idents !n_hyp_map in
+
+ (*print_list hyps_diff_list;*)
+ (*db_print_list hyps_diff_list;*)
+
+ List.iter2 (fun exp act ->
+ assert_equal ~msg:"added" ~printer:db_string_of_pp exp (flatten act))
+ expected hyps_diff_list
+let _ = add_test "diff_hyps compacted with join" t
+
+(* b, a, c : nat ->
+ a : foo
+ b : bar
+ c : nat
+DIFFS
+ a : nat (remove nat)
+ a : foo (add foo)
+ b : nat (remove nat)
+ b : bar (add bar)
+ c : nat
+ is this a realistic use case? *)
+let t () =
+ write_diffs_option "removed"; (* turn on "removed" option *)
+ let o_line_idents = [ ["b"; "a"; "c"] ] in
+ let o_hyp_map = ref StringMap.empty in
+ add_entries o_hyp_map ["b"; "a"; "c"] (str " : nat");
+ let n_line_idents = [ ["a"]; ["b"]; ["c"]] in
+ let n_hyp_map = ref StringMap.empty in
+ add_entries n_hyp_map ["a"] (str " : foo");
+ add_entries n_hyp_map ["b"] (str " : bar");
+ add_entries n_hyp_map ["c"] (str " : nat");
+ let expected = [flatten (wrap_in_bg "diff.removed" (seq [str "a"; str " : "; (tag "diff.removed" (str "nat"))]));
+ flatten (wrap_in_bg "diff.added" (seq [str "a"; str " : "; (tag "diff.added" (str "foo"))]));
+ flatten (wrap_in_bg "diff.removed" (seq [str "b"; str " : "; (tag "diff.removed" (str "nat"))]));
+ flatten (wrap_in_bg "diff.added" (seq [str "b"; str " : "; (tag "diff.added" (str "bar"))]));
+ flatten (seq [str "c"; str " : nat"])
+ ] in
+
+ let hyps_diff_list = diff_hyps o_line_idents !o_hyp_map n_line_idents !n_hyp_map in
+
+ (*print_list hyps_diff_list;*)
+ (*db_print_list hyps_diff_list;*)
+
+ List.iter2 (fun exp act ->
+ assert_equal ~msg:"added" ~printer:db_string_of_pp exp (flatten act))
+ expected hyps_diff_list
+let _ = add_test "diff_hyps compacted with split" t
+
+
+(* other potential tests
+coqtop/terminal formatting BLOCKED: CAN'T GET TAGS IN FORMATTER
+ white space at end of line
+ spanning diffs
+shorten_diff_span
+
+MAYBE NOT WORTH IT
+diff_pp/add_diff_tags
+ add/remove - show it preserves, recurs and processes:
+ nested in boxes
+ breaks, etc. preserved
+diff_pp_combined with/without removed
+*)
+
+
+let _ = run_tests __FILE__ log_out_ch (List.rev !tests)
diff --git a/test-suite/unit-tests/src/utest.ml b/test-suite/unit-tests/src/utest.ml
index 069e6a4bf3..0cb1780ec9 100644
--- a/test-suite/unit-tests/src/utest.ml
+++ b/test-suite/unit-tests/src/utest.ml
@@ -42,10 +42,12 @@ let run_one logit test =
let results = perform_test (fun _ -> ()) test in
process_results results
-(* run list of OUnit test cases, log results *)
-let run_tests ml_fn tests =
+let open_log_out_ch ml_fn =
let log_fn = ml_fn ^ ".log" in
- let out_ch = open_out log_fn in
+ open_out log_fn
+
+(* run list of OUnit test cases, log results *)
+let run_tests ml_fn out_ch tests =
let cprintf s = cfprintf out_ch s in
let ceprintf s = cfprintf stderr s in
let logit = logger out_ch in
diff --git a/test-suite/unit-tests/src/utest.mli b/test-suite/unit-tests/src/utest.mli
index 70928228bf..2e0f26e96b 100644
--- a/test-suite/unit-tests/src/utest.mli
+++ b/test-suite/unit-tests/src/utest.mli
@@ -9,4 +9,10 @@ val mk_bool_test : string -> string -> bool -> OUnit.test
(* the string argument should be the name of the .ml file
containing the tests; use __FILE__ for that purpose.
*)
-val run_tests : string -> OUnit.test list -> unit
+val run_tests : string -> out_channel -> OUnit.test list -> unit
+
+(** open output channel for the test log file *)
+(* the string argument should be the name of the .ml file
+ containing the tests; use __FILE__ for that purpose.
+ *)
+val open_log_out_ch : string -> out_channel