From e6c185f280e2c330825beebad7d2393c21199564 Mon Sep 17 00:00:00 2001 From: Phillip Lord Date: Wed, 27 Jan 2016 20:59:50 +0000 Subject: [PATCH] Add source information to ERT batch mode * lisp/emacs-lisp/ert.el (ert-test-location): New function. (ert-run-tests-batch): Add test location to failed tests. (Bug#22471) --- lisp/emacs-lisp/ert.el | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/lisp/emacs-lisp/ert.el b/lisp/emacs-lisp/ert.el index 57655403c2..36f5062e83 100644 --- a/lisp/emacs-lisp/ert.el +++ b/lisp/emacs-lisp/ert.el @@ -1353,6 +1353,23 @@ ert--insert-infos (defvar ert-quiet nil "Non-nil makes ERT only print important information in batch mode.") +(defun ert-test-location (test) + "Return a string description the source location of TEST." + (let* ((loc + (find-definition-noselect (ert-test-name test) 'ert-deftest)) + (buffer + (car loc)) + (point (cdr loc)) + (file + (file-relative-name + (buffer-file-name buffer))) + (line (with-current-buffer buffer + (line-number-at-pos point)))) + (format "at %s line %s." file line))) + +(defvar ert-batch-backtrace-right-margin 70 + "The maximum line length for printing backtraces in `ert-run-tests-batch'.") + ;;;###autoload (defun ert-run-tests-batch (&optional selector) "Run the tests specified by SELECTOR, printing results to the terminal. @@ -1471,14 +1488,17 @@ ert-run-tests-batch (let* ((max (prin1-to-string (length (ert--stats-tests stats)))) (format-string (concat "%9s %" (prin1-to-string (length max)) - "s/" max " %S (%f sec)"))) + "s/" max " %S (%f sec)%s"))) (message format-string (ert-string-for-test-result result (ert-test-result-expected-p test result)) (1+ (ert--stats-test-pos stats test)) (ert-test-name test) - (ert-test-result-duration result)))))))) + (ert-test-result-duration result) + (if (ert-test-result-expected-p test result) + "" + (concat " " (ert-test-location test)))))))))) nil)) ;;;###autoload -- 2.30.2