diff options
Diffstat (limited to 'test/lisp')
-rw-r--r-- | test/lisp/emacs-lisp/generator-tests.el | 10 | ||||
-rw-r--r-- | test/lisp/net/tramp-tests.el | 29 | ||||
-rw-r--r-- | test/lisp/progmodes/flymake-resources/Makefile | 4 | ||||
-rw-r--r-- | test/lisp/progmodes/flymake-resources/errors-and-warnings.c | 13 | ||||
-rw-r--r-- | test/lisp/progmodes/flymake-resources/no-problems.h | 1 | ||||
-rw-r--r-- | test/lisp/progmodes/flymake-resources/some-problems.h | 5 | ||||
-rw-r--r-- | test/lisp/progmodes/flymake-tests.el | 297 |
7 files changed, 323 insertions, 36 deletions
diff --git a/test/lisp/emacs-lisp/generator-tests.el b/test/lisp/emacs-lisp/generator-tests.el index 4cc6c841dac..cbb136ae919 100644 --- a/test/lisp/emacs-lisp/generator-tests.el +++ b/test/lisp/emacs-lisp/generator-tests.el @@ -282,3 +282,13 @@ identical output. (ert-deftest cps-test-declarations-preserved () (should (equal (documentation 'generator-with-docstring) "Documentation!")) (should (equal (get 'generator-with-docstring 'lisp-indent-function) 5))) + +(ert-deftest cps-iter-lambda-with-dynamic-binding () + "`iter-lambda' with dynamic binding produces correct result (bug#25965)." + (should (= 1 + (iter-next + (funcall (iter-lambda () + (let* ((fill-column 10) ;;any special variable will do + (i 0) + (j (setq i (1+ i)))) + (iter-yield i)))))))) diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index d430caec8aa..a8fe06d4e67 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -3438,7 +3438,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." (fboundp 'connection-local-set-profiles))) ;; `connection-local-set-profile-variables' and - ;; `connection-local-set-profiles' exists since Emacs 26. We don't + ;; `connection-local-set-profiles' exist since Emacs 26. We don't ;; want to see compiler warnings for older Emacsen. (let ((default-directory tramp-test-temporary-file-directory) explicit-shell-file-name kill-buffer-query-functions) @@ -4108,12 +4108,29 @@ Use the `ls' command." tramp-connection-properties))) (tramp--test-utf8))) +(ert-deftest tramp-test37-file-system-info () + "Check that `file-system-info' returns proper values." + (skip-unless (tramp--test-enabled)) + ;; Since Emacs 27.1. + (skip-unless (fboundp 'file-system-info)) + + ;; `file-system-info' exists since Emacs 27. We don't + ;; want to see compiler warnings for older Emacsen. + (let ((fsi (with-no-warnings + (file-system-info tramp-test-temporary-file-directory)))) + (skip-unless fsi) + (should (and (consp fsi) + (= (length fsi) 3) + (numberp (nth 0 fsi)) + (numberp (nth 1 fsi)) + (numberp (nth 2 fsi)))))) + (defun tramp--test-timeout-handler () (interactive) (ert-fail (format "`%s' timed out" (ert-test-name (ert-running-test))))) ;; This test is inspired by Bug#16928. -(ert-deftest tramp-test37-asynchronous-requests () +(ert-deftest tramp-test38-asynchronous-requests () "Check parallel asynchronous requests. Such requests could arrive from timers, process filters and process sentinels. They shall not disturb each other." @@ -4270,7 +4287,7 @@ process sentinels. They shall not disturb each other." (ignore-errors (cancel-timer timer)) (ignore-errors (delete-directory tmp-name 'recursive))))))) -(ert-deftest tramp-test38-recursive-load () +(ert-deftest tramp-test39-recursive-load () "Check that Tramp does not fail due to recursive load." (skip-unless (tramp--test-enabled)) @@ -4293,7 +4310,7 @@ process sentinels. They shall not disturb each other." (mapconcat 'shell-quote-argument load-path " -L ") (shell-quote-argument code)))))))) -(ert-deftest tramp-test39-remote-load-path () +(ert-deftest tramp-test40-remote-load-path () "Check that Tramp autoloads its packages with remote `load-path'." ;; `tramp-cleanup-all-connections' is autoloaded from tramp-cmds.el. ;; It shall still work, when a remote file name is in the @@ -4316,7 +4333,7 @@ process sentinels. They shall not disturb each other." (mapconcat 'shell-quote-argument load-path " -L ") (shell-quote-argument code))))))) -(ert-deftest tramp-test40-unload () +(ert-deftest tramp-test41-unload () "Check that Tramp and its subpackages unload completely. Since it unloads Tramp, it shall be the last test to run." :tags '(:expensive-test) @@ -4374,7 +4391,7 @@ Since it unloads Tramp, it shall be the last test to run." ;; * Fix `tramp-test05-expand-file-name-relative' in `expand-file-name'. ;; * Fix `tramp-test06-directory-file-name' for `ftp'. ;; * Fix `tramp-test27-start-file-process' on MS Windows (`process-send-eof'?). -;; * Fix Bug#16928 in `tramp-test37-asynchronous-requests'. +;; * Fix Bug#16928 in `tramp-test38-asynchronous-requests'. (defun tramp-test-all (&optional interactive) "Run all tests for \\[tramp]." diff --git a/test/lisp/progmodes/flymake-resources/Makefile b/test/lisp/progmodes/flymake-resources/Makefile index 0f3f39791c8..494407567f2 100644 --- a/test/lisp/progmodes/flymake-resources/Makefile +++ b/test/lisp/progmodes/flymake-resources/Makefile @@ -1,6 +1,6 @@ # Makefile for flymake tests -CC_OPTS = -Wall +CC_OPTS = -Wall -Wextra ## Recent gcc (e.g. 4.8.2 on RHEL7) can automatically colorize their output, ## which can confuse flymake. Set GCC_COLORS to disable that. @@ -8,6 +8,6 @@ CC_OPTS = -Wall ## normally use flymake, so it seems like just avoiding the issue ## in this test is fine. Set flymake-log-level to 3 to investigate. check-syntax: - GCC_COLORS= $(CC) $(CC_OPTS) ${CHK_SOURCES} + GCC_COLORS= $(CC) $(CC_OPTS) ${CHK_SOURCES} || true # eof diff --git a/test/lisp/progmodes/flymake-resources/errors-and-warnings.c b/test/lisp/progmodes/flymake-resources/errors-and-warnings.c new file mode 100644 index 00000000000..1d38bd6bd27 --- /dev/null +++ b/test/lisp/progmodes/flymake-resources/errors-and-warnings.c @@ -0,0 +1,13 @@ +/* Flymake should notice an error on the next line, since + that file has at least one warning.*/ +#include "some-problems.h" +/* But not this one */ +#include "no-problems.h" + +int main() +{ + char c = 1000; /* a note and a warning */ + int bla; + char c; if (bla == (void*)3); /* an error, and two warnings */ + return c; +} diff --git a/test/lisp/progmodes/flymake-resources/no-problems.h b/test/lisp/progmodes/flymake-resources/no-problems.h new file mode 100644 index 00000000000..19ddc615b32 --- /dev/null +++ b/test/lisp/progmodes/flymake-resources/no-problems.h @@ -0,0 +1 @@ +typedef int no_problems; diff --git a/test/lisp/progmodes/flymake-resources/some-problems.h b/test/lisp/progmodes/flymake-resources/some-problems.h new file mode 100644 index 00000000000..165d8dd525e --- /dev/null +++ b/test/lisp/progmodes/flymake-resources/some-problems.h @@ -0,0 +1,5 @@ +#include <stdio.h> + +strange; + +sint main(); diff --git a/test/lisp/progmodes/flymake-tests.el b/test/lisp/progmodes/flymake-tests.el index b04346fd97c..5e042f2b082 100644 --- a/test/lisp/progmodes/flymake-tests.el +++ b/test/lisp/progmodes/flymake-tests.el @@ -1,4 +1,4 @@ -;;; flymake-tests.el --- Test suite for flymake +;;; flymake-tests.el --- Test suite for flymake -*- lexical-binding: t -*- ;; Copyright (C) 2011-2017 Free Software Foundation, Inc. @@ -26,54 +26,295 @@ (require 'flymake) (defvar flymake-tests-data-directory - (expand-file-name "lisp/progmodes/flymake-resources" (getenv "EMACS_TEST_DIRECTORY")) + (expand-file-name "lisp/progmodes/flymake-resources" + (or (getenv "EMACS_TEST_DIRECTORY") + (expand-file-name "../../.." + (or load-file-name + buffer-file-name)))) "Directory containing flymake test data.") -;; Warning predicate -(defun flymake-tests--current-face (file predicate) - (let ((buffer (find-file-noselect - (expand-file-name file flymake-tests-data-directory))) - (process-environment (cons "LC_ALL=C" process-environment)) - (i 0)) +;; +;; +(defun flymake-tests--wait-for-backends () + ;; Weirdness here... http://debbugs.gnu.org/17647#25 + ;; ... meaning `sleep-for', and even + ;; `accept-process-output', won't suffice as ways to get + ;; process filters and sentinels to run, though they do work + ;; fine in a non-interactive batch session. The only thing + ;; that will indeed unblock pending process output is + ;; reading an input event, so, as a workaround, use a dummy + ;; `read-event' with a very short timeout. + (unless noninteractive (read-event "" nil 0.1)) + (cl-loop repeat 5 + for notdone = (cl-set-difference (flymake-running-backends) + (flymake-reporting-backends)) + while notdone + unless noninteractive do (read-event "" nil 0.1) + do (sleep-for (+ 0.5 flymake-no-changes-timeout)) + finally (when notdone (ert-fail + (format "Some backends not reporting yet %s" + notdone))))) + +(cl-defun flymake-tests--call-with-fixture (fn file + &key (severity-predicate + nil sev-pred-supplied-p)) + "Call FN after flymake setup in FILE, using `flymake-proc`. +SEVERITY-PREDICATE is used to setup +`flymake-proc-diagnostic-type-pred'" + (let* ((file (expand-file-name file flymake-tests-data-directory)) + (visiting (find-buffer-visiting file)) + (buffer (or visiting (find-file-noselect file))) + (process-environment (cons "LC_ALL=C" process-environment)) + (warning-minimum-log-level :error)) (unwind-protect (with-current-buffer buffer - (setq-local flymake-warning-predicate predicate) - (goto-char (point-min)) - (flymake-mode 1) - ;; Weirdness here... https://debbugs.gnu.org/17647#25 - (while (and flymake-is-running (< (setq i (1+ i)) 10)) - (sleep-for (+ 0.5 flymake-no-changes-timeout))) - (flymake-goto-next-error) - (face-at-point)) - (and buffer (let (kill-buffer-query-functions) (kill-buffer buffer)))))) + (save-excursion + (when sev-pred-supplied-p + (setq-local flymake-proc-diagnostic-type-pred severity-predicate)) + (goto-char (point-min)) + (unless flymake-mode (flymake-mode 1)) + (flymake-tests--wait-for-backends) + (funcall fn))) + (and buffer + (not visiting) + (let (kill-buffer-query-functions) (kill-buffer buffer)))))) + +(cl-defmacro flymake-tests--with-flymake ((file &rest args) + &body body) + (declare (indent 1) + (debug (sexp &rest form))) + `(flymake-tests--call-with-fixture (lambda () ,@body) ,file ,@args)) (ert-deftest warning-predicate-rx-gcc () "Test GCC warning via regexp predicate." (skip-unless (and (executable-find "gcc") (executable-find "make"))) - (should (eq 'flymake-warnline - (flymake-tests--current-face "test.c" "^[Ww]arning")))) + (flymake-tests--with-flymake + ("test.c" :severity-predicate "^[Ww]arning") + (flymake-goto-next-error) + (should (eq 'flymake-warning + (face-at-point))))) (ert-deftest warning-predicate-function-gcc () "Test GCC warning via function predicate." (skip-unless (and (executable-find "gcc") (executable-find "make"))) - (should (eq 'flymake-warnline - (flymake-tests--current-face "test.c" - (lambda (msg) (string-match "^[Ww]arning" msg)))))) + (flymake-tests--with-flymake + ("test.c" :severity-predicate + (lambda (msg) (string-match "^[Ww]arning" msg))) + (flymake-goto-next-error) + (should (eq 'flymake-warning + (face-at-point))))) (ert-deftest warning-predicate-rx-perl () "Test perl warning via regular expression predicate." (skip-unless (executable-find "perl")) - (should (eq 'flymake-warnline - (flymake-tests--current-face "test.pl" "^Scalar value")))) + (flymake-tests--with-flymake + ("test.pl" :severity-predicate "^Scalar value") + (flymake-goto-next-error) + (should (eq 'flymake-warning + (face-at-point))))) (ert-deftest warning-predicate-function-perl () "Test perl warning via function predicate." (skip-unless (executable-find "perl")) - (should (eq 'flymake-warnline - (flymake-tests--current-face - "test.pl" - (lambda (msg) (string-match "^Scalar value" msg)))))) + (flymake-tests--with-flymake + ("test.pl" :severity-predicate + (lambda (msg) (string-match "^Scalar value" msg))) + (flymake-goto-next-error) + (should (eq 'flymake-warning + (face-at-point))))) + +(ert-deftest different-diagnostic-types () + "Test GCC warning via function predicate." + (skip-unless (and (executable-find "gcc") (executable-find "make"))) + (let ((flymake-wrap-around nil)) + (flymake-tests--with-flymake + ("errors-and-warnings.c") + (flymake-goto-next-error) + (should (eq 'flymake-error (face-at-point))) + (flymake-goto-next-error) + (should (eq 'flymake-note (face-at-point))) + (flymake-goto-next-error) + (should (eq 'flymake-warning (face-at-point))) + (flymake-goto-next-error) + (should (eq 'flymake-error (face-at-point))) + (flymake-goto-next-error) + (should (eq 'flymake-warning (face-at-point))) + (flymake-goto-next-error) + (should (eq 'flymake-warning (face-at-point))) + (should-error (flymake-goto-next-error nil nil t))))) + +(ert-deftest included-c-header-files () + "Test inclusion of .h header files." + (skip-unless (and (executable-find "gcc") (executable-find "make"))) + (let ((flymake-wrap-around nil)) + (flymake-tests--with-flymake + ("some-problems.h") + (flymake-goto-next-error) + (should (eq 'flymake-warning (face-at-point))) + (flymake-goto-next-error) + (should (eq 'flymake-error (face-at-point))) + (should-error (flymake-goto-next-error nil nil t))) + (flymake-tests--with-flymake + ("no-problems.h") + (should-error (flymake-goto-next-error nil nil t))))) + +(defmacro flymake-tests--assert-set (set + should + should-not) + (declare (indent 1)) + `(progn + ,@(cl-loop + for s in should + collect `(should (memq (quote ,s) ,set))) + ,@(cl-loop + for s in should-not + collect `(should-not (memq (quote ,s) ,set))))) + +(defun flymake-tests--diagnose-words + (report-fn type words) + "Helper. Call REPORT-FN with diagnostics for WORDS in buffer." + (funcall report-fn + (cl-loop + for word in words + append + (save-excursion + (goto-char (point-min)) + (cl-loop while (word-search-forward word nil t) + collect (flymake-make-diagnostic + (current-buffer) + (match-beginning 0) + (match-end 0) + type + (concat word " is wrong"))))))) + +(ert-deftest dummy-backends () + "Test many different kinds of backends." + (with-temp-buffer + (cl-letf + (((symbol-function 'error-backend) + (lambda (report-fn) + (run-with-timer + 0.5 nil + #'flymake-tests--diagnose-words report-fn :error '("manha" "prognata")))) + ((symbol-function 'warning-backend) + (lambda (report-fn) + (run-with-timer + 0.5 nil + #'flymake-tests--diagnose-words report-fn :warning '("ut" "dolor")))) + ((symbol-function 'sync-backend) + (lambda (report-fn) + (flymake-tests--diagnose-words report-fn :note '("quis" "commodo")))) + ((symbol-function 'panicking-backend) + (lambda (report-fn) + (run-with-timer + 0.5 nil + report-fn :panic :explanation "The spanish inquisition!"))) + ((symbol-function 'crashing-backend) + (lambda (_report-fn) + ;; HACK: Shoosh log during tests + (setq-local warning-minimum-log-level :emergency) + (error "crashed")))) + (insert "Lorem ipsum dolor sit amet, consectetur adipiscing + elit, sed do eiusmod tempor incididunt ut labore et dolore + manha aliqua. Ut enim ad minim veniam, quis nostrud + exercitation ullamco laboris nisi ut aliquip ex ea commodo + consequat. Duis aute irure dolor in reprehenderit in + voluptate velit esse cillum dolore eu fugiat nulla + pariatur. Excepteur sint occaecat cupidatat non prognata + sunt in culpa qui officia deserunt mollit anim id est + laborum.") + (let ((flymake-diagnostic-functions + (list 'error-backend 'warning-backend 'sync-backend + 'panicking-backend + 'crashing-backend + )) + (flymake-wrap-around nil)) + (flymake-mode) + + (flymake-tests--assert-set (flymake-running-backends) + (error-backend warning-backend panicking-backend) + (crashing-backend)) + + (flymake-tests--assert-set (flymake-disabled-backends) + (crashing-backend) + (error-backend warning-backend sync-backend + panicking-backend)) + + (flymake-tests--wait-for-backends) + + (flymake-tests--assert-set (flymake-disabled-backends) + (crashing-backend panicking-backend) + (error-backend warning-backend sync-backend)) + + (goto-char (point-min)) + (flymake-goto-next-error) + (should (eq 'flymake-warning (face-at-point))) ; dolor + (flymake-goto-next-error) + (should (eq 'flymake-warning (face-at-point))) ; ut + (flymake-goto-next-error) + (should (eq 'flymake-error (face-at-point))) ; manha + (flymake-goto-next-error) + (should (eq 'flymake-warning (face-at-point))) ; Ut + (flymake-goto-next-error) + (should (eq 'flymake-note (face-at-point))) ; quis + (flymake-goto-next-error) + (should (eq 'flymake-warning (face-at-point))) ; ut + (flymake-goto-next-error) + (should (eq 'flymake-note (face-at-point))) ; commodo + (flymake-goto-next-error) + (should (eq 'flymake-warning (face-at-point))) ; dolor + (flymake-goto-next-error) + (should (eq 'flymake-error (face-at-point))) ; prognata + (should-error (flymake-goto-next-error nil nil t)))))) + +(ert-deftest recurrent-backend () + "Test a backend that calls REPORT-FN multiple times" + (with-temp-buffer + (let (tick) + (cl-letf + (((symbol-function 'eager-backend) + (lambda (report-fn) + (funcall report-fn nil :explanation "very eager but no diagnostics") + (display-buffer (current-buffer)) + (run-with-timer + 0.5 nil + (lambda () + (flymake-tests--diagnose-words report-fn :warning '("consectetur")) + (setq tick t) + (run-with-timer + 0.5 nil + (lambda () + (flymake-tests--diagnose-words report-fn :error '("fugiat")) + (setq tick t)))))))) + (insert "Lorem ipsum dolor sit amet, consectetur adipiscing + elit, sed do eiusmod tempor incididunt ut labore et dolore + manha aliqua. Ut enim ad minim veniam, quis nostrud + exercitation ullamco laboris nisi ut aliquip ex ea commodo + consequat. Duis aute irure dolor in reprehenderit in + voluptate velit esse cillum dolore eu fugiat nulla + pariatur. Excepteur sint occaecat cupidatat non prognata + sunt in culpa qui officia deserunt mollit anim id est + laborum.") + (let ((flymake-diagnostic-functions + (list 'eager-backend)) + (flymake-wrap-around nil)) + (flymake-mode) + (flymake-tests--assert-set (flymake-running-backends) + (eager-backend) ()) + (cl-loop until tick repeat 4 do (sleep-for 0.2)) + (setq tick nil) + (goto-char (point-max)) + (flymake-goto-prev-error) + (should (eq 'flymake-warning (face-at-point))) ; consectetur + (should-error (flymake-goto-prev-error nil nil t)) + (cl-loop until tick repeat 4 do (sleep-for 0.2)) + (flymake-goto-next-error) + (should (eq 'flymake-error (face-at-point))) ; fugiat + (flymake-goto-prev-error) + (should (eq 'flymake-warning (face-at-point))) ; back at consectetur + (should-error (flymake-goto-prev-error nil nil t)) + ))))) (provide 'flymake-tests) |