]> git.eshelyaron.com Git - emacs.git/commitdiff
Add source information to ERT batch mode. feature/parsable-ert-output
authorPhillip Lord <phillip.lord@russet.org.uk>
Wed, 27 Jan 2016 20:59:50 +0000 (20:59 +0000)
committerPhillip Lord <phillip.lord@russet.org.uk>
Wed, 27 Jan 2016 20:59:50 +0000 (20:59 +0000)
* lisp/emacs-lisp/ert.el (ert-test-location): New function.
  (ert-run-tests-batch): Add test location.

lisp/emacs-lisp/ert.el

index 7a914da3977b207a4d13f71a95bd5075fef6c11a..0b6848fa42b9a1cf1f0286041032ed63953db3b5 100644 (file)
@@ -1330,6 +1330,20 @@ RESULT must be an `ert-test-result-with-condition'."
 
 ;;; Running tests 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'.")
 
@@ -1435,13 +1449,14 @@ Returns the stats object."
           (let* ((max (prin1-to-string (length (ert--stats-tests stats))))
                  (format-string (concat "%9s  %"
                                         (prin1-to-string (length max))
-                                        "s/" max "  %S")))
+                                        "s/" max "  %S %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-name test)
+                     (ert-test-location test)))))))))
 
 ;;;###autoload
 (defun ert-run-tests-batch-and-exit (&optional selector)