diff options
| author | Andrea Corallo | 2021-04-13 12:06:23 +0200 |
|---|---|---|
| committer | Andrea Corallo | 2021-04-13 12:06:23 +0200 |
| commit | b064ddd3f600ed28e62b09d556ecced5f80d9883 (patch) | |
| tree | 2ddf4889f385beb34cd064f245a7e59265377c37 /test | |
| parent | 2d23f19e7d5ff8a1ec1a188dcd530c185029d1f8 (diff) | |
| parent | 6de79542e43ece9a12ebc032c275a6c3fee0b73b (diff) | |
| download | emacs-b064ddd3f600ed28e62b09d556ecced5f80d9883.tar.gz emacs-b064ddd3f600ed28e62b09d556ecced5f80d9883.zip | |
Merge remote-tracking branch 'savannah/master' into native-comp
Diffstat (limited to 'test')
| -rw-r--r-- | test/Makefile.in | 2 | ||||
| -rw-r--r-- | test/lisp/calculator-tests.el | 51 | ||||
| -rw-r--r-- | test/lisp/emacs-lisp/bytecomp-tests.el | 230 | ||||
| -rw-r--r-- | test/lisp/emacs-lisp/cl-macs-tests.el | 14 | ||||
| -rw-r--r-- | test/lisp/emacs-lisp/edebug-tests.el | 25 | ||||
| -rw-r--r-- | test/lisp/loadhist-tests.el | 57 | ||||
| -rw-r--r-- | test/lisp/shadowfile-tests.el | 2 | ||||
| -rw-r--r-- | test/manual/indent/scheme.scm | 23 | ||||
| l--------- | test/src/emacs-resources/seccomp-filter-exec.bpf | 1 | ||||
| l--------- | test/src/emacs-resources/seccomp-filter.bpf | 1 | ||||
| -rw-r--r-- | test/src/emacs-tests.el | 213 |
11 files changed, 480 insertions, 139 deletions
diff --git a/test/Makefile.in b/test/Makefile.in index 3cfd60d46c0..84ab4e70aee 100644 --- a/test/Makefile.in +++ b/test/Makefile.in | |||
| @@ -286,6 +286,8 @@ $(test_module): $(test_module:${SO}=.c) ../src/emacs-module.h | |||
| 286 | $(srcdir)/../lib/timespec.c $(srcdir)/../lib/gettime.c | 286 | $(srcdir)/../lib/timespec.c $(srcdir)/../lib/gettime.c |
| 287 | endif | 287 | endif |
| 288 | 288 | ||
| 289 | src/emacs-tests.log: ../lib-src/seccomp-filter.c | ||
| 290 | |||
| 289 | ## Check that there is no 'automated' subdirectory, which would | 291 | ## Check that there is no 'automated' subdirectory, which would |
| 290 | ## indicate an incomplete merge from an older version of Emacs where | 292 | ## indicate an incomplete merge from an older version of Emacs where |
| 291 | ## the tests were arranged differently. | 293 | ## the tests were arranged differently. |
diff --git a/test/lisp/calculator-tests.el b/test/lisp/calculator-tests.el new file mode 100644 index 00000000000..9551b1a4c61 --- /dev/null +++ b/test/lisp/calculator-tests.el | |||
| @@ -0,0 +1,51 @@ | |||
| 1 | ;;; calculator-tests.el --- Test suite for calculator. -*- lexical-binding: t -*- | ||
| 2 | |||
| 3 | ;; Copyright (C) 2021 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; This file is part of GNU Emacs. | ||
| 6 | |||
| 7 | ;; GNU Emacs is free software: you can redistribute it and/or modify | ||
| 8 | ;; it under the terms of the GNU General Public License as published by | ||
| 9 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 10 | ;; (at your option) any later version. | ||
| 11 | |||
| 12 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | ;; GNU General Public License for more details. | ||
| 16 | |||
| 17 | ;; You should have received a copy of the GNU General Public License | ||
| 18 | ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. | ||
| 19 | |||
| 20 | ;;; Code: | ||
| 21 | (require 'ert) | ||
| 22 | (require 'calculator) | ||
| 23 | |||
| 24 | (ert-deftest calculator-test-calculator-string-to-number () | ||
| 25 | (dolist (x '(("" 0.0) | ||
| 26 | ("+" 0.0) | ||
| 27 | ("-" 0.0) | ||
| 28 | ("." 0.0) | ||
| 29 | ("+." 0.0) | ||
| 30 | ("-." -0.0) | ||
| 31 | (".-" 0.0) | ||
| 32 | ("--." 0.0) | ||
| 33 | ("-0.0e" -0.0) | ||
| 34 | ("1e1" 10.0) | ||
| 35 | ("1e+1" 10.0) | ||
| 36 | ("1e-1" 0.1) | ||
| 37 | ("+1e1" 10.0) | ||
| 38 | ("-1e1" -10.0) | ||
| 39 | ("+1e-1" 0.1) | ||
| 40 | ("-1e-1" -0.1) | ||
| 41 | (".1.e1" 0.1) | ||
| 42 | (".1..e1" 0.1) | ||
| 43 | ("1e+1.1" 10.0) | ||
| 44 | ("-2e-1.1" -0.2))) | ||
| 45 | (pcase x | ||
| 46 | (`(,str ,expected) | ||
| 47 | (let ((calculator-input-radix nil)) | ||
| 48 | (should (equal (calculator-string-to-number str) expected))))))) | ||
| 49 | |||
| 50 | (provide 'calculator-tests) | ||
| 51 | ;; calculator-tests.el ends here | ||
diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el b/test/lisp/emacs-lisp/bytecomp-tests.el index 5147cd26883..a11832d805e 100644 --- a/test/lisp/emacs-lisp/bytecomp-tests.el +++ b/test/lisp/emacs-lisp/bytecomp-tests.el | |||
| @@ -41,7 +41,7 @@ | |||
| 41 | "Identity, but hidden from some optimisations." | 41 | "Identity, but hidden from some optimisations." |
| 42 | x) | 42 | x) |
| 43 | 43 | ||
| 44 | (defconst byte-opt-testsuite-arith-data | 44 | (defconst bytecomp-tests--test-cases |
| 45 | '( | 45 | '( |
| 46 | ;; some functional tests | 46 | ;; some functional tests |
| 47 | (let ((a most-positive-fixnum) (b 1) (c 1.0)) (+ a b c)) | 47 | (let ((a most-positive-fixnum) (b 1) (c 1.0)) (+ a b c)) |
| @@ -364,17 +364,17 @@ | |||
| 364 | '((a c) (b c) (7 c) (-3 c) (nil nil) (t c) (q c) (r c) (s c) | 364 | '((a c) (b c) (7 c) (-3 c) (nil nil) (t c) (q c) (r c) (s c) |
| 365 | (t c) (x "a") (x "c") (x c) (x d) (x e))) | 365 | (t c) (x "a") (x "c") (x c) (x d) (x e))) |
| 366 | 366 | ||
| 367 | (mapcar (lambda (x) (cond ((member '(a . b) x) 1) | 367 | (mapcar (lambda (x) (ignore-errors (cond ((member '(a . b) x) 1) |
| 368 | ((equal x '(c)) 2))) | 368 | ((equal x '(c)) 2)))) |
| 369 | '(((a . b)) a b (c) (d))) | 369 | '(((a . b)) a b (c) (d))) |
| 370 | (mapcar (lambda (x) (cond ((memq '(a . b) x) 1) | 370 | (mapcar (lambda (x) (ignore-errors (cond ((memq '(a . b) x) 1) |
| 371 | ((equal x '(c)) 2))) | 371 | ((equal x '(c)) 2)))) |
| 372 | '(((a . b)) a b (c) (d))) | 372 | '(((a . b)) a b (c) (d))) |
| 373 | (mapcar (lambda (x) (cond ((member '(a b) x) 1) | 373 | (mapcar (lambda (x) (ignore-errors (cond ((member '(a b) x) 1) |
| 374 | ((equal x '(c)) 2))) | 374 | ((equal x '(c)) 2)))) |
| 375 | '(((a b)) a b (c) (d))) | 375 | '(((a b)) a b (c) (d))) |
| 376 | (mapcar (lambda (x) (cond ((memq '(a b) x) 1) | 376 | (mapcar (lambda (x) (ignore-errors (cond ((memq '(a b) x) 1) |
| 377 | ((equal x '(c)) 2))) | 377 | ((equal x '(c)) 2)))) |
| 378 | '(((a b)) a b (c) (d))) | 378 | '(((a b)) a b (c) (d))) |
| 379 | 379 | ||
| 380 | (assoc 'b '((a 1) (b 2) (c 3))) | 380 | (assoc 'b '((a 1) (b 2) (c 3))) |
| @@ -396,7 +396,7 @@ | |||
| 396 | x) | 396 | x) |
| 397 | 397 | ||
| 398 | (let ((x 1) (bytecomp-test-var 2) (y 3)) | 398 | (let ((x 1) (bytecomp-test-var 2) (y 3)) |
| 399 | (list x bytecomp-test-var (bytecomp-get-test-var) y)) | 399 | (list x bytecomp-test-var (bytecomp-test-get-var) y)) |
| 400 | 400 | ||
| 401 | (progn | 401 | (progn |
| 402 | (defvar d) | 402 | (defvar d) |
| @@ -430,69 +430,67 @@ | |||
| 430 | (list s x i)) | 430 | (list s x i)) |
| 431 | 431 | ||
| 432 | (let ((x 2)) | 432 | (let ((x 2)) |
| 433 | (list (or (bytecomp-identity 'a) (setq x 3)) x))) | 433 | (list (or (bytecomp-test-identity 'a) (setq x 3)) x)) |
| 434 | "List of expression for test. | ||
| 435 | Each element will be executed by interpreter and with | ||
| 436 | bytecompiled code, and their results compared.") | ||
| 437 | 434 | ||
| 438 | (defun bytecomp-check-1 (pat) | 435 | (let* ((x 1) |
| 439 | "Return non-nil if PAT is the same whether directly evalled or compiled." | 436 | (y (condition-case x |
| 440 | (let ((warning-minimum-log-level :emergency) | 437 | (/ 1 0) |
| 441 | (byte-compile-warnings nil) | 438 | (arith-error x)))) |
| 442 | (v0 (condition-case err | 439 | (list x y)) |
| 443 | (eval pat) | 440 | |
| 444 | (error (list 'bytecomp-check-error (car err))))) | 441 | (funcall |
| 445 | (v1 (condition-case err | 442 | (condition-case x |
| 446 | (funcall (byte-compile (list 'lambda nil pat))) | 443 | (/ 1 0) |
| 447 | (error (list 'bytecomp-check-error (car err)))))) | 444 | (arith-error (prog1 (lambda (y) (+ y x)) |
| 448 | (equal v0 v1))) | 445 | (setq x 10)))) |
| 449 | 446 | 4) | |
| 450 | (put 'bytecomp-check-1 'ert-explainer 'bytecomp-explain-1) | 447 | ) |
| 451 | 448 | "List of expressions for cross-testing interpreted and compiled code.") | |
| 452 | (defun bytecomp-explain-1 (pat) | 449 | |
| 453 | (let ((v0 (condition-case err | 450 | (defconst bytecomp-tests--test-cases-lexbind-only |
| 454 | (eval pat) | 451 | `( |
| 455 | (error (list 'bytecomp-check-error (car err))))) | 452 | ;; This would infloop (and exhaust stack) with dynamic binding. |
| 456 | (v1 (condition-case err | 453 | (let ((f #'car)) |
| 457 | (funcall (byte-compile (list 'lambda nil pat))) | 454 | (let ((f (lambda (x) (cons (funcall f x) (cdr x))))) |
| 458 | (error (list 'bytecomp-check-error (car err)))))) | 455 | (funcall f '(1 . 2)))) |
| 459 | (format "Expression `%s' gives `%s' if directly evalled, `%s' if compiled." | 456 | ) |
| 460 | pat v0 v1))) | 457 | "List of expressions for cross-testing interpreted and compiled code. |
| 461 | 458 | These are only tested with lexical binding.") | |
| 462 | (ert-deftest bytecomp-tests () | 459 | |
| 463 | "Test the Emacs byte compiler." | 460 | (defun bytecomp-tests--eval-interpreted (form) |
| 464 | (dolist (pat byte-opt-testsuite-arith-data) | 461 | "Evaluate FORM using the Lisp interpreter, returning errors as a |
| 465 | (should (bytecomp-check-1 pat)))) | 462 | special value." |
| 466 | 463 | (condition-case err | |
| 467 | (defun test-byte-opt-arithmetic (&optional arg) | 464 | (eval form lexical-binding) |
| 468 | "Unit test for byte-opt arithmetic operations. | 465 | (error (list 'bytecomp-check-error (car err))))) |
| 469 | Subtests signal errors if something goes wrong." | 466 | |
| 470 | (interactive "P") | 467 | (defun bytecomp-tests--eval-compiled (form) |
| 471 | (switch-to-buffer (generate-new-buffer "*Font Pase Test*")) | 468 | "Evaluate FORM using the Lisp byte-code compiler, returning errors as a |
| 469 | special value." | ||
| 472 | (let ((warning-minimum-log-level :emergency) | 470 | (let ((warning-minimum-log-level :emergency) |
| 473 | (byte-compile-warnings nil) | 471 | (byte-compile-warnings nil)) |
| 474 | (pass-face '((t :foreground "green"))) | 472 | (condition-case err |
| 475 | (fail-face '((t :foreground "red"))) | 473 | (funcall (byte-compile (list 'lambda nil form))) |
| 476 | (print-escape-nonascii t) | 474 | (error (list 'bytecomp-check-error (car err)))))) |
| 477 | (print-escape-newlines t) | 475 | |
| 478 | (print-quoted t) | 476 | (ert-deftest bytecomp-tests-lexbind () |
| 479 | v0 v1) | 477 | "Check that various expressions behave the same when interpreted and |
| 480 | (dolist (pat byte-opt-testsuite-arith-data) | 478 | byte-compiled. Run with lexical binding." |
| 481 | (condition-case err | 479 | (let ((lexical-binding t)) |
| 482 | (setq v0 (eval pat)) | 480 | (dolist (form (append bytecomp-tests--test-cases-lexbind-only |
| 483 | (error (setq v0 (list 'bytecomp-check-error (car err))))) | 481 | bytecomp-tests--test-cases)) |
| 484 | (condition-case err | 482 | (ert-info ((prin1-to-string form) :prefix "form: ") |
| 485 | (setq v1 (funcall (byte-compile (list 'lambda nil pat)))) | 483 | (should (equal (bytecomp-tests--eval-interpreted form) |
| 486 | (error (setq v1 (list 'bytecomp-check-error (car err))))) | 484 | (bytecomp-tests--eval-compiled form))))))) |
| 487 | (insert (format "%s" pat)) | 485 | |
| 488 | (indent-to-column 65) | 486 | (ert-deftest bytecomp-tests-dynbind () |
| 489 | (if (equal v0 v1) | 487 | "Check that various expressions behave the same when interpreted and |
| 490 | (insert (propertize "OK" 'face pass-face)) | 488 | byte-compiled. Run with dynamic binding." |
| 491 | (insert (propertize "FAIL\n" 'face fail-face)) | 489 | (let ((lexical-binding nil)) |
| 492 | (indent-to-column 55) | 490 | (dolist (form bytecomp-tests--test-cases) |
| 493 | (insert (propertize (format "[%s] vs [%s]" v0 v1) | 491 | (ert-info ((prin1-to-string form) :prefix "form: ") |
| 494 | 'face fail-face))) | 492 | (should (equal (bytecomp-tests--eval-interpreted form) |
| 495 | (insert "\n")))) | 493 | (bytecomp-tests--eval-compiled form))))))) |
| 496 | 494 | ||
| 497 | (defun test-byte-comp-compile-and-load (compile &rest forms) | 495 | (defun test-byte-comp-compile-and-load (compile &rest forms) |
| 498 | (declare (indent 1)) | 496 | (declare (indent 1)) |
| @@ -584,8 +582,8 @@ Subtests signal errors if something goes wrong." | |||
| 584 | `(with-current-buffer (get-buffer-create "*Compile-Log*") | 582 | `(with-current-buffer (get-buffer-create "*Compile-Log*") |
| 585 | (let ((inhibit-read-only t)) (erase-buffer)) | 583 | (let ((inhibit-read-only t)) (erase-buffer)) |
| 586 | (byte-compile ,@form) | 584 | (byte-compile ,@form) |
| 587 | (ert-info ((buffer-string) :prefix "buffer: ") | 585 | (ert-info ((prin1-to-string (buffer-string)) :prefix "buffer: ") |
| 588 | (should (re-search-forward ,re-warning))))) | 586 | (should (re-search-forward ,(string-replace " " "[ \n]+" re-warning)))))) |
| 589 | 587 | ||
| 590 | (ert-deftest bytecomp-warn-wrong-args () | 588 | (ert-deftest bytecomp-warn-wrong-args () |
| 591 | (bytecomp--with-warning-test "remq.*3.*2" | 589 | (bytecomp--with-warning-test "remq.*3.*2" |
| @@ -611,12 +609,13 @@ Subtests signal errors if something goes wrong." | |||
| 611 | 609 | ||
| 612 | (defmacro bytecomp--define-warning-file-test (file re-warning &optional reverse) | 610 | (defmacro bytecomp--define-warning-file-test (file re-warning &optional reverse) |
| 613 | `(ert-deftest ,(intern (format "bytecomp/%s" file)) () | 611 | `(ert-deftest ,(intern (format "bytecomp/%s" file)) () |
| 614 | :expected-result ,(if reverse :failed :passed) | ||
| 615 | (with-current-buffer (get-buffer-create "*Compile-Log*") | 612 | (with-current-buffer (get-buffer-create "*Compile-Log*") |
| 616 | (let ((inhibit-read-only t)) (erase-buffer)) | 613 | (let ((inhibit-read-only t)) (erase-buffer)) |
| 617 | (byte-compile-file ,(ert-resource-file file)) | 614 | (byte-compile-file ,(ert-resource-file file)) |
| 618 | (ert-info ((buffer-string) :prefix "buffer: ") | 615 | (ert-info ((buffer-string) :prefix "buffer: ") |
| 619 | (should (re-search-forward ,re-warning)))))) | 616 | (,(if reverse 'should-not 'should) |
| 617 | (re-search-forward ,(string-replace " " "[ \n]+" re-warning) | ||
| 618 | nil t)))))) | ||
| 620 | 619 | ||
| 621 | (bytecomp--define-warning-file-test "error-lexical-var-with-add-hook.el" | 620 | (bytecomp--define-warning-file-test "error-lexical-var-with-add-hook.el" |
| 622 | "add-hook.*lexical var") | 621 | "add-hook.*lexical var") |
| @@ -658,10 +657,10 @@ Subtests signal errors if something goes wrong." | |||
| 658 | "free.*foo") | 657 | "free.*foo") |
| 659 | 658 | ||
| 660 | (bytecomp--define-warning-file-test "warn-free-variable-reference.el" | 659 | (bytecomp--define-warning-file-test "warn-free-variable-reference.el" |
| 661 | "free.*bar") | 660 | "free variable .bar") |
| 662 | 661 | ||
| 663 | (bytecomp--define-warning-file-test "warn-make-variable-buffer-local.el" | 662 | (bytecomp--define-warning-file-test "warn-make-variable-buffer-local.el" |
| 664 | "make-variable-buffer-local.*not called at toplevel") | 663 | "make-variable-buffer-local. not called at toplevel") |
| 665 | 664 | ||
| 666 | (bytecomp--define-warning-file-test "warn-interactive-only.el" | 665 | (bytecomp--define-warning-file-test "warn-interactive-only.el" |
| 667 | "next-line.*interactive use only.*forward-line") | 666 | "next-line.*interactive use only.*forward-line") |
| @@ -670,19 +669,19 @@ Subtests signal errors if something goes wrong." | |||
| 670 | "malformed interactive spec") | 669 | "malformed interactive spec") |
| 671 | 670 | ||
| 672 | (bytecomp--define-warning-file-test "warn-obsolete-defun.el" | 671 | (bytecomp--define-warning-file-test "warn-obsolete-defun.el" |
| 673 | "foo-obsolete.*obsolete function.*99.99") | 672 | "foo-obsolete. is an obsolete function (as of 99.99)") |
| 674 | 673 | ||
| 675 | (defvar bytecomp--tests-obsolete-var nil) | 674 | (defvar bytecomp--tests-obsolete-var nil) |
| 676 | (make-obsolete-variable 'bytecomp--tests-obsolete-var nil "99.99") | 675 | (make-obsolete-variable 'bytecomp--tests-obsolete-var nil "99.99") |
| 677 | 676 | ||
| 678 | (bytecomp--define-warning-file-test "warn-obsolete-hook.el" | 677 | (bytecomp--define-warning-file-test "warn-obsolete-hook.el" |
| 679 | "bytecomp--tests-obs.*obsolete[^z-a]*99.99") | 678 | "bytecomp--tests-obsolete-var. is an obsolete variable (as of 99.99)") |
| 680 | 679 | ||
| 681 | (bytecomp--define-warning-file-test "warn-obsolete-variable-same-file.el" | 680 | (bytecomp--define-warning-file-test "warn-obsolete-variable-same-file.el" |
| 682 | "foo-obs.*obsolete.*99.99" t) | 681 | "foo-obs.*obsolete.*99.99" t) |
| 683 | 682 | ||
| 684 | (bytecomp--define-warning-file-test "warn-obsolete-variable.el" | 683 | (bytecomp--define-warning-file-test "warn-obsolete-variable.el" |
| 685 | "bytecomp--tests-obs.*obsolete[^z-a]*99.99") | 684 | "bytecomp--tests-obsolete-var. is an obsolete variable (as of 99.99)") |
| 686 | 685 | ||
| 687 | (bytecomp--define-warning-file-test "warn-obsolete-variable-bound.el" | 686 | (bytecomp--define-warning-file-test "warn-obsolete-variable-bound.el" |
| 688 | "bytecomp--tests-obs.*obsolete.*99.99" t) | 687 | "bytecomp--tests-obs.*obsolete.*99.99" t) |
| @@ -713,64 +712,64 @@ Subtests signal errors if something goes wrong." | |||
| 713 | 712 | ||
| 714 | (bytecomp--define-warning-file-test | 713 | (bytecomp--define-warning-file-test |
| 715 | "warn-wide-docstring-autoload.el" | 714 | "warn-wide-docstring-autoload.el" |
| 716 | "autoload.*foox.*wider than.*characters") | 715 | "autoload .foox. docstring wider than .* characters") |
| 717 | 716 | ||
| 718 | (bytecomp--define-warning-file-test | 717 | (bytecomp--define-warning-file-test |
| 719 | "warn-wide-docstring-custom-declare-variable.el" | 718 | "warn-wide-docstring-custom-declare-variable.el" |
| 720 | "custom-declare-variable.*foo.*wider than.*characters") | 719 | "custom-declare-variable .foo. docstring wider than .* characters") |
| 721 | 720 | ||
| 722 | (bytecomp--define-warning-file-test | 721 | (bytecomp--define-warning-file-test |
| 723 | "warn-wide-docstring-defalias.el" | 722 | "warn-wide-docstring-defalias.el" |
| 724 | "defalias.*foo.*wider than.*characters") | 723 | "defalias .foo. docstring wider than .* characters") |
| 725 | 724 | ||
| 726 | (bytecomp--define-warning-file-test | 725 | (bytecomp--define-warning-file-test |
| 727 | "warn-wide-docstring-defconst.el" | 726 | "warn-wide-docstring-defconst.el" |
| 728 | "defconst.*foo.*wider than.*characters") | 727 | "defconst .foo-bar. docstring wider than .* characters") |
| 729 | 728 | ||
| 730 | (bytecomp--define-warning-file-test | 729 | (bytecomp--define-warning-file-test |
| 731 | "warn-wide-docstring-define-abbrev-table.el" | 730 | "warn-wide-docstring-define-abbrev-table.el" |
| 732 | "define-abbrev.*foo.*wider than.*characters") | 731 | "define-abbrev-table .foo. docstring wider than .* characters") |
| 733 | 732 | ||
| 734 | (bytecomp--define-warning-file-test | 733 | (bytecomp--define-warning-file-test |
| 735 | "warn-wide-docstring-define-obsolete-function-alias.el" | 734 | "warn-wide-docstring-define-obsolete-function-alias.el" |
| 736 | "defalias.*foo.*wider than.*characters") | 735 | "defalias .foo. docstring wider than .* characters") |
| 737 | 736 | ||
| 738 | (bytecomp--define-warning-file-test | 737 | (bytecomp--define-warning-file-test |
| 739 | "warn-wide-docstring-define-obsolete-variable-alias.el" | 738 | "warn-wide-docstring-define-obsolete-variable-alias.el" |
| 740 | "defvaralias.*foo.*wider than.*characters") | 739 | "defvaralias .foo. docstring wider than .* characters") |
| 741 | 740 | ||
| 742 | ;; TODO: We don't yet issue warnings for defuns. | 741 | ;; TODO: We don't yet issue warnings for defuns. |
| 743 | (bytecomp--define-warning-file-test | 742 | (bytecomp--define-warning-file-test |
| 744 | "warn-wide-docstring-defun.el" | 743 | "warn-wide-docstring-defun.el" |
| 745 | "wider than.*characters" 'reverse) | 744 | "wider than .* characters" 'reverse) |
| 746 | 745 | ||
| 747 | (bytecomp--define-warning-file-test | 746 | (bytecomp--define-warning-file-test |
| 748 | "warn-wide-docstring-defvar.el" | 747 | "warn-wide-docstring-defvar.el" |
| 749 | "defvar.*foo.*wider than.*characters") | 748 | "defvar .foo-bar. docstring wider than .* characters") |
| 750 | 749 | ||
| 751 | (bytecomp--define-warning-file-test | 750 | (bytecomp--define-warning-file-test |
| 752 | "warn-wide-docstring-defvaralias.el" | 751 | "warn-wide-docstring-defvaralias.el" |
| 753 | "defvaralias.*foo.*wider than.*characters") | 752 | "defvaralias .foo-bar. docstring wider than .* characters") |
| 754 | 753 | ||
| 755 | (bytecomp--define-warning-file-test | 754 | (bytecomp--define-warning-file-test |
| 756 | "warn-wide-docstring-ignore-fill-column.el" | 755 | "warn-wide-docstring-ignore-fill-column.el" |
| 757 | "defvar.*foo.*wider than.*characters" 'reverse) | 756 | "defvar .foo-bar. docstring wider than .* characters" 'reverse) |
| 758 | 757 | ||
| 759 | (bytecomp--define-warning-file-test | 758 | (bytecomp--define-warning-file-test |
| 760 | "warn-wide-docstring-ignore-override.el" | 759 | "warn-wide-docstring-ignore-override.el" |
| 761 | "defvar.*foo.*wider than.*characters" 'reverse) | 760 | "defvar .foo-bar. docstring wider than .* characters" 'reverse) |
| 762 | 761 | ||
| 763 | (bytecomp--define-warning-file-test | 762 | (bytecomp--define-warning-file-test |
| 764 | "warn-wide-docstring-ignore.el" | 763 | "warn-wide-docstring-ignore.el" |
| 765 | "defvar.*foo.*wider than.*characters" 'reverse) | 764 | "defvar .foo-bar. docstring wider than .* characters" 'reverse) |
| 766 | 765 | ||
| 767 | (bytecomp--define-warning-file-test | 766 | (bytecomp--define-warning-file-test |
| 768 | "warn-wide-docstring-multiline-first.el" | 767 | "warn-wide-docstring-multiline-first.el" |
| 769 | "defvar.*foo.*wider than.*characters") | 768 | "defvar .foo-bar. docstring wider than .* characters") |
| 770 | 769 | ||
| 771 | (bytecomp--define-warning-file-test | 770 | (bytecomp--define-warning-file-test |
| 772 | "warn-wide-docstring-multiline.el" | 771 | "warn-wide-docstring-multiline.el" |
| 773 | "defvar.*foo.*wider than.*characters") | 772 | "defvar .foo-bar. docstring wider than .* characters") |
| 774 | 773 | ||
| 775 | (bytecomp--define-warning-file-test | 774 | (bytecomp--define-warning-file-test |
| 776 | "nowarn-inline-after-defvar.el" | 775 | "nowarn-inline-after-defvar.el" |
| @@ -813,47 +812,6 @@ Subtests signal errors if something goes wrong." | |||
| 813 | (defun def () (m)))) | 812 | (defun def () (m)))) |
| 814 | (should (equal (funcall 'def) 4))) | 813 | (should (equal (funcall 'def) 4))) |
| 815 | 814 | ||
| 816 | (defconst bytecomp-lexbind-tests | ||
| 817 | `( | ||
| 818 | (let ((f #'car)) | ||
| 819 | (let ((f (lambda (x) (cons (funcall f x) (cdr x))))) | ||
| 820 | (funcall f '(1 . 2)))) | ||
| 821 | ) | ||
| 822 | "List of expression for test. | ||
| 823 | Each element will be executed by interpreter and with | ||
| 824 | bytecompiled code, and their results compared.") | ||
| 825 | |||
| 826 | (defun bytecomp-lexbind-check-1 (pat) | ||
| 827 | "Return non-nil if PAT is the same whether directly evalled or compiled." | ||
| 828 | (let ((warning-minimum-log-level :emergency) | ||
| 829 | (byte-compile-warnings nil) | ||
| 830 | (v0 (condition-case err | ||
| 831 | (eval pat t) | ||
| 832 | (error (list 'bytecomp-check-error (car err))))) | ||
| 833 | (v1 (condition-case err | ||
| 834 | (funcall (let ((lexical-binding t)) | ||
| 835 | (byte-compile `(lambda nil ,pat)))) | ||
| 836 | (error (list 'bytecomp-check-error (car err)))))) | ||
| 837 | (equal v0 v1))) | ||
| 838 | |||
| 839 | (put 'bytecomp-lexbind-check-1 'ert-explainer 'bytecomp-lexbind-explain-1) | ||
| 840 | |||
| 841 | (defun bytecomp-lexbind-explain-1 (pat) | ||
| 842 | (let ((v0 (condition-case err | ||
| 843 | (eval pat t) | ||
| 844 | (error (list 'bytecomp-check-error (car err))))) | ||
| 845 | (v1 (condition-case err | ||
| 846 | (funcall (let ((lexical-binding t)) | ||
| 847 | (byte-compile (list 'lambda nil pat)))) | ||
| 848 | (error (list 'bytecomp-check-error (car err)))))) | ||
| 849 | (format "Expression `%s' gives `%s' if directly evalled, `%s' if compiled." | ||
| 850 | pat v0 v1))) | ||
| 851 | |||
| 852 | (ert-deftest bytecomp-lexbind-tests () | ||
| 853 | "Test the Emacs byte compiler lexbind handling." | ||
| 854 | (dolist (pat bytecomp-lexbind-tests) | ||
| 855 | (should (bytecomp-lexbind-check-1 pat)))) | ||
| 856 | |||
| 857 | (defmacro bytecomp-tests--with-temp-file (file-name-var &rest body) | 815 | (defmacro bytecomp-tests--with-temp-file (file-name-var &rest body) |
| 858 | (declare (indent 1)) | 816 | (declare (indent 1)) |
| 859 | (cl-check-type file-name-var symbol) | 817 | (cl-check-type file-name-var symbol) |
diff --git a/test/lisp/emacs-lisp/cl-macs-tests.el b/test/lisp/emacs-lisp/cl-macs-tests.el index dd6487603d3..5c3e603b92e 100644 --- a/test/lisp/emacs-lisp/cl-macs-tests.el +++ b/test/lisp/emacs-lisp/cl-macs-tests.el | |||
| @@ -629,14 +629,24 @@ collection clause." | |||
| 629 | (let (n1) | 629 | (let (n1) |
| 630 | (and xs | 630 | (and xs |
| 631 | (progn (setq n1 (1+ n)) | 631 | (progn (setq n1 (1+ n)) |
| 632 | (len2 (cdr xs) n1))))))) | 632 | (len2 (cdr xs) n1)))))) |
| 633 | ;; Tail call in error handler. | ||
| 634 | (len3 (xs n) | ||
| 635 | (if xs | ||
| 636 | (condition-case nil | ||
| 637 | (/ 1 0) | ||
| 638 | (arith-error (len3 (cdr xs) (1+ n)))) | ||
| 639 | n))) | ||
| 633 | (should (equal (len nil 0) 0)) | 640 | (should (equal (len nil 0) 0)) |
| 634 | (should (equal (len2 nil 0) 0)) | 641 | (should (equal (len2 nil 0) 0)) |
| 642 | (should (equal (len3 nil 0) 0)) | ||
| 635 | (should (equal (len list-42 0) 42)) | 643 | (should (equal (len list-42 0) 42)) |
| 636 | (should (equal (len2 list-42 0) 42)) | 644 | (should (equal (len2 list-42 0) 42)) |
| 645 | (should (equal (len3 list-42 0) 42)) | ||
| 637 | ;; Should not bump into stack depth limits. | 646 | ;; Should not bump into stack depth limits. |
| 638 | (should (equal (len list-42k 0) 42000)) | 647 | (should (equal (len list-42k 0) 42000)) |
| 639 | (should (equal (len2 list-42k 0) 42000)))) | 648 | (should (equal (len2 list-42k 0) 42000)) |
| 649 | (should (equal (len3 list-42k 0) 42000)))) | ||
| 640 | 650 | ||
| 641 | ;; Check that non-recursive functions are handled more efficiently. | 651 | ;; Check that non-recursive functions are handled more efficiently. |
| 642 | (should (pcase (macroexpand '(cl-labels ((f (x) (+ x 1))) (f 5))) | 652 | (should (pcase (macroexpand '(cl-labels ((f (x) (+ x 1))) (f 5))) |
diff --git a/test/lisp/emacs-lisp/edebug-tests.el b/test/lisp/emacs-lisp/edebug-tests.el index dcb261c2eb9..7d45432e57e 100644 --- a/test/lisp/emacs-lisp/edebug-tests.el +++ b/test/lisp/emacs-lisp/edebug-tests.el | |||
| @@ -1061,5 +1061,30 @@ backtracking (Bug#42701)." | |||
| 1061 | "edebug-anon10001" | 1061 | "edebug-anon10001" |
| 1062 | "edebug-tests-duplicate-symbol-backtrack")))))) | 1062 | "edebug-tests-duplicate-symbol-backtrack")))))) |
| 1063 | 1063 | ||
| 1064 | (defmacro edebug-tests--duplicate-&define (_arg) | ||
| 1065 | "Helper macro for the ERT test `edebug-tests-duplicate-&define'. | ||
| 1066 | The Edebug specification is similar to the one used by `cl-flet' | ||
| 1067 | previously; see Bug#41988." | ||
| 1068 | (declare (debug (&or (&define name function-form) (defun))))) | ||
| 1069 | |||
| 1070 | (ert-deftest edebug-tests-duplicate-&define () | ||
| 1071 | "Check that Edebug doesn't backtrack out of `&define' forms. | ||
| 1072 | This avoids potential duplicate definitions (Bug#41988)." | ||
| 1073 | (with-temp-buffer | ||
| 1074 | (print '(defun edebug-tests-duplicate-&define () | ||
| 1075 | (edebug-tests--duplicate-&define | ||
| 1076 | (edebug-tests-duplicate-&define-inner () nil))) | ||
| 1077 | (current-buffer)) | ||
| 1078 | (let* ((edebug-all-defs t) | ||
| 1079 | (edebug-initial-mode 'Go-nonstop) | ||
| 1080 | (instrumented-names ()) | ||
| 1081 | (edebug-new-definition-function | ||
| 1082 | (lambda (name) | ||
| 1083 | (when (memq name instrumented-names) | ||
| 1084 | (error "Duplicate definition of `%s'" name)) | ||
| 1085 | (push name instrumented-names) | ||
| 1086 | (edebug-new-definition name)))) | ||
| 1087 | (should-error (eval-buffer) :type 'invalid-read-syntax)))) | ||
| 1088 | |||
| 1064 | (provide 'edebug-tests) | 1089 | (provide 'edebug-tests) |
| 1065 | ;;; edebug-tests.el ends here | 1090 | ;;; edebug-tests.el ends here |
diff --git a/test/lisp/loadhist-tests.el b/test/lisp/loadhist-tests.el new file mode 100644 index 00000000000..b29796da42d --- /dev/null +++ b/test/lisp/loadhist-tests.el | |||
| @@ -0,0 +1,57 @@ | |||
| 1 | ;;; loadhist-tests.el --- Tests for loadhist.el -*- lexical-binding:t -*- | ||
| 2 | |||
| 3 | ;; Copyright (C) 2021 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Stefan Kangas <stefankangas@gmail.com> | ||
| 6 | |||
| 7 | ;; This file is part of GNU Emacs. | ||
| 8 | |||
| 9 | ;; GNU Emacs is free software: you can redistribute it and/or modify | ||
| 10 | ;; it under the terms of the GNU General Public License as published by | ||
| 11 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 12 | ;; (at your option) any later version. | ||
| 13 | |||
| 14 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 15 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | ;; GNU General Public License for more details. | ||
| 18 | |||
| 19 | ;; You should have received a copy of the GNU General Public License | ||
| 20 | ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. | ||
| 21 | |||
| 22 | ;;; Commentary: | ||
| 23 | |||
| 24 | ;;; Code: | ||
| 25 | |||
| 26 | (require 'ert) | ||
| 27 | (require 'loadhist) | ||
| 28 | |||
| 29 | (ert-deftest loadhist-tests-feature-symbols () | ||
| 30 | (should (equal (file-name-base (car (feature-symbols 'loadhist))) "loadhist")) | ||
| 31 | (should-not (feature-symbols 'non-existent-feature))) | ||
| 32 | |||
| 33 | (ert-deftest loadhist-tests-feature-file () | ||
| 34 | (should (equal (file-name-base (feature-file 'loadhist)) "loadhist")) | ||
| 35 | (should-error (feature-file 'non-existent-feature))) | ||
| 36 | |||
| 37 | (ert-deftest loadhist-tests-file-loadhist-lookup () | ||
| 38 | ;; This should probably be extended... | ||
| 39 | (should (listp (file-loadhist-lookup "loadhist")))) | ||
| 40 | |||
| 41 | (ert-deftest loadhist-tests-file-provides () | ||
| 42 | (should (eq (car (file-provides "loadhist")) 'loadhist))) | ||
| 43 | |||
| 44 | (ert-deftest loadhist-tests-file-requires () | ||
| 45 | (should-not (file-requires "loadhist"))) | ||
| 46 | |||
| 47 | (ert-deftest loadhist-tests-file-dependents () | ||
| 48 | (require 'dired-x) | ||
| 49 | (let ((deps (file-dependents "dired"))) | ||
| 50 | (should (member "dired-x" (mapcar #'file-name-base deps))))) | ||
| 51 | |||
| 52 | (ert-deftest loadhist-tests-unload-feature () | ||
| 53 | (require 'dired-x) | ||
| 54 | (should-error (unload-feature 'dired)) | ||
| 55 | (unload-feature 'dired-x)) | ||
| 56 | |||
| 57 | ;;; loadhist-tests.el ends here | ||
diff --git a/test/lisp/shadowfile-tests.el b/test/lisp/shadowfile-tests.el index 0c2d7123dd7..7b9c2ff63b2 100644 --- a/test/lisp/shadowfile-tests.el +++ b/test/lisp/shadowfile-tests.el | |||
| @@ -117,8 +117,8 @@ | |||
| 117 | (ignore-errors (delete-file shadow-info-file)) | 117 | (ignore-errors (delete-file shadow-info-file)) |
| 118 | (ignore-errors (delete-file shadow-todo-file)) | 118 | (ignore-errors (delete-file shadow-todo-file)) |
| 119 | ;; Reset variables. | 119 | ;; Reset variables. |
| 120 | (shadow-invalidate-hashtable) | ||
| 120 | (setq shadow-info-buffer nil | 121 | (setq shadow-info-buffer nil |
| 121 | shadow-hashtable nil | ||
| 122 | shadow-todo-buffer nil | 122 | shadow-todo-buffer nil |
| 123 | shadow-files-to-copy nil)) | 123 | shadow-files-to-copy nil)) |
| 124 | 124 | ||
diff --git a/test/manual/indent/scheme.scm b/test/manual/indent/scheme.scm new file mode 100644 index 00000000000..9053a8743e4 --- /dev/null +++ b/test/manual/indent/scheme.scm | |||
| @@ -0,0 +1,23 @@ | |||
| 1 | ;; Testing sexp-comments | ||
| 2 | |||
| 3 | (define a #;(hello) there) | ||
| 4 | |||
| 5 | (define a #;1 there) | ||
| 6 | |||
| 7 | (define a #;"asdf" there) | ||
| 8 | |||
| 9 | (define a ;; #;(hello | ||
| 10 | there) | ||
| 11 | |||
| 12 | (define a #;(hello | ||
| 13 | there) 2) | ||
| 14 | |||
| 15 | (define a #;(hello | ||
| 16 | #;(world)) | ||
| 17 | and) | ||
| 18 | there) 2) | ||
| 19 | |||
| 20 | (define a #;(hello | ||
| 21 | #;"asdf" (world | ||
| 22 | and) | ||
| 23 | there) 2) | ||
diff --git a/test/src/emacs-resources/seccomp-filter-exec.bpf b/test/src/emacs-resources/seccomp-filter-exec.bpf new file mode 120000 index 00000000000..5b0e9978221 --- /dev/null +++ b/test/src/emacs-resources/seccomp-filter-exec.bpf | |||
| @@ -0,0 +1 @@ | |||
| ../../../lib-src/seccomp-filter-exec.bpf \ No newline at end of file | |||
diff --git a/test/src/emacs-resources/seccomp-filter.bpf b/test/src/emacs-resources/seccomp-filter.bpf new file mode 120000 index 00000000000..b3d603d0aeb --- /dev/null +++ b/test/src/emacs-resources/seccomp-filter.bpf | |||
| @@ -0,0 +1 @@ | |||
| ../../../lib-src/seccomp-filter.bpf \ No newline at end of file | |||
diff --git a/test/src/emacs-tests.el b/test/src/emacs-tests.el new file mode 100644 index 00000000000..09f9a248efb --- /dev/null +++ b/test/src/emacs-tests.el | |||
| @@ -0,0 +1,213 @@ | |||
| 1 | ;;; emacs-tests.el --- unit tests for emacs.c -*- lexical-binding: t; -*- | ||
| 2 | |||
| 3 | ;; Copyright (C) 2020 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; This file is part of GNU Emacs. | ||
| 6 | |||
| 7 | ;; GNU Emacs is free software: you can redistribute it and/or modify | ||
| 8 | ;; it under the terms of the GNU General Public License as published | ||
| 9 | ;; by the Free Software Foundation, either version 3 of the License, | ||
| 10 | ;; or (at your option) any later version. | ||
| 11 | |||
| 12 | ;; GNU Emacs is distributed in the hope that it will be useful, but | ||
| 13 | ;; WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | ;; General Public License for more details. | ||
| 16 | |||
| 17 | ;; You should have received a copy of the GNU General Public License | ||
| 18 | ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. | ||
| 19 | |||
| 20 | ;;; Commentary: | ||
| 21 | |||
| 22 | ;; Unit tests for src/emacs.c. | ||
| 23 | |||
| 24 | ;;; Code: | ||
| 25 | |||
| 26 | (require 'cl-lib) | ||
| 27 | (require 'ert) | ||
| 28 | (require 'ert-x) | ||
| 29 | (require 'rx) | ||
| 30 | (require 'subr-x) | ||
| 31 | |||
| 32 | (ert-deftest emacs-tests/seccomp/absent-file () | ||
| 33 | (skip-unless (string-match-p (rx bow "SECCOMP" eow) | ||
| 34 | system-configuration-features)) | ||
| 35 | (let ((emacs | ||
| 36 | (expand-file-name invocation-name invocation-directory)) | ||
| 37 | (process-environment nil)) | ||
| 38 | (skip-unless (file-executable-p emacs)) | ||
| 39 | (should-not (file-exists-p "/does-not-exist.bpf")) | ||
| 40 | (should-not | ||
| 41 | (eql (call-process emacs nil nil nil | ||
| 42 | "--quick" "--batch" | ||
| 43 | "--seccomp=/does-not-exist.bpf") | ||
| 44 | 0)))) | ||
| 45 | |||
| 46 | (cl-defmacro emacs-tests--with-temp-file | ||
| 47 | (var (prefix &optional suffix text) &rest body) | ||
| 48 | "Evaluate BODY while a new temporary file exists. | ||
| 49 | Bind VAR to the name of the file. Pass PREFIX, SUFFIX, and TEXT | ||
| 50 | to `make-temp-file', which see." | ||
| 51 | (declare (indent 2) (debug (symbolp (form form form) body))) | ||
| 52 | (cl-check-type var symbol) | ||
| 53 | ;; Use an uninterned symbol so that the code still works if BODY | ||
| 54 | ;; changes VAR. | ||
| 55 | (let ((filename (make-symbol "filename"))) | ||
| 56 | `(let ((,filename (make-temp-file ,prefix nil ,suffix ,text))) | ||
| 57 | (unwind-protect | ||
| 58 | (let ((,var ,filename)) | ||
| 59 | ,@body) | ||
| 60 | (delete-file ,filename))))) | ||
| 61 | |||
| 62 | (ert-deftest emacs-tests/seccomp/empty-file () | ||
| 63 | (skip-unless (string-match-p (rx bow "SECCOMP" eow) | ||
| 64 | system-configuration-features)) | ||
| 65 | (let ((emacs | ||
| 66 | (expand-file-name invocation-name invocation-directory)) | ||
| 67 | (process-environment nil)) | ||
| 68 | (skip-unless (file-executable-p emacs)) | ||
| 69 | (emacs-tests--with-temp-file filter ("seccomp-invalid-" ".bpf") | ||
| 70 | ;; The --seccomp option is processed early, without filename | ||
| 71 | ;; handlers. Therefore remote or quoted filenames wouldn't | ||
| 72 | ;; work. | ||
| 73 | (should-not (file-remote-p filter)) | ||
| 74 | (cl-callf file-name-unquote filter) | ||
| 75 | ;; According to the Seccomp man page, a filter must have at | ||
| 76 | ;; least one element, so Emacs should reject an empty file. | ||
| 77 | (should-not | ||
| 78 | (eql (call-process emacs nil nil nil | ||
| 79 | "--quick" "--batch" | ||
| 80 | (concat "--seccomp=" filter)) | ||
| 81 | 0))))) | ||
| 82 | |||
| 83 | (ert-deftest emacs-tests/seccomp/file-too-large () | ||
| 84 | (skip-unless (string-match-p (rx bow "SECCOMP" eow) | ||
| 85 | system-configuration-features)) | ||
| 86 | (let ((emacs | ||
| 87 | (expand-file-name invocation-name invocation-directory)) | ||
| 88 | (process-environment nil) | ||
| 89 | ;; This value should be correct on all supported systems. | ||
| 90 | (ushort-max #xFFFF) | ||
| 91 | ;; Either 8 or 16, but 16 should be large enough in all cases. | ||
| 92 | (filter-size 16)) | ||
| 93 | (skip-unless (file-executable-p emacs)) | ||
| 94 | (emacs-tests--with-temp-file | ||
| 95 | filter ("seccomp-too-large-" ".bpf" | ||
| 96 | (make-string (* (1+ ushort-max) filter-size) ?a)) | ||
| 97 | ;; The --seccomp option is processed early, without filename | ||
| 98 | ;; handlers. Therefore remote or quoted filenames wouldn't | ||
| 99 | ;; work. | ||
| 100 | (should-not (file-remote-p filter)) | ||
| 101 | (cl-callf file-name-unquote filter) | ||
| 102 | ;; The filter count must fit into an `unsigned short'. A bigger | ||
| 103 | ;; file should be rejected. | ||
| 104 | (should-not | ||
| 105 | (eql (call-process emacs nil nil nil | ||
| 106 | "--quick" "--batch" | ||
| 107 | (concat "--seccomp=" filter)) | ||
| 108 | 0))))) | ||
| 109 | |||
| 110 | (ert-deftest emacs-tests/seccomp/invalid-file-size () | ||
| 111 | (skip-unless (string-match-p (rx bow "SECCOMP" eow) | ||
| 112 | system-configuration-features)) | ||
| 113 | (let ((emacs | ||
| 114 | (expand-file-name invocation-name invocation-directory)) | ||
| 115 | (process-environment nil)) | ||
| 116 | (skip-unless (file-executable-p emacs)) | ||
| 117 | (emacs-tests--with-temp-file filter ("seccomp-invalid-" ".bpf" | ||
| 118 | "123456") | ||
| 119 | ;; The --seccomp option is processed early, without filename | ||
| 120 | ;; handlers. Therefore remote or quoted filenames wouldn't | ||
| 121 | ;; work. | ||
| 122 | (should-not (file-remote-p filter)) | ||
| 123 | (cl-callf file-name-unquote filter) | ||
| 124 | ;; The Seccomp filter file must have a file size that's a | ||
| 125 | ;; multiple of the size of struct sock_filter, which is 8 or 16, | ||
| 126 | ;; but never 6. | ||
| 127 | (should-not | ||
| 128 | (eql (call-process emacs nil nil nil | ||
| 129 | "--quick" "--batch" | ||
| 130 | (concat "--seccomp=" filter)) | ||
| 131 | 0))))) | ||
| 132 | |||
| 133 | (ert-deftest emacs-tests/seccomp/allows-stdout () | ||
| 134 | (skip-unless (string-match-p (rx bow "SECCOMP" eow) | ||
| 135 | system-configuration-features)) | ||
| 136 | (let ((emacs | ||
| 137 | (expand-file-name invocation-name invocation-directory)) | ||
| 138 | (filter (ert-resource-file "seccomp-filter.bpf")) | ||
| 139 | (process-environment nil)) | ||
| 140 | (skip-unless (file-executable-p emacs)) | ||
| 141 | (skip-unless (file-readable-p filter)) | ||
| 142 | ;; The --seccomp option is processed early, without filename | ||
| 143 | ;; handlers. Therefore remote or quoted filenames wouldn't work. | ||
| 144 | (should-not (file-remote-p filter)) | ||
| 145 | (cl-callf file-name-unquote filter) | ||
| 146 | (with-temp-buffer | ||
| 147 | (let ((status (call-process | ||
| 148 | emacs nil t nil | ||
| 149 | "--quick" "--batch" | ||
| 150 | (concat "--seccomp=" filter) | ||
| 151 | (format "--eval=%S" '(message "Hi"))))) | ||
| 152 | (ert-info ((format "Process output: %s" (buffer-string))) | ||
| 153 | (should (eql status 0))) | ||
| 154 | (should (equal (string-trim (buffer-string)) "Hi")))))) | ||
| 155 | |||
| 156 | (ert-deftest emacs-tests/seccomp/forbids-subprocess () | ||
| 157 | (skip-unless (string-match-p (rx bow "SECCOMP" eow) | ||
| 158 | system-configuration-features)) | ||
| 159 | (let ((emacs | ||
| 160 | (expand-file-name invocation-name invocation-directory)) | ||
| 161 | (filter (ert-resource-file "seccomp-filter.bpf")) | ||
| 162 | (process-environment nil)) | ||
| 163 | (skip-unless (file-executable-p emacs)) | ||
| 164 | (skip-unless (file-readable-p filter)) | ||
| 165 | ;; The --seccomp option is processed early, without filename | ||
| 166 | ;; handlers. Therefore remote or quoted filenames wouldn't work. | ||
| 167 | (should-not (file-remote-p filter)) | ||
| 168 | (cl-callf file-name-unquote filter) | ||
| 169 | (with-temp-buffer | ||
| 170 | (let ((status | ||
| 171 | (call-process | ||
| 172 | emacs nil t nil | ||
| 173 | "--quick" "--batch" | ||
| 174 | (concat "--seccomp=" filter) | ||
| 175 | (format "--eval=%S" `(call-process ,emacs nil nil nil | ||
| 176 | "--version"))))) | ||
| 177 | (ert-info ((format "Process output: %s" (buffer-string))) | ||
| 178 | (should-not (eql status 0))))))) | ||
| 179 | |||
| 180 | (ert-deftest emacs-tests/bwrap/allows-stdout () | ||
| 181 | (let ((bash (executable-find "bash")) | ||
| 182 | (bwrap (executable-find "bwrap")) | ||
| 183 | (emacs | ||
| 184 | (expand-file-name invocation-name invocation-directory)) | ||
| 185 | (filter (ert-resource-file "seccomp-filter-exec.bpf")) | ||
| 186 | (process-environment nil)) | ||
| 187 | (skip-unless bash) | ||
| 188 | (skip-unless bwrap) | ||
| 189 | (skip-unless (file-executable-p emacs)) | ||
| 190 | (skip-unless (file-readable-p filter)) | ||
| 191 | (should-not (file-remote-p bwrap)) | ||
| 192 | (should-not (file-remote-p emacs)) | ||
| 193 | (should-not (file-remote-p filter)) | ||
| 194 | (with-temp-buffer | ||
| 195 | (let* ((command | ||
| 196 | (concat | ||
| 197 | (mapconcat #'shell-quote-argument | ||
| 198 | `(,(file-name-unquote bwrap) | ||
| 199 | "--ro-bind" "/" "/" | ||
| 200 | "--seccomp" "20" | ||
| 201 | "--" | ||
| 202 | ,(file-name-unquote emacs) | ||
| 203 | "--quick" "--batch" | ||
| 204 | ,(format "--eval=%S" '(message "Hi"))) | ||
| 205 | " ") | ||
| 206 | " 20< " | ||
| 207 | (shell-quote-argument (file-name-unquote filter)))) | ||
| 208 | (status (call-process bash nil t nil "-c" command))) | ||
| 209 | (ert-info ((format "Process output: %s" (buffer-string))) | ||
| 210 | (should (eql status 0))) | ||
| 211 | (should (equal (string-trim (buffer-string)) "Hi")))))) | ||
| 212 | |||
| 213 | ;;; emacs-tests.el ends here | ||