diff options
Diffstat (limited to 'test/src')
| -rw-r--r-- | test/src/emacs-module-tests.el | 87 | ||||
| -rw-r--r-- | test/src/fns-tests.el | 6 | ||||
| -rw-r--r-- | test/src/lread-tests.el | 23 |
3 files changed, 87 insertions, 29 deletions
diff --git a/test/src/emacs-module-tests.el b/test/src/emacs-module-tests.el index a4994b6223b..2aa85f0b247 100644 --- a/test/src/emacs-module-tests.el +++ b/test/src/emacs-module-tests.el | |||
| @@ -182,37 +182,66 @@ changes." | |||
| 182 | (should (equal (help-function-arglist #'mod-test-sum) | 182 | (should (equal (help-function-arglist #'mod-test-sum) |
| 183 | '(arg1 arg2)))) | 183 | '(arg1 arg2)))) |
| 184 | 184 | ||
| 185 | (ert-deftest module--test-assertions () | 185 | (defmacro module--with-temp-directory (name &rest body) |
| 186 | "Check that -module-assertions work." | 186 | "Bind NAME to the name of a temporary directory and evaluate BODY. |
| 187 | NAME must be a symbol. Delete the temporary directory after BODY | ||
| 188 | exits normally or non-locally. NAME will be bound to the | ||
| 189 | directory name (not the directory file name) of the temporary | ||
| 190 | directory." | ||
| 191 | (declare (indent 1)) | ||
| 192 | (cl-check-type name symbol) | ||
| 193 | `(let ((,name (file-name-as-directory | ||
| 194 | (make-temp-file "emacs-module-test" :directory)))) | ||
| 195 | (unwind-protect | ||
| 196 | (progn ,@body) | ||
| 197 | (delete-directory ,name :recursive)))) | ||
| 198 | |||
| 199 | (defmacro module--test-assertion (pattern &rest body) | ||
| 200 | "Test that PATTERN matches the assertion triggered by BODY. | ||
| 201 | Run Emacs as a subprocess, load the test module `mod-test-file', | ||
| 202 | and evaluate BODY. Verify that Emacs aborts and prints a module | ||
| 203 | assertion message that matches PATTERN. PATTERN is evaluated and | ||
| 204 | must evaluate to a regular expression string." | ||
| 205 | (declare (indent 1)) | ||
| 206 | ;; To contain any core dumps. | ||
| 207 | `(module--with-temp-directory tempdir | ||
| 208 | (with-temp-buffer | ||
| 209 | (let* ((default-directory tempdir) | ||
| 210 | (status (call-process mod-test-emacs nil t nil | ||
| 211 | "-batch" "-Q" "-module-assertions" "-eval" | ||
| 212 | ,(prin1-to-string | ||
| 213 | `(progn | ||
| 214 | (require 'mod-test ,mod-test-file) | ||
| 215 | ,@body))))) | ||
| 216 | (should (stringp status)) | ||
| 217 | ;; eg "Aborted" or "Abort trap: 6" | ||
| 218 | (should (string-prefix-p "Abort" status)) | ||
| 219 | (search-backward "Emacs module assertion: ") | ||
| 220 | (goto-char (match-end 0)) | ||
| 221 | (should (string-match-p ,pattern | ||
| 222 | (buffer-substring-no-properties | ||
| 223 | (point) (point-max)))))))) | ||
| 224 | |||
| 225 | (ert-deftest module--test-assertions--load-non-live-object () | ||
| 226 | "Check that -module-assertions verify that non-live objects | ||
| 227 | aren’t accessed." | ||
| 187 | (skip-unless (file-executable-p mod-test-emacs)) | 228 | (skip-unless (file-executable-p mod-test-emacs)) |
| 188 | ;; This doesn’t yet cause undefined behavior. | 229 | ;; This doesn’t yet cause undefined behavior. |
| 189 | (should (eq (mod-test-invalid-store) 123)) | 230 | (should (eq (mod-test-invalid-store) 123)) |
| 190 | ;; To contain any core dumps. | 231 | (module--test-assertion (rx "Emacs value not found in " |
| 191 | (let ((tempdir (make-temp-file "emacs-module-test" t))) | 232 | (+ digit) " values of " |
| 192 | (unwind-protect | 233 | (+ digit) " environments\n") |
| 193 | (with-temp-buffer | 234 | ;; Storing and reloading a local value causes undefined behavior, |
| 194 | (should (string-match-p | 235 | ;; which should be detected by the module assertions. |
| 195 | "Abort" ; eg "Aborted" or "Abort trap: 6" | 236 | (mod-test-invalid-store) |
| 196 | (let ((default-directory tempdir)) | 237 | (mod-test-invalid-load))) |
| 197 | (call-process mod-test-emacs nil t nil | 238 | |
| 198 | "-batch" "-Q" "-module-assertions" "-eval" | 239 | (ert-deftest module--test-assertions--call-emacs-from-gc () |
| 199 | (prin1-to-string | 240 | "Check that -module-assertions prevents calling Emacs functions |
| 200 | `(progn | 241 | during garbage collection." |
| 201 | (require 'mod-test ,mod-test-file) | 242 | (skip-unless (file-executable-p mod-test-emacs)) |
| 202 | ;; Storing and reloading a local | 243 | (module--test-assertion |
| 203 | ;; value causes undefined behavior, | 244 | (rx "Module function called during garbage collection\n") |
| 204 | ;; which should be detected by the | 245 | (mod-test-invalid-finalizer))) |
| 205 | ;; module assertions. | ||
| 206 | (mod-test-invalid-store) | ||
| 207 | (mod-test-invalid-load))))))) | ||
| 208 | (search-backward "Emacs module assertion:") | ||
| 209 | (should (string-match-p (rx bos "Emacs module assertion: " | ||
| 210 | "Emacs value not found in " | ||
| 211 | (+ digit) " values of " | ||
| 212 | (+ digit) " environments" eos) | ||
| 213 | (buffer-substring-no-properties | ||
| 214 | (line-beginning-position) | ||
| 215 | (line-end-position))))) | ||
| 216 | (delete-directory tempdir t)))) | ||
| 217 | 246 | ||
| 218 | ;;; emacs-module-tests.el ends here | 247 | ;;; emacs-module-tests.el ends here |
diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el index 2e463455f0c..e294859226c 100644 --- a/test/src/fns-tests.el +++ b/test/src/fns-tests.el | |||
| @@ -373,6 +373,12 @@ | |||
| 373 | (should-error (assoc 3 d1) :type 'wrong-type-argument) | 373 | (should-error (assoc 3 d1) :type 'wrong-type-argument) |
| 374 | (should-error (assoc 3 d2) :type 'wrong-type-argument))) | 374 | (should-error (assoc 3 d2) :type 'wrong-type-argument))) |
| 375 | 375 | ||
| 376 | (ert-deftest test-assoc-testfn () | ||
| 377 | (let ((alist '(("a" . 1) ("b" . 2)))) | ||
| 378 | (should-not (assoc "a" alist #'ignore)) | ||
| 379 | (should (eq (assoc "b" alist #'string-equal) (cadr alist))) | ||
| 380 | (should-not (assoc "b" alist #'eq)))) | ||
| 381 | |||
| 376 | (ert-deftest test-cycle-rassq () | 382 | (ert-deftest test-cycle-rassq () |
| 377 | (let ((c1 (cyc1 '(0 . 1))) | 383 | (let ((c1 (cyc1 '(0 . 1))) |
| 378 | (c2 (cyc2 '(0 . 1) '(0 . 2))) | 384 | (c2 (cyc2 '(0 . 1) '(0 . 2))) |
diff --git a/test/src/lread-tests.el b/test/src/lread-tests.el index 98cbb6a301d..dd5a2003b41 100644 --- a/test/src/lread-tests.el +++ b/test/src/lread-tests.el | |||
| @@ -142,6 +142,23 @@ literals (Bug#20852)." | |||
| 142 | "unescaped character literals " | 142 | "unescaped character literals " |
| 143 | "`?\"', `?(', `?)', `?;', `?[', `?]' detected!"))))) | 143 | "`?\"', `?(', `?)', `?;', `?[', `?]' detected!"))))) |
| 144 | 144 | ||
| 145 | (ert-deftest lread-tests--funny-quote-symbols () | ||
| 146 | "Check that 'smart quotes' or similar trigger errors in symbol names." | ||
| 147 | (dolist (quote-char | ||
| 148 | '(#x2018 ;; LEFT SINGLE QUOTATION MARK | ||
| 149 | #x2019 ;; RIGHT SINGLE QUOTATION MARK | ||
| 150 | #x201B ;; SINGLE HIGH-REVERSED-9 QUOTATION MARK | ||
| 151 | #x201C ;; LEFT DOUBLE QUOTATION MARK | ||
| 152 | #x201D ;; RIGHT DOUBLE QUOTATION MARK | ||
| 153 | #x201F ;; DOUBLE HIGH-REVERSED-9 QUOTATION MARK | ||
| 154 | #x301E ;; DOUBLE PRIME QUOTATION MARK | ||
| 155 | #xFF02 ;; FULLWIDTH QUOTATION MARK | ||
| 156 | #xFF07 ;; FULLWIDTH APOSTROPHE | ||
| 157 | )) | ||
| 158 | (let ((str (format "%cfoo" quote-char))) | ||
| 159 | (should-error (read str) :type 'invalid-read-syntax) | ||
| 160 | (should (eq (read (concat "\\" str)) (intern str)))))) | ||
| 161 | |||
| 145 | (ert-deftest lread-test-bug26837 () | 162 | (ert-deftest lread-test-bug26837 () |
| 146 | "Test for http://debbugs.gnu.org/26837 ." | 163 | "Test for http://debbugs.gnu.org/26837 ." |
| 147 | (let ((load-path (cons | 164 | (let ((load-path (cons |
| @@ -164,4 +181,10 @@ literals (Bug#20852)." | |||
| 164 | (concat (format-message "Loading `%s': " file-name) | 181 | (concat (format-message "Loading `%s': " file-name) |
| 165 | "old-style backquotes detected!"))))) | 182 | "old-style backquotes detected!"))))) |
| 166 | 183 | ||
| 184 | (ert-deftest lread-lread--substitute-object-in-subtree () | ||
| 185 | (let ((x (cons 0 1))) | ||
| 186 | (setcar x x) | ||
| 187 | (lread--substitute-object-in-subtree x 1 t) | ||
| 188 | (should (eq x (cdr x))))) | ||
| 189 | |||
| 167 | ;;; lread-tests.el ends here | 190 | ;;; lread-tests.el ends here |