diff options
| author | Andrea Corallo | 2021-01-24 21:05:33 +0100 |
|---|---|---|
| committer | Andrea Corallo | 2021-01-24 21:05:33 +0100 |
| commit | b8d3ae78c54db7c7bb65d367a80f9be3d8744c48 (patch) | |
| tree | 982f190d1dd79685c43a9829dd66e6a7cbbd0c67 /test/src | |
| parent | 0ffb3dfaa483b0c5cf1f7f367efcb5e9c041ab53 (diff) | |
| parent | e5aaa1251cfb9d6d18682a5eda137a2e12ca4213 (diff) | |
| download | emacs-b8d3ae78c54db7c7bb65d367a80f9be3d8744c48.tar.gz emacs-b8d3ae78c54db7c7bb65d367a80f9be3d8744c48.zip | |
Merge remote-tracking branch 'savannah/master' into native-comp
Diffstat (limited to 'test/src')
| -rw-r--r-- | test/src/process-tests.el | 150 | ||||
| -rw-r--r-- | test/src/xdisp-tests.el | 33 |
2 files changed, 160 insertions, 23 deletions
diff --git a/test/src/process-tests.el b/test/src/process-tests.el index 57097cfa052..a3fba8d328b 100644 --- a/test/src/process-tests.el +++ b/test/src/process-tests.el | |||
| @@ -576,11 +576,6 @@ FD_SETSIZE file descriptors (Bug#24325)." | |||
| 576 | (should (memq (process-status process) '(run exit))) | 576 | (should (memq (process-status process) '(run exit))) |
| 577 | (when (process-live-p process) | 577 | (when (process-live-p process) |
| 578 | (process-send-eof process)) | 578 | (process-send-eof process)) |
| 579 | ;; FIXME: This `sleep-for' shouldn't be needed. It | ||
| 580 | ;; indicates a bug in Emacs; perhaps SIGCHLD is | ||
| 581 | ;; received in parallel with `accept-process-output', | ||
| 582 | ;; causing the latter to hang. | ||
| 583 | (sleep-for 0.1) | ||
| 584 | (while (accept-process-output process)) | 579 | (while (accept-process-output process)) |
| 585 | (should (eq (process-status process) 'exit)) | 580 | (should (eq (process-status process) 'exit)) |
| 586 | ;; If there's an error between fork and exec, Emacs | 581 | ;; If there's an error between fork and exec, Emacs |
| @@ -739,5 +734,150 @@ Return nil if that can't be determined." | |||
| 739 | (match-string-no-properties 1)))))) | 734 | (match-string-no-properties 1)))))) |
| 740 | process-tests--EMFILE-message) | 735 | process-tests--EMFILE-message) |
| 741 | 736 | ||
| 737 | (ert-deftest process-tests/sentinel-called () | ||
| 738 | "Check that sentinels are called after processes finish" | ||
| 739 | (let ((command (process-tests--emacs-command))) | ||
| 740 | (skip-unless command) | ||
| 741 | (dolist (conn-type '(pipe pty)) | ||
| 742 | (ert-info ((format "Connection type: %s" conn-type)) | ||
| 743 | (process-tests--with-processes processes | ||
| 744 | (let* ((calls ()) | ||
| 745 | (process (make-process | ||
| 746 | :name "echo" | ||
| 747 | :command (process-tests--eval | ||
| 748 | command '(print "first")) | ||
| 749 | :noquery t | ||
| 750 | :connection-type conn-type | ||
| 751 | :coding 'utf-8-unix | ||
| 752 | :sentinel (lambda (process message) | ||
| 753 | (push (list process message) | ||
| 754 | calls))))) | ||
| 755 | (push process processes) | ||
| 756 | (while (accept-process-output process)) | ||
| 757 | (should (equal calls | ||
| 758 | (list (list process "finished\n")))))))))) | ||
| 759 | |||
| 760 | (ert-deftest process-tests/sentinel-with-multiple-processes () | ||
| 761 | "Check that sentinels are called in time even when other processes | ||
| 762 | have written output." | ||
| 763 | (let ((command (process-tests--emacs-command))) | ||
| 764 | (skip-unless command) | ||
| 765 | (dolist (conn-type '(pipe pty)) | ||
| 766 | (ert-info ((format "Connection type: %s" conn-type)) | ||
| 767 | (process-tests--with-processes processes | ||
| 768 | (let* ((calls ()) | ||
| 769 | (process (make-process | ||
| 770 | :name "echo" | ||
| 771 | :command (process-tests--eval | ||
| 772 | command '(print "first")) | ||
| 773 | :noquery t | ||
| 774 | :connection-type conn-type | ||
| 775 | :coding 'utf-8-unix | ||
| 776 | :sentinel (lambda (process message) | ||
| 777 | (push (list process message) | ||
| 778 | calls))))) | ||
| 779 | (push process processes) | ||
| 780 | (push (make-process | ||
| 781 | :name "bash" | ||
| 782 | :command (process-tests--eval | ||
| 783 | command | ||
| 784 | '(progn (sleep-for 10) (print "second"))) | ||
| 785 | :noquery t | ||
| 786 | :connection-type conn-type) | ||
| 787 | processes) | ||
| 788 | (while (accept-process-output process)) | ||
| 789 | (should (equal calls | ||
| 790 | (list (list process "finished\n")))))))))) | ||
| 791 | |||
| 792 | (ert-deftest process-tests/multiple-threads-waiting () | ||
| 793 | (skip-unless (fboundp 'make-thread)) | ||
| 794 | (with-timeout (60 (ert-fail "Test timed out")) | ||
| 795 | (process-tests--with-processes processes | ||
| 796 | (let ((threads ()) | ||
| 797 | (cat (executable-find "cat"))) | ||
| 798 | (skip-unless cat) | ||
| 799 | (dotimes (i 10) | ||
| 800 | (let* ((name (format "test %d" i)) | ||
| 801 | (process (make-process :name name | ||
| 802 | :command (list cat) | ||
| 803 | :coding 'no-conversion | ||
| 804 | :noquery t | ||
| 805 | :connection-type 'pipe))) | ||
| 806 | (push process processes) | ||
| 807 | (set-process-thread process nil) | ||
| 808 | (push (make-thread | ||
| 809 | (lambda () | ||
| 810 | (while (accept-process-output process))) | ||
| 811 | name) | ||
| 812 | threads))) | ||
| 813 | (mapc #'process-send-eof processes) | ||
| 814 | (cl-loop for process in processes | ||
| 815 | and thread in threads | ||
| 816 | do | ||
| 817 | (should-not (thread-join thread)) | ||
| 818 | (should-not (thread-last-error)) | ||
| 819 | (should (eq (process-status process) 'exit)) | ||
| 820 | (should (eql (process-exit-status process) 0))))))) | ||
| 821 | |||
| 822 | (defun process-tests--eval (command form) | ||
| 823 | "Return a command that evaluates FORM in an Emacs subprocess. | ||
| 824 | COMMAND must be a list returned by | ||
| 825 | `process-tests--emacs-command'." | ||
| 826 | (let ((print-gensym t) | ||
| 827 | (print-circle t) | ||
| 828 | (print-length nil) | ||
| 829 | (print-level nil) | ||
| 830 | (print-escape-control-characters t) | ||
| 831 | (print-escape-newlines t) | ||
| 832 | (print-escape-multibyte t) | ||
| 833 | (print-escape-nonascii t)) | ||
| 834 | `(,@command "--quick" "--batch" ,(format "--eval=%S" form)))) | ||
| 835 | |||
| 836 | (defun process-tests--emacs-command () | ||
| 837 | "Return a command to reinvoke the current Emacs instance. | ||
| 838 | Return nil if that doesn't appear to be possible." | ||
| 839 | (when-let ((binary (process-tests--emacs-binary)) | ||
| 840 | (dump (process-tests--dump-file))) | ||
| 841 | (cons binary | ||
| 842 | (unless (eq dump :not-needed) | ||
| 843 | (list (concat "--dump-file=" | ||
| 844 | (file-name-unquote dump))))))) | ||
| 845 | |||
| 846 | (defun process-tests--emacs-binary () | ||
| 847 | "Return the filename of the currently running Emacs binary. | ||
| 848 | Return nil if that can't be determined." | ||
| 849 | (and (stringp invocation-name) | ||
| 850 | (not (file-remote-p invocation-name)) | ||
| 851 | (not (file-name-absolute-p invocation-name)) | ||
| 852 | (stringp invocation-directory) | ||
| 853 | (not (file-remote-p invocation-directory)) | ||
| 854 | (file-name-absolute-p invocation-directory) | ||
| 855 | (when-let ((file (process-tests--usable-file-for-reinvoke | ||
| 856 | (expand-file-name invocation-name | ||
| 857 | invocation-directory)))) | ||
| 858 | (and (file-executable-p file) file)))) | ||
| 859 | |||
| 860 | (defun process-tests--dump-file () | ||
| 861 | "Return the filename of the dump file used to start Emacs. | ||
| 862 | Return nil if that can't be determined. Return `:not-needed' if | ||
| 863 | Emacs wasn't started with a dump file." | ||
| 864 | (if-let ((stats (and (fboundp 'pdumper-stats) (pdumper-stats)))) | ||
| 865 | (when-let ((file (process-tests--usable-file-for-reinvoke | ||
| 866 | (cdr (assq 'dump-file-name stats))))) | ||
| 867 | (and (file-readable-p file) file)) | ||
| 868 | :not-needed)) | ||
| 869 | |||
| 870 | (defun process-tests--usable-file-for-reinvoke (filename) | ||
| 871 | "Return a version of FILENAME that can be used to reinvoke Emacs. | ||
| 872 | Return nil if FILENAME doesn't exist." | ||
| 873 | (when (and (stringp filename) | ||
| 874 | (not (file-remote-p filename))) | ||
| 875 | (cl-callf file-truename filename) | ||
| 876 | (and (stringp filename) | ||
| 877 | (not (file-remote-p filename)) | ||
| 878 | (file-name-absolute-p filename) | ||
| 879 | (file-regular-p filename) | ||
| 880 | filename))) | ||
| 881 | |||
| 742 | (provide 'process-tests) | 882 | (provide 'process-tests) |
| 743 | ;;; process-tests.el ends here | 883 | ;;; process-tests.el ends here |
diff --git a/test/src/xdisp-tests.el b/test/src/xdisp-tests.el index ec96d777ffb..4e7d2ad8ab2 100644 --- a/test/src/xdisp-tests.el +++ b/test/src/xdisp-tests.el | |||
| @@ -75,31 +75,28 @@ | |||
| 75 | (ert-deftest xdisp-tests--window-text-pixel-size () ;; bug#45748 | 75 | (ert-deftest xdisp-tests--window-text-pixel-size () ;; bug#45748 |
| 76 | (with-temp-buffer | 76 | (with-temp-buffer |
| 77 | (insert "xxx") | 77 | (insert "xxx") |
| 78 | (let* ((window | 78 | (switch-to-buffer (current-buffer)) |
| 79 | (display-buffer (current-buffer) '(display-buffer-in-child-frame . nil))) | 79 | (let* ((char-width (frame-char-width)) |
| 80 | (char-width (frame-char-width)) | 80 | (size (window-text-pixel-size nil t t)) |
| 81 | (size (window-text-pixel-size nil t t))) | 81 | (width-in-chars (/ (car size) char-width))) |
| 82 | (delete-frame (window-frame window)) | 82 | (should (equal width-in-chars 3))))) |
| 83 | (should (equal (/ (car size) char-width) 3))))) | ||
| 84 | 83 | ||
| 85 | (ert-deftest xdisp-tests--window-text-pixel-size-leading-space () ;; bug#45748 | 84 | (ert-deftest xdisp-tests--window-text-pixel-size-leading-space () ;; bug#45748 |
| 86 | (with-temp-buffer | 85 | (with-temp-buffer |
| 87 | (insert " xx") | 86 | (insert " xx") |
| 88 | (let* ((window | 87 | (switch-to-buffer (current-buffer)) |
| 89 | (display-buffer (current-buffer) '(display-buffer-in-child-frame . nil))) | 88 | (let* ((char-width (frame-char-width)) |
| 90 | (char-width (frame-char-width)) | 89 | (size (window-text-pixel-size nil t t)) |
| 91 | (size (window-text-pixel-size nil t t))) | 90 | (width-in-chars (/ (car size) char-width))) |
| 92 | (delete-frame (window-frame window)) | 91 | (should (equal width-in-chars 3))))) |
| 93 | (should (equal (/ (car size) char-width) 3))))) | ||
| 94 | 92 | ||
| 95 | (ert-deftest xdisp-tests--window-text-pixel-size-trailing-space () ;; bug#45748 | 93 | (ert-deftest xdisp-tests--window-text-pixel-size-trailing-space () ;; bug#45748 |
| 96 | (with-temp-buffer | 94 | (with-temp-buffer |
| 97 | (insert "xx ") | 95 | (insert "xx ") |
| 98 | (let* ((window | 96 | (switch-to-buffer (current-buffer)) |
| 99 | (display-buffer (current-buffer) '(display-buffer-in-child-frame . nil))) | 97 | (let* ((char-width (frame-char-width)) |
| 100 | (char-width (frame-char-width)) | 98 | (size (window-text-pixel-size nil t t)) |
| 101 | (size (window-text-pixel-size nil t t))) | 99 | (width-in-chars (/ (car size) char-width))) |
| 102 | (delete-frame (window-frame window)) | 100 | (should (equal width-in-chars 3))))) |
| 103 | (should (equal (/ (car size) char-width) 3))))) | ||
| 104 | 101 | ||
| 105 | ;;; xdisp-tests.el ends here | 102 | ;;; xdisp-tests.el ends here |