aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2013-10-24 09:34:41 +0200
committerMichael Albinus2013-10-24 09:34:41 +0200
commit50b5b857412f310d69cac74ffe906837da6757c6 (patch)
tree52e647f8b4e202378e3b69981efcda53f5887cc5
parent9698f11c57f42777e67419816340b1d931ef7854 (diff)
downloademacs-50b5b857412f310d69cac74ffe906837da6757c6.tar.gz
emacs-50b5b857412f310d69cac74ffe906837da6757c6.zip
* emacs-lisp/ert.el (ert-deftest): Bind macro `skip-unless'.
(ert-test-skipped): New error. (ert-skip, ert-stats-skipped): New defuns. (ert--skip-unless): New macro. (ert-test-skipped): New struct. (ert--run-test-debugger, ert-test-result-type-p) (ert-test-result-expected-p, ert--stats, ert-stats-completed) (ert--stats-set-test-and-result, ert-char-for-test-result) (ert-string-for-test-result, ert-run-tests-batch) (ert--results-update-ewoc-hf, ert-run-tests-interactively): Handle skipped tests.
-rw-r--r--lisp/ChangeLog14
-rw-r--r--lisp/emacs-lisp/ert.el101
2 files changed, 94 insertions, 21 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index f69ec89b48d..587535e328e 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,17 @@
12013-10-24 Michael Albinus <michael.albinus@gmx.de>
2
3 * emacs-lisp/ert.el (ert-deftest): Bind macro `skip-unless'.
4 (ert-test-skipped): New error.
5 (ert-skip, ert-stats-skipped): New defuns.
6 (ert--skip-unless): New macro.
7 (ert-test-skipped): New struct.
8 (ert--run-test-debugger, ert-test-result-type-p)
9 (ert-test-result-expected-p, ert--stats, ert-stats-completed)
10 (ert--stats-set-test-and-result, ert-char-for-test-result)
11 (ert-string-for-test-result, ert-run-tests-batch)
12 (ert--results-update-ewoc-hf, ert-run-tests-interactively): Handle
13 skipped tests.
14
12013-10-24 Glenn Morris <rgm@gnu.org> 152013-10-24 Glenn Morris <rgm@gnu.org>
2 16
3 * Makefile.in (check-declare): Remove unnecessary path in -l argument. 17 * Makefile.in (check-declare): Remove unnecessary path in -l argument.
diff --git a/lisp/emacs-lisp/ert.el b/lisp/emacs-lisp/ert.el
index 409e4faf4d5..c63c5324c9f 100644
--- a/lisp/emacs-lisp/ert.el
+++ b/lisp/emacs-lisp/ert.el
@@ -34,14 +34,17 @@
34;; `ert-run-tests-batch-and-exit' for non-interactive use. 34;; `ert-run-tests-batch-and-exit' for non-interactive use.
35;; 35;;
36;; The body of `ert-deftest' forms resembles a function body, but the 36;; The body of `ert-deftest' forms resembles a function body, but the
37;; additional operators `should', `should-not' and `should-error' are 37;; additional operators `should', `should-not', `should-error' and
38;; available. `should' is similar to cl's `assert', but signals a 38;; `skip-unless' are available. `should' is similar to cl's `assert',
39;; different error when its condition is violated that is caught and 39;; but signals a different error when its condition is violated that
40;; processed by ERT. In addition, it analyzes its argument form and 40;; is caught and processed by ERT. In addition, it analyzes its
41;; records information that helps debugging (`assert' tries to do 41;; argument form and records information that helps debugging
42;; something similar when its second argument SHOW-ARGS is true, but 42;; (`assert' tries to do something similar when its second argument
43;; `should' is more sophisticated). For information on `should-not' 43;; SHOW-ARGS is true, but `should' is more sophisticated). For
44;; and `should-error', see their docstrings. 44;; information on `should-not' and `should-error', see their
45;; docstrings. `skip-unless' skips the test immediately without
46;; processing further, this is useful for checking the test
47;; environment (like availability of features, external binaries, etc).
45;; 48;;
46;; See ERT's info manual as well as the docstrings for more details. 49;; See ERT's info manual as well as the docstrings for more details.
47;; To compile the manual, run `makeinfo ert.texinfo' in the ERT 50;; To compile the manual, run `makeinfo ert.texinfo' in the ERT
@@ -174,8 +177,8 @@ and the body."
174BODY is evaluated as a `progn' when the test is run. It should 177BODY is evaluated as a `progn' when the test is run. It should
175signal a condition on failure or just return if the test passes. 178signal a condition on failure or just return if the test passes.
176 179
177`should', `should-not' and `should-error' are useful for 180`should', `should-not', `should-error' and `skip-unless' are
178assertions in BODY. 181useful for assertions in BODY.
179 182
180Use `ert' to run tests interactively. 183Use `ert' to run tests interactively.
181 184
@@ -200,7 +203,7 @@ description of valid values for RESULT-TYPE.
200 (tags nil tags-supplied-p)) 203 (tags nil tags-supplied-p))
201 body) 204 body)
202 (ert--parse-keys-and-body docstring-keys-and-body) 205 (ert--parse-keys-and-body docstring-keys-and-body)
203 `(progn 206 `(cl-macrolet ((skip-unless (form) `(ert--skip-unless ,form)))
204 (ert-set-test ',name 207 (ert-set-test ',name
205 (make-ert-test 208 (make-ert-test
206 :name ',name 209 :name ',name
@@ -237,6 +240,7 @@ description of valid values for RESULT-TYPE.
237 240
238 241
239(define-error 'ert-test-failed "Test failed") 242(define-error 'ert-test-failed "Test failed")
243(define-error 'ert-test-skipped "Test skipped")
240 244
241(defun ert-pass () 245(defun ert-pass ()
242 "Terminate the current test and mark it passed. Does not return." 246 "Terminate the current test and mark it passed. Does not return."
@@ -247,6 +251,11 @@ description of valid values for RESULT-TYPE.
247DATA is displayed to the user and should state the reason of the failure." 251DATA is displayed to the user and should state the reason of the failure."
248 (signal 'ert-test-failed (list data))) 252 (signal 'ert-test-failed (list data)))
249 253
254(defun ert-skip (data)
255 "Terminate the current test and mark it skipped. Does not return.
256DATA is displayed to the user and should state the reason for skipping."
257 (signal 'ert-test-skipped (list data)))
258
250 259
251;;; The `should' macros. 260;;; The `should' macros.
252 261
@@ -425,6 +434,15 @@ failed."
425 (list 434 (list
426 :fail-reason "did not signal an error"))))))))) 435 :fail-reason "did not signal an error")))))))))
427 436
437(cl-defmacro ert--skip-unless (form)
438 "Evaluate FORM. If it returns nil, skip the current test.
439Errors during evaluation are catched and handled like nil."
440 (declare (debug t))
441 (ert--expand-should `(skip-unless ,form) form
442 (lambda (inner-form form-description-form _value-var)
443 `(unless (ignore-errors ,inner-form)
444 (ert-skip ,form-description-form)))))
445
428 446
429;;; Explanation of `should' failures. 447;;; Explanation of `should' failures.
430 448
@@ -644,6 +662,7 @@ and is displayed in front of the value of MESSAGE-FORM."
644 (infos (cl-assert nil))) 662 (infos (cl-assert nil)))
645(cl-defstruct (ert-test-quit (:include ert-test-result-with-condition))) 663(cl-defstruct (ert-test-quit (:include ert-test-result-with-condition)))
646(cl-defstruct (ert-test-failed (:include ert-test-result-with-condition))) 664(cl-defstruct (ert-test-failed (:include ert-test-result-with-condition)))
665(cl-defstruct (ert-test-skipped (:include ert-test-result-with-condition)))
647(cl-defstruct (ert-test-aborted-with-non-local-exit 666(cl-defstruct (ert-test-aborted-with-non-local-exit
648 (:include ert-test-result))) 667 (:include ert-test-result)))
649 668
@@ -728,6 +747,7 @@ run. ARGS are the arguments to `debugger'."
728 (let* ((condition (car more-debugger-args)) 747 (let* ((condition (car more-debugger-args))
729 (type (cl-case (car condition) 748 (type (cl-case (car condition)
730 ((quit) 'quit) 749 ((quit) 'quit)
750 ((ert-test-skipped) 'skipped)
731 (otherwise 'failed))) 751 (otherwise 'failed)))
732 (backtrace (ert--record-backtrace)) 752 (backtrace (ert--record-backtrace))
733 (infos (reverse ert--infos))) 753 (infos (reverse ert--infos)))
@@ -737,6 +757,10 @@ run. ARGS are the arguments to `debugger'."
737 (make-ert-test-quit :condition condition 757 (make-ert-test-quit :condition condition
738 :backtrace backtrace 758 :backtrace backtrace
739 :infos infos)) 759 :infos infos))
760 (skipped
761 (make-ert-test-skipped :condition condition
762 :backtrace backtrace
763 :infos infos))
740 (failed 764 (failed
741 (make-ert-test-failed :condition condition 765 (make-ert-test-failed :condition condition
742 :backtrace backtrace 766 :backtrace backtrace
@@ -862,7 +886,7 @@ Valid result types:
862 886
863nil -- Never matches. 887nil -- Never matches.
864t -- Always matches. 888t -- Always matches.
865:failed, :passed -- Matches corresponding results. 889:failed, :passed, :skipped -- Matches corresponding results.
866\(and TYPES...\) -- Matches if all TYPES match. 890\(and TYPES...\) -- Matches if all TYPES match.
867\(or TYPES...\) -- Matches if some TYPES match. 891\(or TYPES...\) -- Matches if some TYPES match.
868\(not TYPE\) -- Matches if TYPE does not match. 892\(not TYPE\) -- Matches if TYPE does not match.
@@ -875,6 +899,7 @@ t -- Always matches.
875 ((member t) t) 899 ((member t) t)
876 ((member :failed) (ert-test-failed-p result)) 900 ((member :failed) (ert-test-failed-p result))
877 ((member :passed) (ert-test-passed-p result)) 901 ((member :passed) (ert-test-passed-p result))
902 ((member :skipped) (ert-test-skipped-p result))
878 (cons 903 (cons
879 (cl-destructuring-bind (operator &rest operands) result-type 904 (cl-destructuring-bind (operator &rest operands) result-type
880 (cl-ecase operator 905 (cl-ecase operator
@@ -899,7 +924,9 @@ t -- Always matches.
899 924
900(defun ert-test-result-expected-p (test result) 925(defun ert-test-result-expected-p (test result)
901 "Return non-nil if TEST's expected result type matches RESULT." 926 "Return non-nil if TEST's expected result type matches RESULT."
902 (ert-test-result-type-p result (ert-test-expected-result-type test))) 927 (or
928 (ert-test-result-type-p result :skipped)
929 (ert-test-result-type-p result (ert-test-expected-result-type test))))
903 930
904(defun ert-select-tests (selector universe) 931(defun ert-select-tests (selector universe)
905 "Return a list of tests that match SELECTOR. 932 "Return a list of tests that match SELECTOR.
@@ -1085,6 +1112,7 @@ contained in UNIVERSE."
1085 (passed-unexpected 0) 1112 (passed-unexpected 0)
1086 (failed-expected 0) 1113 (failed-expected 0)
1087 (failed-unexpected 0) 1114 (failed-unexpected 0)
1115 (skipped 0)
1088 (start-time nil) 1116 (start-time nil)
1089 (end-time nil) 1117 (end-time nil)
1090 (aborted-p nil) 1118 (aborted-p nil)
@@ -1103,10 +1131,15 @@ contained in UNIVERSE."
1103 (+ (ert--stats-passed-unexpected stats) 1131 (+ (ert--stats-passed-unexpected stats)
1104 (ert--stats-failed-unexpected stats))) 1132 (ert--stats-failed-unexpected stats)))
1105 1133
1134(defun ert-stats-skipped (stats)
1135 "Number of tests in STATS that have skipped."
1136 (ert--stats-skipped stats))
1137
1106(defun ert-stats-completed (stats) 1138(defun ert-stats-completed (stats)
1107 "Number of tests in STATS that have run so far." 1139 "Number of tests in STATS that have run so far."
1108 (+ (ert-stats-completed-expected stats) 1140 (+ (ert-stats-completed-expected stats)
1109 (ert-stats-completed-unexpected stats))) 1141 (ert-stats-completed-unexpected stats)
1142 (ert-stats-skipped stats)))
1110 1143
1111(defun ert-stats-total (stats) 1144(defun ert-stats-total (stats)
1112 "Number of tests in STATS, regardless of whether they have run yet." 1145 "Number of tests in STATS, regardless of whether they have run yet."
@@ -1138,6 +1171,8 @@ Also changes the counters in STATS to match."
1138 (cl-incf (ert--stats-passed-expected stats) d)) 1171 (cl-incf (ert--stats-passed-expected stats) d))
1139 (ert-test-failed 1172 (ert-test-failed
1140 (cl-incf (ert--stats-failed-expected stats) d)) 1173 (cl-incf (ert--stats-failed-expected stats) d))
1174 (ert-test-skipped
1175 (cl-incf (ert--stats-skipped stats) d))
1141 (null) 1176 (null)
1142 (ert-test-aborted-with-non-local-exit) 1177 (ert-test-aborted-with-non-local-exit)
1143 (ert-test-quit)) 1178 (ert-test-quit))
@@ -1146,6 +1181,8 @@ Also changes the counters in STATS to match."
1146 (cl-incf (ert--stats-passed-unexpected stats) d)) 1181 (cl-incf (ert--stats-passed-unexpected stats) d))
1147 (ert-test-failed 1182 (ert-test-failed
1148 (cl-incf (ert--stats-failed-unexpected stats) d)) 1183 (cl-incf (ert--stats-failed-unexpected stats) d))
1184 (ert-test-skipped
1185 (cl-incf (ert--stats-skipped stats) d))
1149 (null) 1186 (null)
1150 (ert-test-aborted-with-non-local-exit) 1187 (ert-test-aborted-with-non-local-exit)
1151 (ert-test-quit))))) 1188 (ert-test-quit)))))
@@ -1240,6 +1277,7 @@ EXPECTEDP specifies whether the result was expected."
1240 (let ((s (cl-etypecase result 1277 (let ((s (cl-etypecase result
1241 (ert-test-passed ".P") 1278 (ert-test-passed ".P")
1242 (ert-test-failed "fF") 1279 (ert-test-failed "fF")
1280 (ert-test-skipped "sS")
1243 (null "--") 1281 (null "--")
1244 (ert-test-aborted-with-non-local-exit "aA") 1282 (ert-test-aborted-with-non-local-exit "aA")
1245 (ert-test-quit "qQ")))) 1283 (ert-test-quit "qQ"))))
@@ -1252,6 +1290,7 @@ EXPECTEDP specifies whether the result was expected."
1252 (let ((s (cl-etypecase result 1290 (let ((s (cl-etypecase result
1253 (ert-test-passed '("passed" "PASSED")) 1291 (ert-test-passed '("passed" "PASSED"))
1254 (ert-test-failed '("failed" "FAILED")) 1292 (ert-test-failed '("failed" "FAILED"))
1293 (ert-test-skipped '("skipped" "SKIPPED"))
1255 (null '("unknown" "UNKNOWN")) 1294 (null '("unknown" "UNKNOWN"))
1256 (ert-test-aborted-with-non-local-exit '("aborted" "ABORTED")) 1295 (ert-test-aborted-with-non-local-exit '("aborted" "ABORTED"))
1257 (ert-test-quit '("quit" "QUIT"))))) 1296 (ert-test-quit '("quit" "QUIT")))))
@@ -1318,8 +1357,9 @@ Returns the stats object."
1318 (run-ended 1357 (run-ended
1319 (cl-destructuring-bind (stats abortedp) event-args 1358 (cl-destructuring-bind (stats abortedp) event-args
1320 (let ((unexpected (ert-stats-completed-unexpected stats)) 1359 (let ((unexpected (ert-stats-completed-unexpected stats))
1321 (expected-failures (ert--stats-failed-expected stats))) 1360 (skipped (ert-stats-skipped stats))
1322 (message "\n%sRan %s tests, %s results as expected%s (%s)%s\n" 1361 (expected-failures (ert--stats-failed-expected stats)))
1362 (message "\n%sRan %s tests, %s results as expected%s%s (%s)%s\n"
1323 (if (not abortedp) 1363 (if (not abortedp)
1324 "" 1364 ""
1325 "Aborted: ") 1365 "Aborted: ")
@@ -1328,6 +1368,9 @@ Returns the stats object."
1328 (if (zerop unexpected) 1368 (if (zerop unexpected)
1329 "" 1369 ""
1330 (format ", %s unexpected" unexpected)) 1370 (format ", %s unexpected" unexpected))
1371 (if (zerop skipped)
1372 ""
1373 (format ", %s skipped" skipped))
1331 (ert--format-time-iso8601 (ert--stats-end-time stats)) 1374 (ert--format-time-iso8601 (ert--stats-end-time stats))
1332 (if (zerop expected-failures) 1375 (if (zerop expected-failures)
1333 "" 1376 ""
@@ -1340,6 +1383,15 @@ Returns the stats object."
1340 (message "%9s %S" 1383 (message "%9s %S"
1341 (ert-string-for-test-result result nil) 1384 (ert-string-for-test-result result nil)
1342 (ert-test-name test)))) 1385 (ert-test-name test))))
1386 (message "%s" ""))
1387 (unless (zerop skipped)
1388 (message "%s skipped results:" skipped)
1389 (cl-loop for test across (ert--stats-tests stats)
1390 for result = (ert-test-most-recent-result test) do
1391 (when (ert-test-result-type-p result :skipped)
1392 (message "%9s %S"
1393 (ert-string-for-test-result result nil)
1394 (ert-test-name test))))
1343 (message "%s" ""))))) 1395 (message "%s" "")))))
1344 (test-started 1396 (test-started
1345 ) 1397 )
@@ -1562,15 +1614,17 @@ Also sets `ert--results-progress-bar-button-begin'."
1562 (ert--insert-human-readable-selector (ert--stats-selector stats)) 1614 (ert--insert-human-readable-selector (ert--stats-selector stats))
1563 (insert "\n") 1615 (insert "\n")
1564 (insert 1616 (insert
1565 (format (concat "Passed: %s\n" 1617 (format (concat "Passed: %s\n"
1566 "Failed: %s\n" 1618 "Failed: %s\n"
1567 "Total: %s/%s\n\n") 1619 "Skipped: %s\n"
1620 "Total: %s/%s\n\n")
1568 (ert--results-format-expected-unexpected 1621 (ert--results-format-expected-unexpected
1569 (ert--stats-passed-expected stats) 1622 (ert--stats-passed-expected stats)
1570 (ert--stats-passed-unexpected stats)) 1623 (ert--stats-passed-unexpected stats))
1571 (ert--results-format-expected-unexpected 1624 (ert--results-format-expected-unexpected
1572 (ert--stats-failed-expected stats) 1625 (ert--stats-failed-expected stats)
1573 (ert--stats-failed-unexpected stats)) 1626 (ert--stats-failed-unexpected stats))
1627 (ert-stats-skipped stats)
1574 run-count 1628 run-count
1575 (ert-stats-total stats))) 1629 (ert-stats-total stats)))
1576 (insert 1630 (insert
@@ -1850,7 +1904,7 @@ and how to display message."
1850 (run-ended 1904 (run-ended
1851 (cl-destructuring-bind (stats abortedp) event-args 1905 (cl-destructuring-bind (stats abortedp) event-args
1852 (funcall message-fn 1906 (funcall message-fn
1853 "%sRan %s tests, %s results were as expected%s" 1907 "%sRan %s tests, %s results were as expected%s%s"
1854 (if (not abortedp) 1908 (if (not abortedp)
1855 "" 1909 ""
1856 "Aborted: ") 1910 "Aborted: ")
@@ -1860,7 +1914,12 @@ and how to display message."
1860 (ert-stats-completed-unexpected stats))) 1914 (ert-stats-completed-unexpected stats)))
1861 (if (zerop unexpected) 1915 (if (zerop unexpected)
1862 "" 1916 ""
1863 (format ", %s unexpected" unexpected)))) 1917 (format ", %s unexpected" unexpected)))
1918 (let ((skipped
1919 (ert-stats-skipped stats)))
1920 (if (zerop skipped)
1921 ""
1922 (format ", %s skipped" skipped))))
1864 (ert--results-update-stats-display (with-current-buffer buffer 1923 (ert--results-update-stats-display (with-current-buffer buffer
1865 ert--results-ewoc) 1924 ert--results-ewoc)
1866 stats))) 1925 stats)))