OSDN Git Service

[LIT] Handle xml characters in test names
authorChris Matthews <cmatthews5@apple.com>
Wed, 9 May 2018 23:48:32 +0000 (23:48 +0000)
committerChris Matthews <cmatthews5@apple.com>
Wed, 9 May 2018 23:48:32 +0000 (23:48 +0000)
Lit creates malformed xml when the test case has an & in the name.

Escape those correctly.

This also adds a test case which I will add other nasty encoding issues to in some followup commits.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331942 91177308-0d34-0410-b5e6-96231b3b80d8

utils/lit/lit/Test.py
utils/lit/tests/test-output.py
utils/lit/tests/xunit-output.py

index 46b8248..d87906c 100644 (file)
@@ -361,7 +361,7 @@ class Test:
         return self.suite.config.is_early
 
     def getJUnitXML(self):
-        test_name = self.path_in_suite[-1]
+        test_name = escape(self.path_in_suite[-1])
         test_path = self.path_in_suite[:-1]
         safe_test_path = [x.replace(".","_") for x in test_path]
         safe_name = self.suite.name.replace(".","-")
index a504427..073c838 100644 (file)
 # CHECK-NEXT:       "value0": 1,
 # CHECK-NEXT:       "value1": 2.3456
 # CHECK-NEXT:     }
+# CHECK-NEXT:     "name": "test-data :: bad&name.ini",
+# CHECK-NEXT:     "output": "& < > \""
+# CHECK-NEXT:   },
+# CHECK-NEXT:   {
+# CHECK-NEXT:     "code": "PASS",
+# CHECK-NEXT:     "elapsed": {{[0-9.]+}},
+# CHECK-NEXT:     "metrics": {
+# CHECK-NEXT:       "value0": 1,
+# CHECK-NEXT:       "value1": 2.3456
+# CHECK-NEXT:     }
 # CHECK-NEXT:     "name": "test-data :: metrics.ini",
 # CHECK-NEXT:     "output": "Test passed."
 # CHECK-NEXT:   }
+
 # CHECK-NEXT: ]
 # CHECK-NEXT: }
index 5368990..396f10e 100644 (file)
@@ -4,7 +4,8 @@
 
 # CHECK: <?xml version="1.0" encoding="UTF-8" ?>
 # CHECK: <testsuites>
-# CHECK: <testsuite name='test-data' tests='1' failures='0'>
+# CHECK: <testsuite name='test-data' tests='2' failures='0'>
+# CHECK: <testcase classname='test-data.test-data' name='bad&amp;name.ini' time='{{[0-1]}}.{{[0-9]+}}'/>
 # CHECK: <testcase classname='test-data.test-data' name='metrics.ini' time='{{[0-1]}}.{{[0-9]+}}'/>
 # CHECK: </testsuite>
 # CHECK: </testsuites>