Function: ert-write-junit-test-summary-report

ert-write-junit-test-summary-report is a byte-compiled function defined in ert.el.gz.

Signature

(ert-write-junit-test-summary-report &rest LOGFILES)

Documentation

Write a JUnit summary test report, generated from LOGFILES.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/ert.el.gz
(defun ert-write-junit-test-summary-report (&rest logfiles)
  "Write a JUnit summary test report, generated from LOGFILES."
  (let ((report (file-name-with-extension
                 (getenv "EMACS_TEST_JUNIT_REPORT") "xml"))
        (tests 0) (errors 0) (failures 0) (skipped 0) (time 0) (id 0))
    (with-temp-file report
      (dolist (logfile logfiles)
        (let ((test-report (file-name-with-extension logfile "xml")))
          (if (not (file-readable-p test-report))
              (let* ((logfile (file-name-with-extension logfile "log"))
                     (logfile-contents
                      (when (file-readable-p logfile)
                        (with-temp-buffer
                          (insert-file-contents-literally logfile)
                          (buffer-string)))))
                (unless
                    ;; No defined tests, perhaps a helper file.
                    (and logfile-contents
                         (string-match-p "^Running 0 tests" logfile-contents))
                  (insert (format "  <testsuite id=\"%s\" name=\"%s\" tests=\"1\" errors=\"1\" failures=\"0\" skipped=\"0\" time=\"0\" timestamp=\"%s\">\n"
                                  id test-report
				  (ert--format-time-iso8601 nil)))
                  (insert (format "    <testcase name=\"Test report missing %s\" status=\"error\" time=\"0\">\n"
                                  (file-name-nondirectory test-report)))
                  (insert (format "      <error message=\"Test report missing %s\" type=\"error\">\n"
                                  (file-name-nondirectory test-report)))
                  (when logfile-contents
                    (insert (xml-escape-string logfile-contents 'noerror)))
                  (insert "      </error>\n"
                          "    </testcase>\n"
                          "  </testsuite>\n")
                  (cl-incf errors 1)
                  (cl-incf id 1)))

            (insert-file-contents-literally test-report)
            (when (looking-at-p
                   (regexp-quote "<?xml version=\"1.0\" encoding=\"utf-8\"?>"))
              (delete-region (point) (line-beginning-position 2)))
            (when (looking-at
                   "<testsuites name=\".+\" tests=\"\\(.+\\)\" errors=\"\\(.+\\)\" failures=\"\\(.+\\)\" skipped=\"\\(.+\\)\" time=\"\\(.+\\)\">")
              (cl-incf tests (string-to-number (match-string 1)))
              (cl-incf errors  (string-to-number (match-string 2)))
              (cl-incf failures  (string-to-number (match-string 3)))
              (cl-incf skipped (string-to-number (match-string 4)))
              (cl-incf time (string-to-number (match-string 5)))
              (delete-region (point) (line-beginning-position 2)))
            (when (looking-at "  <testsuite id=\"\\(0\\)\"")
              (replace-match (number-to-string id) nil nil nil 1)
              (cl-incf id 1))
            (goto-char (point-max))
            (beginning-of-line 0)
            (when (looking-at-p "</testsuites>")
              (delete-region (point) (line-beginning-position 2))))

          (narrow-to-region (point-max) (point-max))))

      (insert "</testsuites>\n")
      (widen)
      (goto-char (point-min))
      (insert "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
      (insert (format "<testsuites name=\"%s\" tests=\"%s\" errors=\"%s\" failures=\"%s\" skipped=\"%s\" time=\"%s\">\n"
                      (file-name-nondirectory report)
                      tests errors failures skipped time)))))