Don't error in Proced tests if %CPU is a NaN
* test/lisp/proced-tests.el (proced--cpu-at-point): New function. (proced--assert-process-valid-cpu-refinement) (proced-refine-test, proced-refine-with-update-test): If %CPU for any process visited is a NaN skip the test. (proced-update-preserves-pid-at-point-test): Fix typo in comment. (proced--assert-process-valid-cpu-refinement-explainer): Add process attributes to the explainer along with tweaking how the process %CPU is obtained to account for circumstances where it's not numeric (most notably '-nan').
This commit is contained in:
parent
c29c54410e
commit
926d47ab2c
1 changed files with 18 additions and 6 deletions
|
@ -35,6 +35,15 @@
|
|||
,@body)
|
||||
(kill-buffer "*Proced*"))))
|
||||
|
||||
(defun proced--cpu-at-point ()
|
||||
"Return as an integer the current CPU value at point."
|
||||
(if (string-suffix-p "nan" (thing-at-point 'sexp))
|
||||
(let ((pid (proced-pid-at-point)))
|
||||
(ert-skip
|
||||
(format
|
||||
"Found NaN value for %%CPU at point for process with PID %d" pid)))
|
||||
(thing-at-point 'number)))
|
||||
|
||||
(defun proced--assert-emacs-pid-in-buffer ()
|
||||
"Fail unless the process ID of the current Emacs process exists in buffer."
|
||||
(should (string-match-p
|
||||
|
@ -51,7 +60,7 @@
|
|||
"Fail unless the process at point could be present after a refinement using CPU."
|
||||
(proced--move-to-column "%CPU")
|
||||
(condition-case err
|
||||
(>= (thing-at-point 'number) cpu)
|
||||
(>= (proced--cpu-at-point) cpu)
|
||||
(error
|
||||
(ert-fail
|
||||
(list err (proced--assert-process-valid-cpu-refinement-explainer cpu))))))
|
||||
|
@ -64,11 +73,14 @@ CPU is as in `proced--assert-process-valid-cpu-refinement'."
|
|||
(header-line
|
||||
,(substring-no-properties
|
||||
(string-replace "%%" "%" (cadr (proced-header-line)))))
|
||||
(process ,(thing-at-point 'line t))
|
||||
(buffer-process-line ,(thing-at-point 'line t))
|
||||
(process-attributes ,(format "%s" (process-attributes (proced-pid-at-point))))
|
||||
(refined-value ,cpu)
|
||||
(process-value
|
||||
,(save-excursion
|
||||
(proced--move-to-column "%CPU") (thing-at-point 'number)))))
|
||||
(proced--move-to-column "%CPU")
|
||||
(or (thing-at-point 'number)
|
||||
(substring-no-properties (thing-at-point 'sexp)))))))
|
||||
|
||||
(put #'proced--assert-process-valid-cpu-refinement 'ert-explainer
|
||||
#'proced--assert-process-valid-cpu-refinement-explainer)
|
||||
|
@ -108,7 +120,7 @@ CPU is as in `proced--assert-process-valid-cpu-refinement'."
|
|||
;; When refining on %CPU for process A, a process is kept if and only
|
||||
;; if its %CPU is greater than or equal to that of process A.
|
||||
(proced--move-to-column "%CPU")
|
||||
(let ((cpu (thing-at-point 'number)))
|
||||
(let ((cpu (proced--cpu-at-point)))
|
||||
(proced-refine)
|
||||
(while (not (eobp))
|
||||
(should (proced--assert-process-valid-cpu-refinement cpu))
|
||||
|
@ -119,7 +131,7 @@ CPU is as in `proced--assert-process-valid-cpu-refinement'."
|
|||
'verbose
|
||||
'user
|
||||
(proced--move-to-column "%CPU")
|
||||
(let ((cpu (thing-at-point 'number)))
|
||||
(let ((cpu (proced--cpu-at-point)))
|
||||
(proced-refine)
|
||||
;; Don't use (proced-update t) since this will reset `proced-process-alist'
|
||||
;; and it's possible the process refined on would have exited by that
|
||||
|
@ -132,7 +144,7 @@ CPU is as in `proced--assert-process-valid-cpu-refinement'."
|
|||
|
||||
(ert-deftest proced-update-preserves-pid-at-point-test ()
|
||||
;; FIXME: Occasionally the cursor inexplicably changes to the first line which
|
||||
;; causes the test to file when the line isn't the Emacs process.
|
||||
;; causes the test to fail when the line isn't the Emacs process.
|
||||
:tags '(:unstable)
|
||||
(proced--within-buffer
|
||||
'medium
|
||||
|
|
Loading…
Add table
Reference in a new issue