Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ the Git ChangeLog, the GitHub repo https://github.com/ProofGeneral/PG
`proof-goals-scroll-margin'.

** Coq changes
*** The Coq program, compiler and dependency analyzer given by file or
directory variables (`coq-prog-name', `coq-compiler',
`coq-dependency-analyzer') are no longer replaced by the detected
ones when Coq starts.
*** The options `coq-use-makefile' and `coq-pre-v85', deprecated and
unused, are removed: use `coq-pinned-version' instead of the
latter.
*** The toggle commands of the user options of Proof General
(`proof-three-window-toggle', `proof-electric-terminator-toggle'…),
of `coq-show-proof-stepwise' and of `coq-auto-adapt-printing-width'
Expand Down
174 changes: 174 additions & 0 deletions ci/simple-tests/coq-test-file-variables.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
;;; coq-test-file-variables.el --- Test the file variables of Coq -*- lexical-binding: t -*-
;;
;; This file is part of Proof General.
;;
;; License: GPL (GNU GENERAL PUBLIC LICENSE)

;;; Commentary:
;;
;; Test the priority of the file variables (and directory variables)
;; over the project file (_CoqProject, _RocqProject) for
;; `coq-load-path' and `coq-prog-args', and the choice of the Coq
;; program by `coq-pg-detect-programs', run just before starting Coq:
;; detected by default, kept when customized or asked. Coq is not
;; started.

;;; Code:

(require 'proof-site)
(proof-ready-for-assistant 'coq)

(require 'ert)

(defvar coq-load-path)
(defvar coq-prog-args)
(defvar coq-prog-name)
(defvar coq-compiler)
(defvar coq-dependency-analyzer)
(defvar proof-prog-name)
(defvar proof-prog-name-ask)

(declare-function coq-pg-detect-programs "coq")
(declare-function coq-autodetect-progname "coq-mode")


;;; utility functions

(defmacro coq-test-file-variables-with-file (project local-variables &rest body)
"Run BODY in a buffer visiting a Coq file, with PROJECT and LOCAL-VARIABLES.
PROJECT is the content of a _RocqProject file next to it, or nil for
none. LOCAL-VARIABLES is a list of strings \"VAR: VALUE\" for the
Local Variables section of the file. The variable `dir' is bound to
the directory of the file in BODY."
(declare (indent 2) (debug t))
`(let* ((dir (file-name-as-directory (make-temp-file "file_variables" t)))
(file (expand-file-name "a.v" dir))
(enable-local-variables :all)
(local-variables ,local-variables)
buffer)
(unwind-protect
(progn
(when ,project
(with-temp-file (expand-file-name "_RocqProject" dir)
(insert ,project)))
(with-temp-file file
(insert "Definition x := 0.\n")
(when local-variables
(insert "(* Local Variables: *)\n")
(dolist (var local-variables)
(insert "(* " var " *)\n"))
(insert "(* End: *)\n")))
(find-file file)
(setq buffer (current-buffer))
,@body)
(when buffer
(with-current-buffer buffer
(set-buffer-modified-p nil))
(kill-buffer buffer))
(delete-directory dir t))))

(defmacro coq-test-file-variables-detect (&rest body)
"Run `coq-pg-detect-programs' then BODY, restoring the global options."
(declare (indent 0) (debug t))
`(let ((proof-prog-name proof-prog-name)
(proof-prog-name-ask proof-prog-name-ask)
(coq-compiler coq-compiler)
(coq-dependency-analyzer coq-dependency-analyzer)
(coq-prog-name coq-prog-name))
,@body))

(defconst coq-test-file-variables-project
"-R theories Foo\n-arg -w -arg all\n"
"Project file of the tests.")


;;; tests

(ert-deftest coq-test-file-variables-project-file ()
"Without file variables, the project file sets the load path and the args."
(coq-test-file-variables-with-file coq-test-file-variables-project nil
(should (equal coq-load-path
`((rec ,(expand-file-name "theories" dir) "Foo"))))
(should (equal coq-prog-args '("-w" "all")))))

(ert-deftest coq-test-file-variables-over-project-file ()
"File variables have priority over the project file, one by one."
(coq-test-file-variables-with-file coq-test-file-variables-project
'("coq-load-path: ((\"lib\" \"Bar\"))")
(should (equal coq-load-path '(("lib" "Bar"))))
(should (equal coq-prog-args '("-w" "all"))))
(coq-test-file-variables-with-file coq-test-file-variables-project
'("coq-prog-args: (\"-type-in-type\")")
(should (equal coq-load-path
`((rec ,(expand-file-name "theories" dir) "Foo"))))
(should (equal coq-prog-args '("-type-in-type"))))
(coq-test-file-variables-with-file coq-test-file-variables-project
'("coq-load-path: ((\"lib\" \"Bar\"))"
"coq-prog-args: (\"-type-in-type\")")
(should (equal coq-load-path '(("lib" "Bar"))))
(should (equal coq-prog-args '("-type-in-type")))))

(ert-deftest coq-test-file-variables-dir-locals ()
"Directory variables also have priority over the project file."
(coq-test-file-variables-with-file coq-test-file-variables-project nil
(with-temp-file (expand-file-name ".dir-locals.el" dir)
(insert "((coq-mode . ((coq-prog-args . (\"-type-in-type\")))))\n"))
(revert-buffer t t)
(should (equal coq-prog-args '("-type-in-type")))
(should (equal coq-load-path
`((rec ,(expand-file-name "theories" dir) "Foo"))))))

(ert-deftest coq-test-file-variables-prog-name-detected ()
"By default, the Coq program is detected just before starting Coq."
(coq-test-file-variables-with-file nil nil
(coq-test-file-variables-detect
(setq proof-prog-name "not-a-coq-program")
(coq-pg-detect-programs)
(should (equal proof-prog-name (coq-autodetect-progname)))
(should (equal coq-prog-name proof-prog-name)))))

(ert-deftest coq-test-file-variables-prog-name-asked ()
"The Coq program given by the user with `proof-prog-name-ask' is kept."
(coq-test-file-variables-with-file nil nil
(coq-test-file-variables-detect
(setq proof-prog-name-ask t)
(setq proof-prog-name "/asked/rocq")
(coq-pg-detect-programs)
(should (equal proof-prog-name "/asked/rocq"))
(should (equal coq-prog-name "/asked/rocq")))))

(ert-deftest coq-test-file-variables-prog-name-customized ()
"A customized Coq program is kept."
(coq-test-file-variables-with-file nil nil
(coq-test-file-variables-detect
(let ((customized (get 'coq-prog-name 'customized-value)))
(unwind-protect
(progn
(put 'coq-prog-name 'customized-value '("/customized/rocq"))
(setq proof-prog-name "/customized/rocq")
(coq-pg-detect-programs)
(should (equal proof-prog-name "/customized/rocq")))
(put 'coq-prog-name 'customized-value customized))))))

(ert-deftest coq-test-file-variables-prog-name-local ()
"The Coq program and the compilers given by file variables are kept."
(let* ((progdir (file-name-as-directory (make-temp-file "progdir" t)))
(prog (expand-file-name "rocq" progdir)))
(unwind-protect
(progn
(make-symbolic-link (executable-find (coq-autodetect-progname)) prog)
(coq-test-file-variables-with-file nil
(list (format "coq-prog-name: %S" prog)
"coq-compiler: \"/local/coqc\""
"coq-dependency-analyzer: \"/local/coqdep\"")
(coq-test-file-variables-detect
(coq-pg-detect-programs)
(should (equal proof-prog-name prog))
(should (equal coq-prog-name prog))
(should (equal coq-compiler "/local/coqc"))
(should (equal coq-dependency-analyzer "/local/coqdep")))))
(delete-directory progdir t))))

(provide 'coq-test-file-variables)

;;; coq-test-file-variables.el ends here
79 changes: 79 additions & 0 deletions ci/simple-tests/coq-test-system.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
;;; coq-test-system.el --- Test coq-system.el -*- lexical-binding: t -*-
;;
;; This file is part of Proof General.
;;
;; License: GPL (GNU GENERAL PUBLIC LICENSE)

;;; Commentary:
;;
;; Test the cache of `coq-detect-rocq-cli' and the round trip between
;; the options of a project file and `coq-load-path'. Coq is not
;; started.

;;; Code:

(require 'proof-site)
(proof-ready-for-assistant 'coq)

(require 'ert)
(require 'cl-lib)
(require 'coq-system)

(defvar coq--rocq-cli-cache)
(defvar coq-load-path-include-current)

(declare-function coq-detect-rocq-cli "coq-system")
(declare-function coq--read-options-from-project-file "coq-project")
(declare-function coq--extract-load-path "coq-project")
(declare-function coq-include-options "coq-project")


(ert-deftest coq-test-system-rocq-cli-cache ()
"`coq-detect-rocq-cli' runs a command once per command and `exec-path'."
(let ((coq--rocq-cli-cache nil)
(calls nil))
(cl-letf (((symbol-function 'process-file)
(lambda (program &rest _)
(push program calls)
(cond
((equal program "fake-rocq")
(princ "Supported subcommands: c, top, dep")
1)
((equal program "fake-coqtop") 0)
(t (error "No such program: %s" program))))))
(should (coq-detect-rocq-cli "fake-rocq"))
(should (coq-detect-rocq-cli "fake-rocq"))
(should (equal calls '("fake-rocq")))
(should-not (coq-detect-rocq-cli "fake-coqtop"))
(should-not (coq-detect-rocq-cli "fake-coqtop"))
(should (equal calls '("fake-coqtop" "fake-rocq")))
;; another exec-path, for example another opam switch
(let ((exec-path (cons "/another/switch/bin" exec-path)))
(should (coq-detect-rocq-cli "fake-rocq")))
(should (equal calls '("fake-rocq" "fake-coqtop" "fake-rocq")))
;; a command that cannot be run is not cached
(should-not (coq-detect-rocq-cli "missing"))
(should-not (coq-detect-rocq-cli "missing"))
(should (equal (cl-count "missing" calls :test #'equal) 2)))))

(defun coq-test-system-roundtrip (project pre-v85)
"Return non-nil if the include options of PROJECT survive a round trip.
Read as `coq-load-path' then printed back, with PRE-V85 compatibility."
(with-no-warnings ; obsolete variable
(let* ((parsed (coq--read-options-from-project-file project))
(coq-load-path-include-current nil)
(extracted (coq--extract-load-path parsed nil)))
(equal (apply #'append parsed)
(coq-include-options extracted nil pre-v85)))))

(ert-deftest coq-test-system-options-roundtrip ()
"The include options of a project file are printed back unchanged."
(dolist (project '("-Q /test Test" "-Q /test \"\"" "-R /test Test" "-I /test"))
(should (coq-test-system-roundtrip project nil)))
;; Coq < 8.5 has no -Q
(dolist (project '("-R /test Test" "-I /test"))
(should (coq-test-system-roundtrip project t))))

(provide 'coq-test-system)

;;; coq-test-system.el ends here
1 change: 0 additions & 1 deletion coq/coq-compile-common.el
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
(require 'coq-system)
(require 'compile)

;;(defvar coq-pre-v85 nil)
(defvar coq-confirm-external-compilation); defpacustom
(defvar coq-compile-parallel-in-background) ; defpacustom

Expand Down
Loading
Loading