diff options
author | Paul J. Davis <paul.joseph.davis@gmail.com> | 2020-01-09 11:12:03 -0600 |
---|---|---|
committer | Paul J. Davis <paul.joseph.davis@gmail.com> | 2020-01-09 12:51:18 -0600 |
commit | 8dd8988760a09ccd78d84e987b127ed5f9e14433 (patch) | |
tree | fedc70b8de0022d0750ba2febf6cb6de773316d0 | |
parent | 9fd9d15254cc1b6d69431d47b0122e465caed2b1 (diff) | |
download | couchdb-8dd8988760a09ccd78d84e987b127ed5f9e14433.tar.gz |
Add a JUnit report to JavaScript tests
-rw-r--r-- | .gitignore | 1 | ||||
-rwxr-xr-x | test/javascript/run | 76 |
2 files changed, 73 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore index 9406d9b50..5eec70f3e 100644 --- a/.gitignore +++ b/.gitignore @@ -111,6 +111,7 @@ src/global_changes/ebin/ src/mango/ebin/ src/mango/test/*.pyc src/mango/venv/ +test/javascript/junit.xml /_build/ /src/bunt diff --git a/test/javascript/run b/test/javascript/run index a465a7b68..761fa456b 100755 --- a/test/javascript/run +++ b/test/javascript/run @@ -17,7 +17,9 @@ import optparse as op import os import subprocess as sp import sys +import time import re +import xml.dom.minidom as md USAGE = "%prog [options] [command to run...]" @@ -83,16 +85,66 @@ def run_couchjs(test, fmt): + SCRIPTS + [test, RUNNER] ) - p = sp.Popen(cmd, stdin=sp.PIPE, stdout=sp.PIPE, stderr=sys.stderr) + p = sp.Popen(cmd, stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.STDOUT) + output = [] while True: line = p.stdout.readline() if not line: break line = line.decode() + output.append(line) sys.stderr.write(line) p.wait() fmt(p.returncode) - return p.returncode + return (p.returncode, "".join(output)) + + +def write_junit(filename, total_time, results): + failures = 0 + skipped = 0 + for (_, rc, _, _) in results: + if rc == 2 or rc == 3: + skipped += 1 + else: + failures += 1 + + doc = md.Document() + root = doc.createElement("testsuite") + root.setAttribute("name", "JavaScript tests") + root.setAttribute("time", "%0.3f" % total_time) + root.setAttribute("tests", str(len(results))) + root.setAttribute("failures", str(failures)) + root.setAttribute("errors", "0") + root.setAttribute("skipped", str(skipped)) + doc.appendChild(root) + + for (path, rc, output, test_time) in results: + sys.stderr.write("WHUT? %r\n" % output) + name = os.path.split(path)[-1] + tc = doc.createElement("testcase") + tc.setAttribute("name", name) + tc.setAttribute("time", "%0.3f" % test_time) + if rc == 0: + pass + elif rc == 2: + skipped = doc.createElement("skipped") + skipped.setAttribute("message", "disabled") + tc.appendChild(skipped) + elif rc == 3: + skipped = doc.createElement("skipped") + skipped.setAttribute("message", "ported to elixir") + tc.appendChild(skipped) + else: + failure = doc.createElement("failure") + failure.setAttribute("message", "failed: %d" % rc) + failure_text = "Exit Code: %d" % rc + "\n\n" + output + message = doc.createTextNode(failure_text) + failure.appendChild(message) + tc.appendChild(failure) + root.appendChild(tc) + + with open(filename, "w") as handle: + doc.writexml(handle, addindent=" ", newl=os.linesep) def options(): @@ -102,7 +154,7 @@ def options(): "--start", metavar="FILENAME", default=None, - help="Start from the given filename if multiple files " "are passed", + help="Start from the given filename if multiple files are passed", ), op.make_option( "-a", @@ -139,6 +191,14 @@ def options(): dest="test_path", help="Path where the tests are located", ), + op.make_option( + "-j", + "--junit-report", + type="string", + default="test/javascript/junit.xml", + dest="junit_report", + help="Write a JUnit compatible test report", + ), ] @@ -162,12 +222,16 @@ def main(): tmp.append(name) tests = tmp + results = [] + begin = time.time() passed = 0 failed = 0 if len(tests) > 0: fmt = mkformatter(tests) for test in tests: - result = run_couchjs(test, fmt) + tbefore = time.time() + (result, output) = run_couchjs(test, fmt) + results.append((test, result, output, time.time() - tbefore)) if result == 0 or result == 2 or result == 3: passed += 1 else: @@ -175,6 +239,10 @@ def main(): if not opts.all: break + total_time = time.time() - begin + if opts.junit_report: + write_junit(opts.junit_report, total_time, results) + sys.stderr.write( "=======================================================" + os.linesep ) |