diff options
| author | Yuan Fu | 2022-06-14 15:59:46 -0700 |
|---|---|---|
| committer | Yuan Fu | 2022-06-14 15:59:46 -0700 |
| commit | 98bfb240818bae14cd87a1ffeb8fae7cb7846e05 (patch) | |
| tree | 16e8ab06875ed54e110cf98ccdbd7e78f15905c6 /test/src | |
| parent | 184d212042ffa5a4f02c92085d9b6e8346d66e99 (diff) | |
| parent | 787c4ad8b0776280305a220d6669c956d9ed8a5d (diff) | |
| download | emacs-98bfb240818bae14cd87a1ffeb8fae7cb7846e05.tar.gz emacs-98bfb240818bae14cd87a1ffeb8fae7cb7846e05.zip | |
Merge remote-tracking branch 'savannah/master' into feature/tree-sitter
Diffstat (limited to 'test/src')
| -rw-r--r-- | test/src/buffer-tests.el | 49 | ||||
| -rw-r--r-- | test/src/comp-tests.el | 9 | ||||
| -rw-r--r-- | test/src/eval-tests.el | 27 | ||||
| -rw-r--r-- | test/src/fileio-tests.el | 10 | ||||
| -rw-r--r-- | test/src/image-tests.el | 7 | ||||
| -rw-r--r-- | test/src/lread-tests.el | 41 | ||||
| -rw-r--r-- | test/src/print-tests.el | 105 | ||||
| -rw-r--r-- | test/src/process-tests.el | 2 |
8 files changed, 247 insertions, 3 deletions
diff --git a/test/src/buffer-tests.el b/test/src/buffer-tests.el index c1e5d0ebed3..13d48b31a4f 100644 --- a/test/src/buffer-tests.el +++ b/test/src/buffer-tests.el | |||
| @@ -1482,4 +1482,53 @@ with parameters from the *Messages* buffer modification." | |||
| 1482 | (when auto-save | 1482 | (when auto-save |
| 1483 | (ignore-errors (delete-file auto-save)))))))) | 1483 | (ignore-errors (delete-file auto-save)))))))) |
| 1484 | 1484 | ||
| 1485 | (ert-deftest test-buffer-modifications () | ||
| 1486 | (ert-with-temp-file file | ||
| 1487 | (with-current-buffer (find-file file) | ||
| 1488 | (auto-save-mode 1) | ||
| 1489 | (should-not (buffer-modified-p)) | ||
| 1490 | (insert "foo") | ||
| 1491 | (should (buffer-modified-p)) | ||
| 1492 | (should-not (eq (buffer-modified-p) 'autosaved)) | ||
| 1493 | (do-auto-save nil t) | ||
| 1494 | (should (eq (buffer-modified-p) 'autosaved)) | ||
| 1495 | (with-silent-modifications | ||
| 1496 | (put-text-property 1 3 'face 'bold)) | ||
| 1497 | (should (eq (buffer-modified-p) 'autosaved)) | ||
| 1498 | (save-buffer) | ||
| 1499 | (should-not (buffer-modified-p)) | ||
| 1500 | (with-silent-modifications | ||
| 1501 | (put-text-property 1 3 'face 'italic)) | ||
| 1502 | (should-not (buffer-modified-p))))) | ||
| 1503 | |||
| 1504 | (ert-deftest test-restore-buffer-modified-p () | ||
| 1505 | (ert-with-temp-file file | ||
| 1506 | (with-current-buffer (find-file file) | ||
| 1507 | (auto-save-mode 1) | ||
| 1508 | (should-not (buffer-modified-p)) | ||
| 1509 | (insert "foo") | ||
| 1510 | (should (buffer-modified-p)) | ||
| 1511 | (restore-buffer-modified-p nil) | ||
| 1512 | (should-not (buffer-modified-p)) | ||
| 1513 | (insert "bar") | ||
| 1514 | (do-auto-save nil t) | ||
| 1515 | (should (eq (buffer-modified-p) 'autosaved)) | ||
| 1516 | (insert "zot") | ||
| 1517 | (restore-buffer-modified-p 'autosaved) | ||
| 1518 | (should (eq (buffer-modified-p) 'autosaved)) | ||
| 1519 | |||
| 1520 | ;; Clean up. | ||
| 1521 | (when (file-exists-p buffer-auto-save-file-name) | ||
| 1522 | (delete-file buffer-auto-save-file-name)))) | ||
| 1523 | |||
| 1524 | (ert-with-temp-file file | ||
| 1525 | (with-current-buffer (find-file file) | ||
| 1526 | (auto-save-mode 1) | ||
| 1527 | (should-not (buffer-modified-p)) | ||
| 1528 | (insert "foo") | ||
| 1529 | (should (buffer-modified-p)) | ||
| 1530 | (should-not (eq (buffer-modified-p) 'autosaved)) | ||
| 1531 | (restore-buffer-modified-p 'autosaved) | ||
| 1532 | (should (eq (buffer-modified-p) 'autosaved))))) | ||
| 1533 | |||
| 1485 | ;;; buffer-tests.el ends here | 1534 | ;;; buffer-tests.el ends here |
diff --git a/test/src/comp-tests.el b/test/src/comp-tests.el index 212d9e999f2..e7b534d00ec 100644 --- a/test/src/comp-tests.el +++ b/test/src/comp-tests.el | |||
| @@ -51,7 +51,14 @@ | |||
| 51 | (doc-string 3)) | 51 | (doc-string 3)) |
| 52 | `(ert-deftest ,(intern (concat "comp-tests-" (symbol-name name))) ,args | 52 | `(ert-deftest ,(intern (concat "comp-tests-" (symbol-name name))) ,args |
| 53 | :tags '(:nativecomp) | 53 | :tags '(:nativecomp) |
| 54 | ,@docstring-and-body)) | 54 | ,@(and (stringp (car docstring-and-body)) |
| 55 | (list (pop docstring-and-body))) | ||
| 56 | ;; Some of the tests leave spill files behind -- so create a | ||
| 57 | ;; sub-dir where native-comp can do its work, and then delete it | ||
| 58 | ;; at the end. | ||
| 59 | (ert-with-temp-directory dir | ||
| 60 | (let ((temporary-file-directory dir)) | ||
| 61 | ,@docstring-and-body)))) | ||
| 55 | 62 | ||
| 56 | 63 | ||
| 57 | 64 | ||
diff --git a/test/src/eval-tests.el b/test/src/eval-tests.el index e4230c10efd..1b2ad99360b 100644 --- a/test/src/eval-tests.el +++ b/test/src/eval-tests.el | |||
| @@ -240,4 +240,31 @@ expressions works for identifiers starting with period." | |||
| 240 | (should (equal (string-trim (buffer-string)) | 240 | (should (equal (string-trim (buffer-string)) |
| 241 | "Error: (error \"Boo\")"))))) | 241 | "Error: (error \"Boo\")"))))) |
| 242 | 242 | ||
| 243 | (ert-deftest eval-tests/funcall-with-delayed-message () | ||
| 244 | ;; Check that `funcall-with-delayed-message' displays its message before | ||
| 245 | ;; its function terminates iff the timeout is short enough. | ||
| 246 | |||
| 247 | ;; This also serves as regression test for bug#55628 where a short | ||
| 248 | ;; timeout was rounded up to the next whole second. | ||
| 249 | (dolist (params '((0.8 0.4) | ||
| 250 | (0.1 0.8))) | ||
| 251 | (let ((timeout (nth 0 params)) | ||
| 252 | (work-time (nth 1 params))) | ||
| 253 | (ert-info ((prin1-to-string params) :prefix "params: ") | ||
| 254 | (with-current-buffer "*Messages*" | ||
| 255 | (let ((inhibit-read-only t)) | ||
| 256 | (erase-buffer)) | ||
| 257 | (let ((stop (+ (float-time) work-time))) | ||
| 258 | (funcall-with-delayed-message | ||
| 259 | timeout "timed out" | ||
| 260 | (lambda () | ||
| 261 | (while (< (float-time) stop)) | ||
| 262 | (message "finished")))) | ||
| 263 | (let ((expected-messages | ||
| 264 | (if (< timeout work-time) | ||
| 265 | "timed out\nfinished" | ||
| 266 | "finished"))) | ||
| 267 | (should (equal (string-trim (buffer-string)) | ||
| 268 | expected-messages)))))))) | ||
| 269 | |||
| 243 | ;;; eval-tests.el ends here | 270 | ;;; eval-tests.el ends here |
diff --git a/test/src/fileio-tests.el b/test/src/fileio-tests.el index 511490c5745..c137ce06f1a 100644 --- a/test/src/fileio-tests.el +++ b/test/src/fileio-tests.el | |||
| @@ -138,7 +138,7 @@ Also check that an encoding error can appear in a symlink." | |||
| 138 | (should (and (file-name-absolute-p name) | 138 | (should (and (file-name-absolute-p name) |
| 139 | (not (eq (aref name 0) ?~)))))) | 139 | (not (eq (aref name 0) ?~)))))) |
| 140 | 140 | ||
| 141 | (ert-deftest fileio-test--expand-file-name-null-bytes () | 141 | (ert-deftest fileio-tests--expand-file-name-null-bytes () |
| 142 | "Test that `expand-file-name' checks for null bytes in filenames." | 142 | "Test that `expand-file-name' checks for null bytes in filenames." |
| 143 | (should-error (expand-file-name (concat "file" (char-to-string ?\0) ".txt")) | 143 | (should-error (expand-file-name (concat "file" (char-to-string ?\0) ".txt")) |
| 144 | :type 'wrong-type-argument) | 144 | :type 'wrong-type-argument) |
| @@ -193,4 +193,12 @@ Also check that an encoding error can appear in a symlink." | |||
| 193 | (should (equal (file-name-concat "" "bar") "bar")) | 193 | (should (equal (file-name-concat "" "bar") "bar")) |
| 194 | (should (equal (file-name-concat "" "") ""))) | 194 | (should (equal (file-name-concat "" "") ""))) |
| 195 | 195 | ||
| 196 | (ert-deftest fileio-tests--non-regular-insert () | ||
| 197 | (skip-unless (file-exists-p "/dev/urandom")) | ||
| 198 | (with-temp-buffer | ||
| 199 | (set-buffer-multibyte nil) | ||
| 200 | (should-error (insert-file-contents "/dev/urandom" nil 5 10)) | ||
| 201 | (insert-file-contents "/dev/urandom" nil nil 10) | ||
| 202 | (should (= (buffer-size) 10)))) | ||
| 203 | |||
| 196 | ;;; fileio-tests.el ends here | 204 | ;;; fileio-tests.el ends here |
diff --git a/test/src/image-tests.el b/test/src/image-tests.el index 3885981e0b2..f710aadea74 100644 --- a/test/src/image-tests.el +++ b/test/src/image-tests.el | |||
| @@ -53,6 +53,8 @@ | |||
| 53 | 53 | ||
| 54 | ;;;; image-test-size | 54 | ;;;; image-test-size |
| 55 | 55 | ||
| 56 | (declare-function image-size "image.c" (spec &optional pixels frame)) | ||
| 57 | |||
| 56 | (ert-deftest image-tests-image-size/gif () | 58 | (ert-deftest image-tests-image-size/gif () |
| 57 | (image-skip-unless 'gif) | 59 | (image-skip-unless 'gif) |
| 58 | (pcase (image-size (create-image (cdr (assq 'gif image-tests--images)))) | 60 | (pcase (image-size (create-image (cdr (assq 'gif image-tests--images)))) |
| @@ -126,6 +128,8 @@ | |||
| 126 | 128 | ||
| 127 | ;;;; image-mask-p | 129 | ;;;; image-mask-p |
| 128 | 130 | ||
| 131 | (declare-function image-mask-p "image.c" (spec &optional frame)) | ||
| 132 | |||
| 129 | (ert-deftest image-tests-image-mask-p/gif () | 133 | (ert-deftest image-tests-image-mask-p/gif () |
| 130 | (image-skip-unless 'gif) | 134 | (image-skip-unless 'gif) |
| 131 | (should-not (image-mask-p (create-image | 135 | (should-not (image-mask-p (create-image |
| @@ -176,6 +180,8 @@ | |||
| 176 | 180 | ||
| 177 | ;;;; image-metadata | 181 | ;;;; image-metadata |
| 178 | 182 | ||
| 183 | (declare-function image-metadata "image.c" (spec &optional frame)) | ||
| 184 | |||
| 179 | ;; TODO: These tests could be expanded with files that actually | 185 | ;; TODO: These tests could be expanded with files that actually |
| 180 | ;; contain metadata. | 186 | ;; contain metadata. |
| 181 | 187 | ||
| @@ -238,6 +244,7 @@ | |||
| 238 | 244 | ||
| 239 | (ert-deftest image-tests-init-image-library () | 245 | (ert-deftest image-tests-init-image-library () |
| 240 | (skip-unless (fboundp 'init-image-library)) | 246 | (skip-unless (fboundp 'init-image-library)) |
| 247 | (declare-function init-image-library "image.c" (type)) | ||
| 241 | (should (init-image-library 'pbm)) ; built-in | 248 | (should (init-image-library 'pbm)) ; built-in |
| 242 | (should-not (init-image-library 'invalid-image-type))) | 249 | (should-not (init-image-library 'invalid-image-type))) |
| 243 | 250 | ||
diff --git a/test/src/lread-tests.el b/test/src/lread-tests.el index 9ec54c719c8..f190f14781e 100644 --- a/test/src/lread-tests.el +++ b/test/src/lread-tests.el | |||
| @@ -281,4 +281,45 @@ literals (Bug#20852)." | |||
| 281 | (should (equal (lread-test-read-and-print str) str)))) | 281 | (should (equal (lread-test-read-and-print str) str)))) |
| 282 | (should-error (read-from-string "#1=#1#") :type 'invalid-read-syntax)) | 282 | (should-error (read-from-string "#1=#1#") :type 'invalid-read-syntax)) |
| 283 | 283 | ||
| 284 | (ert-deftest lread-deeply-nested () | ||
| 285 | ;; Check that we can read a deeply nested data structure correctly. | ||
| 286 | (let ((levels 10000) | ||
| 287 | (prefix nil) | ||
| 288 | (suffix nil)) | ||
| 289 | (dotimes (_ levels) | ||
| 290 | (push "([#s(r " prefix) | ||
| 291 | (push ")])" suffix)) | ||
| 292 | (let ((str (concat (apply #'concat prefix) | ||
| 293 | "a" | ||
| 294 | (apply #'concat suffix)))) | ||
| 295 | (let* ((read-circle t) | ||
| 296 | (result (read-from-string str))) | ||
| 297 | (should (equal (cdr result) (length str))) | ||
| 298 | ;; Check the result. (We can't build a reference value and compare | ||
| 299 | ;; using `equal' because that function is currently depth-limited.) | ||
| 300 | (named-let check ((x (car result)) (level 0)) | ||
| 301 | (if (equal level levels) | ||
| 302 | (should (equal x 'a)) | ||
| 303 | (should (and (consp x) (null (cdr x)))) | ||
| 304 | (let ((x2 (car x))) | ||
| 305 | (should (and (vectorp x2) (equal (length x2) 1))) | ||
| 306 | (let ((x3 (aref x2 0))) | ||
| 307 | (should (and (recordp x3) (equal (length x3) 2) | ||
| 308 | (equal (aref x3 0) 'r))) | ||
| 309 | (check (aref x3 1) (1+ level)))))))))) | ||
| 310 | |||
| 311 | (ert-deftest lread-misc () | ||
| 312 | ;; Regression tests for issues found and fixed in bug#55676: | ||
| 313 | ;; Non-breaking space after a dot makes it a dot token. | ||
| 314 | (should (equal (read-from-string "(a .\u00A0b)") | ||
| 315 | '((a . b) . 7))) | ||
| 316 | ;; #_ without symbol following is the interned empty symbol. | ||
| 317 | (should (equal (read-from-string "#_") | ||
| 318 | '(## . 2)))) | ||
| 319 | |||
| 320 | (ert-deftest lread-escaped-lf () | ||
| 321 | ;; ?\LF should signal an error; \LF is ignored inside string literals. | ||
| 322 | (should-error (read-from-string "?\\\n x")) | ||
| 323 | (should (equal (read-from-string "\"a\\\nb\"") '("ab" . 6)))) | ||
| 324 | |||
| 284 | ;;; lread-tests.el ends here | 325 | ;;; lread-tests.el ends here |
diff --git a/test/src/print-tests.el b/test/src/print-tests.el index 0bae1959d1b..6ff7e997837 100644 --- a/test/src/print-tests.el +++ b/test/src/print-tests.el | |||
| @@ -425,5 +425,110 @@ otherwise, use a different charset." | |||
| 425 | (should (equal (prin1-to-string '\?bar) "\\?bar")) | 425 | (should (equal (prin1-to-string '\?bar) "\\?bar")) |
| 426 | (should (equal (prin1-to-string '\?bar?) "\\?bar?"))) | 426 | (should (equal (prin1-to-string '\?bar?) "\\?bar?"))) |
| 427 | 427 | ||
| 428 | (ert-deftest test-prin1-overrides () | ||
| 429 | (with-temp-buffer | ||
| 430 | (let ((print-length 10)) | ||
| 431 | (prin1 (make-list 20 t) (current-buffer) t) | ||
| 432 | (should (= print-length 10))) | ||
| 433 | (goto-char (point-min)) | ||
| 434 | (should (= (length (read (current-buffer))) 20))) | ||
| 435 | |||
| 436 | (with-temp-buffer | ||
| 437 | (let ((print-length 10)) | ||
| 438 | (prin1 (make-list 20 t) (current-buffer) '((length . 5))) | ||
| 439 | (should (= print-length 10))) | ||
| 440 | (goto-char (point-min)) | ||
| 441 | (should (= (length (read (current-buffer))) 6))) | ||
| 442 | |||
| 443 | (with-temp-buffer | ||
| 444 | (let ((print-length 10)) | ||
| 445 | (prin1 (make-list 20 t) (current-buffer) '(t (length . 5))) | ||
| 446 | (should (= print-length 10))) | ||
| 447 | (goto-char (point-min)) | ||
| 448 | (should (= (length (read (current-buffer))) 6)))) | ||
| 449 | |||
| 450 | (ert-deftest test-prin1-to-string-overrides () | ||
| 451 | (let ((print-length 10)) | ||
| 452 | (should | ||
| 453 | (= (length (car (read-from-string | ||
| 454 | (prin1-to-string (make-list 20 t) nil t)))) | ||
| 455 | 20))) | ||
| 456 | |||
| 457 | (let ((print-length 10)) | ||
| 458 | (should | ||
| 459 | (= (length (car (read-from-string | ||
| 460 | (prin1-to-string (make-list 20 t) nil | ||
| 461 | '((length . 5)))))) | ||
| 462 | 6))) | ||
| 463 | |||
| 464 | (should-error (prin1-to-string 'foo nil 'a)) | ||
| 465 | (should-error (prin1-to-string 'foo nil '(a))) | ||
| 466 | (should-error (prin1-to-string 'foo nil '(t . b))) | ||
| 467 | (should-error (prin1-to-string 'foo nil '(t b))) | ||
| 468 | (should-error (prin1-to-string 'foo nil '((a . b) b))) | ||
| 469 | (should-error (prin1-to-string 'foo nil '((length . 10) . b)))) | ||
| 470 | |||
| 471 | (ert-deftest print-deeply-nested () | ||
| 472 | ;; Check that we can print a deeply nested data structure correctly. | ||
| 473 | (let ((print-circle t)) | ||
| 474 | (let ((levels 10000) | ||
| 475 | (x 'a) | ||
| 476 | (prefix nil) | ||
| 477 | (suffix nil)) | ||
| 478 | (dotimes (_ levels) | ||
| 479 | (setq x (list (vector (record 'r x)))) | ||
| 480 | (push "([#s(r " prefix) | ||
| 481 | (push ")])" suffix)) | ||
| 482 | (let ((expected (concat (apply #'concat prefix) | ||
| 483 | "a" | ||
| 484 | (apply #'concat suffix)))) | ||
| 485 | (should (equal (prin1-to-string x) expected)))))) | ||
| 486 | |||
| 487 | (defun print-test-rho (lead loop) | ||
| 488 | "A circular iota list with LEAD elements followed by LOOP in circle." | ||
| 489 | (let ((l (number-sequence 1 (+ lead loop)))) | ||
| 490 | (setcdr (nthcdr (+ lead loop -1) l) (nthcdr lead l)) | ||
| 491 | l)) | ||
| 492 | |||
| 493 | (ert-deftest print-circular () | ||
| 494 | ;; Check printing of rho-shaped circular lists such as (1 2 3 4 5 4 5 4 . #6) | ||
| 495 | ;; when `print-circle' is nil. The exact output may differ since the number | ||
| 496 | ;; of elements printed of the looping part can vary depending on when the | ||
| 497 | ;; circularity was detected. | ||
| 498 | (dotimes (lead 7) | ||
| 499 | (ert-info ((prin1-to-string lead) :prefix "lead: ") | ||
| 500 | (dolist (loop (number-sequence 1 7)) | ||
| 501 | (ert-info ((prin1-to-string loop) :prefix "loop: ") | ||
| 502 | (let* ((rho (print-test-rho lead loop)) | ||
| 503 | (print-circle nil) | ||
| 504 | (str (prin1-to-string rho))) | ||
| 505 | (should (string-match (rx "(" | ||
| 506 | (group (+ (+ digit) " ")) | ||
| 507 | ". #" (group (+ digit)) ")") | ||
| 508 | str)) | ||
| 509 | (let* ((g1 (match-string 1 str)) | ||
| 510 | (g2 (match-string 2 str)) | ||
| 511 | (numbers (mapcar #'string-to-number (split-string g1))) | ||
| 512 | (loopback-index (string-to-number g2))) | ||
| 513 | ;; Split the numbers in the lead and loop part. | ||
| 514 | (should (< lead (length numbers))) | ||
| 515 | (should (<= lead loopback-index)) | ||
| 516 | (should (< loopback-index (length numbers))) | ||
| 517 | (let ((lead-part (butlast numbers (- (length numbers) lead))) | ||
| 518 | (loop-part (nthcdr lead numbers))) | ||
| 519 | ;; The lead part must match exactly. | ||
| 520 | (should (equal lead-part (number-sequence 1 lead))) | ||
| 521 | ;; The loop part is at least LOOP long: make sure it matches. | ||
| 522 | (should (>= (length loop-part) loop)) | ||
| 523 | (let ((expected-loop-part | ||
| 524 | (mapcar (lambda (x) (+ lead 1 (% x loop))) | ||
| 525 | (number-sequence 0 (1- (length loop-part)))))) | ||
| 526 | (should (equal loop-part expected-loop-part)) | ||
| 527 | ;; The loopback index must match the length of the | ||
| 528 | ;; loop part. | ||
| 529 | (should (equal (% (- (length numbers) loopback-index) loop) | ||
| 530 | 0))))))))))) | ||
| 531 | |||
| 532 | |||
| 428 | (provide 'print-tests) | 533 | (provide 'print-tests) |
| 429 | ;;; print-tests.el ends here | 534 | ;;; print-tests.el ends here |
diff --git a/test/src/process-tests.el b/test/src/process-tests.el index f5908d3cda5..824c6da1191 100644 --- a/test/src/process-tests.el +++ b/test/src/process-tests.el | |||
| @@ -931,7 +931,7 @@ Return nil if FILENAME doesn't exist." | |||
| 931 | (< (float-time) (+ t0 limit))) | 931 | (< (float-time) (+ t0 limit))) |
| 932 | (sit-for 0.1))) | 932 | (sit-for 0.1))) |
| 933 | (should status) | 933 | (should status) |
| 934 | (should-not (assq :error status)) | 934 | (should-not (plist-get status ':error)) |
| 935 | (should buf) | 935 | (should buf) |
| 936 | (should (> (buffer-size buf) 0)) | 936 | (should (> (buffer-size buf) 0)) |
| 937 | ) | 937 | ) |