Add an ERT explainer for 'time-equal-p'.
* lisp/emacs-lisp/ert.el (ert--explain-time-equal-p): New explainer function. * test/lisp/emacs-lisp/ert-tests.el (ert-test-explain-time-equal-p): New test.
This commit is contained in:
parent
cf6d0b48d8
commit
8be7e98557
2 changed files with 21 additions and 0 deletions
|
@ -669,6 +669,19 @@ Return nil if they are."
|
|||
(put 'equal-including-properties 'ert-explainer
|
||||
'ert--explain-equal-including-properties)
|
||||
|
||||
(defun ert--explain-time-equal-p (a b)
|
||||
"Explainer function for `time-equal-p'.
|
||||
A and B are the time values to compare."
|
||||
(declare (ftype (function (t t) list))
|
||||
(side-effect-free t))
|
||||
(unless (time-equal-p a b)
|
||||
`(different-time-values
|
||||
,(format-time-string "%F %T.%N %Z" a t)
|
||||
,(format-time-string "%F %T.%N %Z" b t)
|
||||
difference
|
||||
,(format-time-string "%s.%N" (time-subtract a b) t))))
|
||||
(function-put #'time-equal-p 'ert-explainer #'ert--explain-time-equal-p)
|
||||
|
||||
;;; Implementation of `ert-info'.
|
||||
|
||||
;; TODO(ohler): The name `info' clashes with
|
||||
|
|
|
@ -792,6 +792,14 @@ This macro is used to test if macroexpansion in `should' works."
|
|||
'(char 1 "o" (different-properties-for-key a (different-atoms b foo))
|
||||
context-before "f" context-after "o"))))
|
||||
|
||||
(ert-deftest ert-test-explain-time-equal-p ()
|
||||
(should-not (ert--explain-time-equal-p 123 '(0 123 0 0)))
|
||||
(should (equal (ert--explain-time-equal-p 123 '(0 120 0 0))
|
||||
'(different-time-values
|
||||
"1970-01-01 00:02:03.000000000 UTC"
|
||||
"1970-01-01 00:02:00.000000000 UTC"
|
||||
difference "3.000000000"))))
|
||||
|
||||
(ert-deftest ert-test-stats-set-test-and-result ()
|
||||
(let* ((test-1 (make-ert-test :name 'test-1
|
||||
:body (lambda () nil)))
|
||||
|
|
Loading…
Add table
Reference in a new issue