Skip to content

Commit 3e89b8c

Browse files
authored
Merge pull request #837 from hendriktews/extend-long
CI: add new test for extending/retracting with huge goals
2 parents 999cafb + b05b93d commit 3e89b8c

File tree

2 files changed

+122
-3
lines changed

2 files changed

+122
-3
lines changed

ci/simple-tests/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ coq-test-par-job-needs-compilation-quick
1313
coq-test-prelude-correct
1414
: test that the Proof General prelude is correct
1515
coq-test-goals-present
16-
: Test that Proof General shows goals correctly in various situations.
17-
Test also that in other situations the response buffer contains the
18-
right output and is visible in two-pane mode.
16+
: Test that Proof General shows goals and responses correctly in
17+
various situations and that the expected thing is visible in
18+
two-pane mode. Test also that extending and retracting works as
19+
expected when huge goals cause a delay.
1920
coq-test-three-window
2021
: Test three-pane mode for different frame sizes, including ones that
2122
are too small for three windows.

ci/simple-tests/coq-test-goals-present.el

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,35 @@ Used in `check-response-present' for all `response-buffer-visible-*' tests.")
176176
"
177177
"Coq source for ert-deftest's error-message-visible-at-qed-*")
178178

179+
(defconst coq-src-queuemode-for-show
180+
"Require Export Coq.Lists.List.
181+
Export ListNotations.
182+
183+
Inductive tree : Type :=
184+
Subtrees : list tree -> tree.
185+
186+
Fixpoint list_create(n : nat)(t : tree) : list tree :=
187+
match n with
188+
| 0 => []
189+
| S n => t :: (list_create n t)
190+
end.
191+
192+
Fixpoint build_tree(n m : nat) : tree :=
193+
match n with
194+
| 0 => Subtrees []
195+
| S n => Subtrees (list_create m (build_tree n m))
196+
end.
197+
198+
Lemma a :
199+
build_tree 6 6 = Subtrees [].
200+
Proof using. (* marker A *)
201+
cbv.
202+
trivial.
203+
"
204+
"Coq source code for extend/retract tests during long running Show.
205+
When unfolded, the function build_tree generates big terms that take
206+
quite long to print.")
207+
179208

180209
;;; utility functions
181210

@@ -701,3 +730,92 @@ in proof mode with no more goals."
701730
(check-response-present
702731
#'(lambda() (coq-Check t)) 3 "Nat.add_comm" "@eq nat (Nat.add n m)"))
703732

733+
734+
(defun user-action-during-long-running-show (extend)
735+
"Test to extend or retract during long running Show.
736+
The source code for this test generates a goal that takes about half a
737+
second to print. When running completely silent, this printing happens
738+
inside a Show command added as priority item. The user should be able to
739+
extend the queue region during this long running Show.
740+
741+
This function can test both, extension (if EXTEND is not `nil') and
742+
retraction (if EXTEND is `nil') during a long running Show. Retraction
743+
should fail with the error message \"Proof process busy!\". Extending
744+
the queue should not fail.
745+
746+
Process the source code just before the cbv command that produces the
747+
big term. Then process cbv alone but do not wait until Coq finished
748+
processing. Instead, extend or retract after a short delay. Catch
749+
potential errors with `condition-case' and test their error message.
750+
751+
Need to clear `debug-on-error', which is set in ERT in Emacs 29 and
752+
earlier. `debug-on-error' changes `cl-assert' such that it's error is
753+
not handled by `unwind-protect'. Then the next test triggers the wrong
754+
queuemode assertion again, because Coq was not killed in the handler."
755+
(let (buffer)
756+
(unwind-protect
757+
(progn
758+
(find-file "goals.v")
759+
(setq buffer (current-buffer))
760+
(insert coq-src-queuemode-for-show)
761+
(goto-char (point-min))
762+
(should (re-search-forward "marker A" nil t))
763+
(forward-line 1)
764+
(proof-goto-point)
765+
(wait-for-coq)
766+
767+
(message "Start command with long running Show")
768+
(forward-line 1)
769+
(proof-goto-point)
770+
(accept-process-output nil 0.1)
771+
772+
;;(record-buffer-content "*coq*")
773+
774+
(if (consp proof-action-list)
775+
(progn
776+
(if extend
777+
(progn
778+
(message
779+
"Show still running, extend queue with next command")
780+
(forward-line 1))
781+
(message "%s%s"
782+
"Show still running, retract queue to line "
783+
"before previous command")
784+
(forward-line -1))
785+
786+
(condition-case evar
787+
(let ((debug-on-error nil))
788+
(proof-goto-point))
789+
790+
(error
791+
;; If the just excuted proof-goto-point is an
792+
;; retract, then eventually the check in
793+
;; `proof-shell-ready-prover' will raise an error
794+
;; "Proof process busy!". In other cases an
795+
;; cl-assert might get hit, which usually also
796+
;; results in a call to error - just with a
797+
;; different message.
798+
(message "Error when extending queue: %s" (cdr evar))
799+
;; Kill Coq here. Otherwise the next test might
800+
;; still find the long running Show.
801+
(proof-shell-exit t)
802+
(should (equal (cadr evar) "Proof process busy!")))))
803+
(message "Unexpected: Show not running any more")
804+
(should nil)))
805+
806+
;; clean up
807+
(when buffer
808+
(with-current-buffer buffer
809+
(set-buffer-modified-p nil))
810+
(kill-buffer buffer)))))
811+
812+
(ert-deftest extend-queue-during-long-running-show ()
813+
"Test extending the queue region during a long running Show."
814+
:expected-result :failed
815+
(message "Extend queue during a long running Show of the previous command")
816+
(user-action-during-long-running-show t))
817+
818+
(ert-deftest retract-during-long-running-show ()
819+
"Test retracting during a long running Show."
820+
(message "Retract during a long running Show of the previous command")
821+
(user-action-during-long-running-show nil))

0 commit comments

Comments
 (0)