diff options
| author | Julian Scheid | 2021-06-15 17:01:49 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2021-06-15 17:01:57 +0200 |
| commit | 8be9d4a1568c34aed753b085d5d33daef5dfa797 (patch) | |
| tree | b2c3d84d4dcdc1fc6274f4ccb45c90f72eddfd34 | |
| parent | 81fd5603ce701a0acae096314c1f7ab1db69c64f (diff) | |
| download | emacs-8be9d4a1568c34aed753b085d5d33daef5dfa797.tar.gz emacs-8be9d4a1568c34aed753b085d5d33daef5dfa797.zip | |
Allow ERT tests to output the failure reasons, too
* lisp/emacs-lisp/ert.el (ert-reason-for-test-result): New function.
(ert-run-tests-batch): Output failure or skip reason (bug#47071).
| -rw-r--r-- | doc/misc/ert.texi | 4 | ||||
| -rw-r--r-- | etc/NEWS | 7 | ||||
| -rw-r--r-- | lisp/emacs-lisp/ert.el | 31 |
3 files changed, 38 insertions, 4 deletions
diff --git a/doc/misc/ert.texi b/doc/misc/ert.texi index a4e2cb506a3..fafdb8c4eb4 100644 --- a/doc/misc/ert.texi +++ b/doc/misc/ert.texi | |||
| @@ -347,6 +347,10 @@ emacs -batch -l ert -l my-tests.el \ | |||
| 347 | -eval '(ert-run-tests-batch-and-exit "to-match")' | 347 | -eval '(ert-run-tests-batch-and-exit "to-match")' |
| 348 | @end example | 348 | @end example |
| 349 | 349 | ||
| 350 | By default, ERT test failure summaries are quite brief in batch | ||
| 351 | mode--only the names of the failed tests are listed. If the | ||
| 352 | EMACS_TEST_VERBOSE environment variable is set, the failure summaries | ||
| 353 | will also include the data from the failing test. | ||
| 350 | 354 | ||
| 351 | @node Test Selectors | 355 | @node Test Selectors |
| 352 | @section Test Selectors | 356 | @section Test Selectors |
| @@ -2090,6 +2090,13 @@ This allows mode-specific alterations to how 'thing-at-point' works. | |||
| 2090 | This is so 'C-a' works as in other modes, and in particular holding | 2090 | This is so 'C-a' works as in other modes, and in particular holding |
| 2091 | Shift while typing 'C-a', i.e. 'C-S-a', will now highlight the text. | 2091 | Shift while typing 'C-a', i.e. 'C-S-a', will now highlight the text. |
| 2092 | 2092 | ||
| 2093 | ** ERT | ||
| 2094 | |||
| 2095 | +++ | ||
| 2096 | *** ERT can now output more verbose test failure reports. | ||
| 2097 | If the EMACS_TEST_VERBOSE environment variable is set, failure | ||
| 2098 | summaries will include the failing condition. | ||
| 2099 | |||
| 2093 | ** Miscellaneous | 2100 | ** Miscellaneous |
| 2094 | 2101 | ||
| 2095 | +++ | 2102 | +++ |
diff --git a/lisp/emacs-lisp/ert.el b/lisp/emacs-lisp/ert.el index e91ec0af443..6793b374eea 100644 --- a/lisp/emacs-lisp/ert.el +++ b/lisp/emacs-lisp/ert.el | |||
| @@ -1279,6 +1279,23 @@ EXPECTEDP specifies whether the result was expected." | |||
| 1279 | (ert-test-quit '("quit" "QUIT"))))) | 1279 | (ert-test-quit '("quit" "QUIT"))))) |
| 1280 | (elt s (if expectedp 0 1)))) | 1280 | (elt s (if expectedp 0 1)))) |
| 1281 | 1281 | ||
| 1282 | (defun ert-reason-for-test-result (result) | ||
| 1283 | "Return the reason given for RESULT, as a string. | ||
| 1284 | |||
| 1285 | The reason is the argument given when invoking `ert-fail' or `ert-skip'. | ||
| 1286 | It is output using `prin1' prefixed by two spaces. | ||
| 1287 | |||
| 1288 | If no reason was given, or for a successful RESULT, return the | ||
| 1289 | empty string." | ||
| 1290 | (let ((reason | ||
| 1291 | (and | ||
| 1292 | (ert-test-result-with-condition-p result) | ||
| 1293 | (cadr (ert-test-result-with-condition-condition result)))) | ||
| 1294 | (print-escape-newlines t) | ||
| 1295 | (print-level 6) | ||
| 1296 | (print-length 10)) | ||
| 1297 | (if reason (format " %S" reason) ""))) | ||
| 1298 | |||
| 1282 | (defun ert--pp-with-indentation-and-newline (object) | 1299 | (defun ert--pp-with-indentation-and-newline (object) |
| 1283 | "Pretty-print OBJECT, indenting it to the current column of point. | 1300 | "Pretty-print OBJECT, indenting it to the current column of point. |
| 1284 | Ensures a final newline is inserted." | 1301 | Ensures a final newline is inserted." |
| @@ -1369,18 +1386,24 @@ Returns the stats object." | |||
| 1369 | (cl-loop for test across (ert--stats-tests stats) | 1386 | (cl-loop for test across (ert--stats-tests stats) |
| 1370 | for result = (ert-test-most-recent-result test) do | 1387 | for result = (ert-test-most-recent-result test) do |
| 1371 | (when (not (ert-test-result-expected-p test result)) | 1388 | (when (not (ert-test-result-expected-p test result)) |
| 1372 | (message "%9s %S" | 1389 | (message "%9s %S%s" |
| 1373 | (ert-string-for-test-result result nil) | 1390 | (ert-string-for-test-result result nil) |
| 1374 | (ert-test-name test)))) | 1391 | (ert-test-name test) |
| 1392 | (if (getenv "EMACS_TEST_VERBOSE") | ||
| 1393 | (ert-reason-for-test-result result) | ||
| 1394 | "")))) | ||
| 1375 | (message "%s" "")) | 1395 | (message "%s" "")) |
| 1376 | (unless (zerop skipped) | 1396 | (unless (zerop skipped) |
| 1377 | (message "%s skipped results:" skipped) | 1397 | (message "%s skipped results:" skipped) |
| 1378 | (cl-loop for test across (ert--stats-tests stats) | 1398 | (cl-loop for test across (ert--stats-tests stats) |
| 1379 | for result = (ert-test-most-recent-result test) do | 1399 | for result = (ert-test-most-recent-result test) do |
| 1380 | (when (ert-test-result-type-p result :skipped) | 1400 | (when (ert-test-result-type-p result :skipped) |
| 1381 | (message "%9s %S" | 1401 | (message "%9s %S%s" |
| 1382 | (ert-string-for-test-result result nil) | 1402 | (ert-string-for-test-result result nil) |
| 1383 | (ert-test-name test)))) | 1403 | (ert-test-name test) |
| 1404 | (if (getenv "EMACS_TEST_VERBOSE") | ||
| 1405 | (ert-reason-for-test-result result) | ||
| 1406 | "")))) | ||
| 1384 | (message "%s" ""))))) | 1407 | (message "%s" ""))))) |
| 1385 | (test-started | 1408 | (test-started |
| 1386 | ) | 1409 | ) |