Skip to content

Commit 3c99467

Browse files
committed
proof-stat: add batch mode and TAP support
1 parent c1a4cc6 commit 3c99467

File tree

2 files changed

+62
-29
lines changed

2 files changed

+62
-29
lines changed

ci/simple-tests/coq-test-proof-stat.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Test that the report buffer contains the expected output."
3636
(find-file "proof_stat.v")
3737

3838
;; run check on file where all errors are in opaque parts
39-
(proof-check-proofs)
39+
(proof-check-proofs nil)
4040

4141
;; the result buffer should exist
4242
(should (buffer-live-p (get-buffer "*proof-check-report*")))
@@ -74,7 +74,7 @@ Check that `proof-check-proofs' signals an error with the expected message."
7474
;; proof-check-proofs should abort now with an error
7575
(condition-case err-desc
7676
(progn
77-
(proof-check-proofs)
77+
(proof-check-proofs nil)
7878
;; Still here? Make test fail!
7979
(should nil))
8080
(error

generic/pg-user.el

Lines changed: 60 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -603,14 +603,20 @@ last use time, to discourage saving these into the users database."
603603
;; Check validity of proofs
604604
;;
605605

606-
(defun proof-check-report (proof-results)
606+
(defun proof-check-report (proof-results tap batch)
607607
"Report `proof-check-proofs' results in PROOF-RESULTS in special buffer.
608608
Report the results of `proof-check-proofs' in buffer
609-
`proof-check-report-buffer' in human readable form."
609+
`proof-check-report-buffer' in human readable form or, if TAP is
610+
not nil, in test anything protocol (TAP). If BATCH is not nil,
611+
report the results via message, such that they appear on stdout
612+
when Emacs runs in batch mode or, when BATCH is a string, append
613+
the results to the file denoted by BATCH."
610614
(let* ((ok-fail (seq-group-by #'car proof-results))
611615
(frmt " %-4s %s")
612616
(frmt-face (propertize frmt 'face 'error))
617+
(count 1)
613618
coq-proj-dir src-file)
619+
614620
;; determine a relative file name for current buffer
615621
(when buffer-file-name
616622
(setq coq-proj-dir (locate-dominating-file buffer-file-name
@@ -622,25 +628,43 @@ Report the results of `proof-check-proofs' in buffer
622628
;; generate header
623629
(with-current-buffer (get-buffer-create proof-check-report-buffer)
624630
(erase-buffer)
625-
(insert
626-
(propertize (concat "Proof check results for " src-file) 'face 'bold)
627-
"\n\n")
628-
(insert
629-
(format
630-
(propertize "%d opaque proofs recognized: %d successful " 'face 'bold)
631-
(length proof-results)
632-
(length (cdr (assoc t ok-fail)))))
633-
(insert (format (propertize "%d FAILING" 'face 'error 'face 'bold)
634-
(length (cdr (assoc nil ok-fail)))))
635-
(insert "\n\n")
636-
;; generate actual proof results
631+
(if tap
632+
(insert (format "TAP version 14\n1..%d\n" (length proof-results)))
633+
;; human output
634+
(insert
635+
(propertize (concat "Proof check results for " src-file) 'face 'bold)
636+
"\n\n")
637+
(insert
638+
(format
639+
(propertize "%d opaque proofs recognized: %d successful " 'face 'bold)
640+
(length proof-results)
641+
(length (cdr (assoc t ok-fail)))))
642+
(insert (format (propertize "%d FAILING" 'face 'error 'face 'bold)
643+
(length (cdr (assoc nil ok-fail)))))
644+
(insert "\n\n"))
637645
(dolist (pr proof-results)
638-
(insert (format (if (car pr) frmt frmt-face)
639-
(if (car pr) "OK " "FAIL")
640-
(cadr pr)))
641-
(insert "\n"))
642-
(goto-char (point-min))
643-
(display-buffer (current-buffer)))))
646+
(if tap
647+
(progn
648+
(insert (format "%sok %d - %s\n"
649+
(if (car pr) "" "not ")
650+
count
651+
(cadr pr)))
652+
(setq count (1+ count)))
653+
;; human readable
654+
(insert (format (if (car pr) frmt frmt-face)
655+
(if (car pr) "OK " "FAIL")
656+
(cadr pr)))
657+
(insert "\n")))
658+
(if batch
659+
(progn
660+
(insert "\n\n")
661+
(if (stringp batch)
662+
(append-to-file (point-min) (point-max) batch)
663+
(message "%s"
664+
(buffer-substring-no-properties
665+
(point-min) (point-max)))))
666+
(goto-char (point-min))
667+
(display-buffer (current-buffer))))))
644668

645669
(defun proof-check-chunks (chunks)
646670
"Worker function for `proof-check-proofs for processing CHUNKS.
@@ -727,19 +751,28 @@ as reported by `proof-get-proof-info-fn'."
727751
(setq chunks (cdr chunks))))
728752
(nreverse proof-results)))
729753

730-
(defun proof-check-proofs ()
731-
"Generate overview about valid and invalid proofs in current buffer.
754+
(defun proof-check-proofs (tap &optional batch)
755+
"Generate overview about valid and invalid proofs.
732756
This command completely processes the current buffer and
733-
generates an overview in the `proof-check-report-buffer' about
734-
all the opaque proofs in it and whether their proof scripts are
735-
valid or invalid.
757+
generates an overview about all the opaque proofs in it and
758+
whether their proof scripts are valid or invalid.
736759
737760
This command makes sense for a development process where invalid
738761
proofs are permitted and vos compilation and the omit proofs
739762
feature (see `proof-omit-proofs-configured') are used to work at
740763
the most interesting or challenging point instead of on the first
741764
invalid proof.
742765
766+
Argument TAP, which can be set by a prefix argument, controls the
767+
form of the generated overview. Nil, without prefix, gives an
768+
human readable overview, otherwise it's test anything
769+
protocol (TAP). Argument BATCH controls where the overview goes
770+
to. If nil, or in an interactive call, the overview appears in
771+
`proof-check-report-buffer'. If BATCH is a string, it should be a
772+
filename and the overview is appended there. Otherwise the
773+
overview is output via `message' such that it appears on stdout
774+
when this command runs in batch mode.
775+
743776
In the same way as the omit-proofs feature, this command only
744777
tolerates errors inside scripts of opaque proofs. Any other error
745778
is reported to the user without generating an overview. The
@@ -748,7 +781,7 @@ scripts are classified as opaque by the omit-proofs feature. For
748781
Coq for instance, among others, proof scripts terminated with
749782
'Defined' are not opaque and do not appear in the generated
750783
overview."
751-
(interactive)
784+
(interactive "P")
752785
(unless (and proof-omit-proofs-configured
753786
proof-get-proof-info-fn
754787
proof-retract-command-fn)
@@ -773,7 +806,7 @@ overview."
773806
nil "proof-check: first chunk cannot be a proof")
774807
(setq proof-results (proof-check-chunks chunks))
775808
(proof-shell-exit t)
776-
(proof-check-report proof-results)))
809+
(proof-check-report proof-results tap batch)))
777810

778811

779812

0 commit comments

Comments
 (0)