diff options
| author | Laurence Warne | 2022-12-08 13:39:00 +0000 |
|---|---|---|
| committer | Eli Zaretskii | 2022-12-14 16:34:39 +0200 |
| commit | e22a71443ac854ef58dbfdc6d2ee11969ff30607 (patch) | |
| tree | 1f2a6200dd2579fa21e13b5fc4a95423f8bcaa26 /test | |
| parent | 7b8f3e00dd0ff1083f22d07b7ce3ecc3b5a6a032 (diff) | |
| download | emacs-e22a71443ac854ef58dbfdc6d2ee11969ff30607.tar.gz emacs-e22a71443ac854ef58dbfdc6d2ee11969ff30607.zip | |
Add tests for proced
* test/lisp/proced-tests.el: New file.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/proced-tests.el | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/test/lisp/proced-tests.el b/test/lisp/proced-tests.el new file mode 100644 index 00000000000..78d1b6aa400 --- /dev/null +++ b/test/lisp/proced-tests.el | |||
| @@ -0,0 +1,109 @@ | |||
| 1 | ;;; proced-tests.el --- Test suite for proced.el -*- lexical-binding: t -*- | ||
| 2 | |||
| 3 | ;; Copyright (C) 2022 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 'proced) | ||
| 23 | |||
| 24 | (cl-defmacro proced--within-buffer (format filter &body body) | ||
| 25 | "Execute BODY within a proced buffer using format FORMAT and filter FILTER." | ||
| 26 | `(let ((proced-format ,format) | ||
| 27 | (proced-filter ,filter) | ||
| 28 | (proced-auto-update-flag nil) | ||
| 29 | (inhibit-message t)) | ||
| 30 | (proced) | ||
| 31 | (unwind-protect | ||
| 32 | (with-current-buffer "*Proced*" | ||
| 33 | ,@body) | ||
| 34 | (kill-buffer "*Proced*")))) | ||
| 35 | |||
| 36 | (defun proced--assert-emacs-pid-in-buffer () | ||
| 37 | "Fail unless the process ID of the current Emacs process exists in buffer." | ||
| 38 | (should (string-match-p | ||
| 39 | (number-to-string (emacs-pid)) | ||
| 40 | (buffer-substring-no-properties (point-min) (point-max))))) | ||
| 41 | |||
| 42 | (defun proced--move-to-column (attribute) | ||
| 43 | "Move to the column under ATTRIBUTE in the current proced buffer." | ||
| 44 | (move-to-column (string-match attribute proced-header-line))) | ||
| 45 | |||
| 46 | (ert-deftest proced-format-test () | ||
| 47 | (skip-unless (memq system-type '(gnu/linux gnu/kfreebsd darwin))) | ||
| 48 | (dolist (format '(short medium long verbose)) | ||
| 49 | (proced--within-buffer | ||
| 50 | format | ||
| 51 | 'user | ||
| 52 | (proced--assert-emacs-pid-in-buffer)))) | ||
| 53 | |||
| 54 | (ert-deftest proced-update-test () | ||
| 55 | (skip-unless (memq system-type '(gnu/linux gnu/kfreebsd darwin))) | ||
| 56 | (proced--within-buffer | ||
| 57 | 'short | ||
| 58 | 'user | ||
| 59 | (proced-update) | ||
| 60 | (proced--assert-emacs-pid-in-buffer))) | ||
| 61 | |||
| 62 | (ert-deftest proced-revert-test () | ||
| 63 | (skip-unless (memq system-type '(gnu/linux gnu/kfreebsd darwin))) | ||
| 64 | (proced--within-buffer | ||
| 65 | 'short | ||
| 66 | 'user | ||
| 67 | (proced-revert) | ||
| 68 | (proced--assert-emacs-pid-in-buffer))) | ||
| 69 | |||
| 70 | (ert-deftest proced-color-test () | ||
| 71 | (skip-unless (memq system-type '(gnu/linux gnu/kfreebsd darwin))) | ||
| 72 | (let ((proced-enable-color-flag t)) | ||
| 73 | (proced--within-buffer | ||
| 74 | 'short | ||
| 75 | 'user | ||
| 76 | (proced--assert-emacs-pid-in-buffer)))) | ||
| 77 | |||
| 78 | (ert-deftest proced-refine-test () | ||
| 79 | (skip-unless (memq system-type '(gnu/linux gnu/kfreebsd darwin))) | ||
| 80 | (proced--within-buffer | ||
| 81 | 'medium | ||
| 82 | 'user | ||
| 83 | ;; When refining on Args for process A, a process is kept if and only | ||
| 84 | ;; if its args are the same as process A, which more or less guarentees | ||
| 85 | ;; the refinement will remove some processes. | ||
| 86 | (proced--move-to-column "Args") | ||
| 87 | (let ((args (buffer-substring-no-properties (point) (line-end-position)))) | ||
| 88 | (proced-refine) | ||
| 89 | (while (not (eobp)) | ||
| 90 | (proced--move-to-column "Args") | ||
| 91 | (should (string= args (buffer-substring-no-properties (point) (line-end-position)))) | ||
| 92 | (forward-line))))) | ||
| 93 | |||
| 94 | (ert-deftest proced-refine-with-update-test () | ||
| 95 | (skip-unless (memq system-type '(gnu/linux gnu/kfreebsd darwin))) | ||
| 96 | (proced--within-buffer | ||
| 97 | 'medium | ||
| 98 | 'user | ||
| 99 | (proced--move-to-column "Args") | ||
| 100 | (let ((args (buffer-substring-no-properties (point) (line-end-position)))) | ||
| 101 | (proced-refine) | ||
| 102 | (proced-update t) | ||
| 103 | (while (not (eobp)) | ||
| 104 | (proced--move-to-column "Args") | ||
| 105 | (should (string= args (buffer-substring-no-properties (point) (line-end-position)))) | ||
| 106 | (forward-line))))) | ||
| 107 | |||
| 108 | (provide 'proced-tests) | ||
| 109 | ;;; proced-tests.el ends here | ||