Patchwork [1,of,2] run-tests: wrap failures in an XUnit 'failure' element

login
register
mail settings
Submitter Siddharth Agarwal
Date June 7, 2017, 10:47 p.m.
Message ID <0bdfd2f0e15b0d4a20ea.1496875637@devvm31800.prn1.facebook.com>
Download mbox | patch
Permalink /patch/21238/
State Accepted
Headers show

Comments

Siddharth Agarwal - June 7, 2017, 10:47 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1496875626 25200
#      Wed Jun 07 15:47:06 2017 -0700
# Node ID 0bdfd2f0e15b0d4a20ea4d288e0b4e04f37f25b4
# Parent  3210ffcae3d0b2c2a34b0485f7e20c4057ba6953
run-tests: wrap failures in an XUnit 'failure' element

This is closer to what most XUnit consumers can understand.
Yuya Nishihara - June 8, 2017, 2:41 p.m.
On Wed, 7 Jun 2017 15:47:17 -0700, Siddharth Agarwal wrote:
> # HG changeset patch
> # User Siddharth Agarwal <sid0@fb.com>
> # Date 1496875626 25200
> #      Wed Jun 07 15:47:06 2017 -0700
> # Node ID 0bdfd2f0e15b0d4a20ea4d288e0b4e04f37f25b4
> # Parent  3210ffcae3d0b2c2a34b0485f7e20c4057ba6953
> run-tests: wrap failures in an XUnit 'failure' element

Queued these, thanks.

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -2024,6 +2024,7 @@  class TextTestRunner(unittest.TextTestRu
 
     @staticmethod
     def _writexunit(result, outf):
+        # See http://llg.cubic.org/docs/junit/ for a reference.
         timesd = dict((t[0], t[3]) for t in result.times)
         doc = minidom.Document()
         s = doc.createElement('testsuite')
@@ -2052,7 +2053,13 @@  class TextTestRunner(unittest.TextTestRu
             # fail if string isn't ASCII.
             err = cdatasafe(err).decode('utf-8', 'replace')
             cd = doc.createCDATASection(err)
-            t.appendChild(cd)
+            # Use 'failure' here instead of 'error' to match errors = 0,
+            # failures = len(result.failures) in the testsuite element.
+            failelem = doc.createElement('failure')
+            failelem.setAttribute('message', 'output changed')
+            failelem.setAttribute('type', 'output-mismatch')
+            failelem.appendChild(cd)
+            t.appendChild(failelem)
             s.appendChild(t)
         outf.write(doc.toprettyxml(indent='  ', encoding='utf-8'))
 
diff --git a/tests/test-run-tests.t b/tests/test-run-tests.t
--- a/tests/test-run-tests.t
+++ b/tests/test-run-tests.t
@@ -200,14 +200,17 @@  test --xunit support
   <testsuite errors="0" failures="2" name="run-tests" skipped="0" tests="3">
     <testcase name="test-success.t" time="*"/> (glob)
     <testcase name="test-failure-unicode.t" time="*"> (glob)
+      <failure message="output changed" type="output-mismatch">
   <![CDATA[--- $TESTTMP/test-failure-unicode.t
   +++ $TESTTMP/test-failure-unicode.t.err
   @@ -1,2 +1,2 @@
      $ echo babar\xce\xb1 (esc)
   -  l\xce\xb5\xce\xb5t (esc)
   +  babar\xce\xb1 (esc)
-  ]]>  </testcase>
+  ]]>    </failure>
+    </testcase>
     <testcase name="test-failure.t" time="*"> (glob)
+      <failure message="output changed" type="output-mismatch">
   <![CDATA[--- $TESTTMP/test-failure.t
   +++ $TESTTMP/test-failure.t.err
   @@ -1,5 +1,5 @@
@@ -217,7 +220,8 @@  test --xunit support
    This is a noop statement so that
    this test is still more bytes than success.
    pad pad pad pad............................................................
-  ]]>  </testcase>
+  ]]>    </failure>
+    </testcase>
   </testsuite>
 
   $ cat .testtimes