gtest_xml_output_unittest.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. #!/usr/bin/env python
  2. #
  3. # Copyright 2006, Google Inc.
  4. # All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions are
  8. # met:
  9. #
  10. # * Redistributions of source code must retain the above copyright
  11. # notice, this list of conditions and the following disclaimer.
  12. # * Redistributions in binary form must reproduce the above
  13. # copyright notice, this list of conditions and the following disclaimer
  14. # in the documentation and/or other materials provided with the
  15. # distribution.
  16. # * Neither the name of Google Inc. nor the names of its
  17. # contributors may be used to endorse or promote products derived from
  18. # this software without specific prior written permission.
  19. #
  20. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. """Unit test for the gtest_xml_output module"""
  32. import datetime
  33. import errno
  34. import os
  35. import re
  36. import sys
  37. from xml.dom import minidom, Node
  38. import gtest_test_utils
  39. import gtest_xml_test_utils
  40. GTEST_FILTER_FLAG = '--gtest_filter'
  41. GTEST_LIST_TESTS_FLAG = '--gtest_list_tests'
  42. GTEST_OUTPUT_FLAG = '--gtest_output'
  43. GTEST_DEFAULT_OUTPUT_FILE = 'test_detail.xml'
  44. GTEST_PROGRAM_NAME = 'gtest_xml_output_unittest_'
  45. # The flag indicating stacktraces are not supported
  46. NO_STACKTRACE_SUPPORT_FLAG = '--no_stacktrace_support'
  47. # The environment variables for test sharding.
  48. TOTAL_SHARDS_ENV_VAR = 'GTEST_TOTAL_SHARDS'
  49. SHARD_INDEX_ENV_VAR = 'GTEST_SHARD_INDEX'
  50. SHARD_STATUS_FILE_ENV_VAR = 'GTEST_SHARD_STATUS_FILE'
  51. SUPPORTS_STACK_TRACES = NO_STACKTRACE_SUPPORT_FLAG not in sys.argv
  52. if SUPPORTS_STACK_TRACES:
  53. STACK_TRACE_TEMPLATE = '\nStack trace:\n*'
  54. else:
  55. STACK_TRACE_TEMPLATE = ''
  56. # unittest.main() can't handle unknown flags
  57. sys.argv.remove(NO_STACKTRACE_SUPPORT_FLAG)
  58. EXPECTED_NON_EMPTY_XML = """<?xml version="1.0" encoding="UTF-8"?>
  59. <testsuites tests="26" failures="5" disabled="2" errors="0" time="*" timestamp="*" name="AllTests" ad_hoc_property="42">
  60. <testsuite name="SuccessfulTest" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
  61. <testcase name="Succeeds" status="run" result="completed" time="*" timestamp="*" classname="SuccessfulTest"/>
  62. </testsuite>
  63. <testsuite name="FailedTest" tests="1" failures="1" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
  64. <testcase name="Fails" status="run" result="completed" time="*" timestamp="*" classname="FailedTest">
  65. <failure message="gtest_xml_output_unittest_.cc:*&#x0A;Expected equality of these values:&#x0A; 1&#x0A; 2" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
  66. Expected equality of these values:
  67. 1
  68. 2%(stack)s]]></failure>
  69. </testcase>
  70. </testsuite>
  71. <testsuite name="MixedResultTest" tests="3" failures="1" disabled="1" skipped="0" errors="0" time="*" timestamp="*">
  72. <testcase name="Succeeds" status="run" result="completed" time="*" timestamp="*" classname="MixedResultTest"/>
  73. <testcase name="Fails" status="run" result="completed" time="*" timestamp="*" classname="MixedResultTest">
  74. <failure message="gtest_xml_output_unittest_.cc:*&#x0A;Expected equality of these values:&#x0A; 1&#x0A; 2" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
  75. Expected equality of these values:
  76. 1
  77. 2%(stack)s]]></failure>
  78. <failure message="gtest_xml_output_unittest_.cc:*&#x0A;Expected equality of these values:&#x0A; 2&#x0A; 3" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
  79. Expected equality of these values:
  80. 2
  81. 3%(stack)s]]></failure>
  82. </testcase>
  83. <testcase name="DISABLED_test" status="notrun" result="suppressed" time="*" timestamp="*" classname="MixedResultTest"/>
  84. </testsuite>
  85. <testsuite name="XmlQuotingTest" tests="1" failures="1" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
  86. <testcase name="OutputsCData" status="run" result="completed" time="*" timestamp="*" classname="XmlQuotingTest">
  87. <failure message="gtest_xml_output_unittest_.cc:*&#x0A;Failed&#x0A;XML output: &lt;?xml encoding=&quot;utf-8&quot;&gt;&lt;top&gt;&lt;![CDATA[cdata text]]&gt;&lt;/top&gt;" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
  88. Failed
  89. XML output: <?xml encoding="utf-8"><top><![CDATA[cdata text]]>]]&gt;<![CDATA[</top>%(stack)s]]></failure>
  90. </testcase>
  91. </testsuite>
  92. <testsuite name="InvalidCharactersTest" tests="1" failures="1" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
  93. <testcase name="InvalidCharactersInMessage" status="run" result="completed" time="*" timestamp="*" classname="InvalidCharactersTest">
  94. <failure message="gtest_xml_output_unittest_.cc:*&#x0A;Failed&#x0A;Invalid characters in brackets []" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
  95. Failed
  96. Invalid characters in brackets []%(stack)s]]></failure>
  97. </testcase>
  98. </testsuite>
  99. <testsuite name="DisabledTest" tests="1" failures="0" disabled="1" skipped="0" errors="0" time="*" timestamp="*">
  100. <testcase name="DISABLED_test_not_run" status="notrun" result="suppressed" time="*" timestamp="*" classname="DisabledTest"/>
  101. </testsuite>
  102. <testsuite name="SkippedTest" tests="3" failures="1" disabled="0" skipped="2" errors="0" time="*" timestamp="*">
  103. <testcase name="Skipped" status="run" result="skipped" time="*" timestamp="*" classname="SkippedTest">
  104. <skipped message="gtest_xml_output_unittest_.cc:*&#x0A;"><![CDATA[gtest_xml_output_unittest_.cc:*
  105. %(stack)s]]></skipped>
  106. </testcase>
  107. <testcase name="SkippedWithMessage" status="run" result="skipped" time="*" timestamp="*" classname="SkippedTest">
  108. <skipped message="gtest_xml_output_unittest_.cc:*&#x0A;It is good practice to tell why you skip a test."><![CDATA[gtest_xml_output_unittest_.cc:*
  109. It is good practice to tell why you skip a test.%(stack)s]]></skipped>
  110. </testcase>
  111. <testcase name="SkippedAfterFailure" status="run" result="completed" time="*" timestamp="*" classname="SkippedTest">
  112. <failure message="gtest_xml_output_unittest_.cc:*&#x0A;Expected equality of these values:&#x0A; 1&#x0A; 2" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
  113. Expected equality of these values:
  114. 1
  115. 2%(stack)s]]></failure>
  116. <skipped message="gtest_xml_output_unittest_.cc:*&#x0A;It is good practice to tell why you skip a test."><![CDATA[gtest_xml_output_unittest_.cc:*
  117. It is good practice to tell why you skip a test.%(stack)s]]></skipped>
  118. </testcase>
  119. </testsuite>
  120. <testsuite name="PropertyRecordingTest" tests="4" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*" SetUpTestSuite="yes" TearDownTestSuite="aye">
  121. <testcase name="OneProperty" status="run" result="completed" time="*" timestamp="*" classname="PropertyRecordingTest">
  122. <properties>
  123. <property name="key_1" value="1"/>
  124. </properties>
  125. </testcase>
  126. <testcase name="IntValuedProperty" status="run" result="completed" time="*" timestamp="*" classname="PropertyRecordingTest">
  127. <properties>
  128. <property name="key_int" value="1"/>
  129. </properties>
  130. </testcase>
  131. <testcase name="ThreeProperties" status="run" result="completed" time="*" timestamp="*" classname="PropertyRecordingTest">
  132. <properties>
  133. <property name="key_1" value="1"/>
  134. <property name="key_2" value="2"/>
  135. <property name="key_3" value="3"/>
  136. </properties>
  137. </testcase>
  138. <testcase name="TwoValuesForOneKeyUsesLastValue" status="run" result="completed" time="*" timestamp="*" classname="PropertyRecordingTest">
  139. <properties>
  140. <property name="key_1" value="2"/>
  141. </properties>
  142. </testcase>
  143. </testsuite>
  144. <testsuite name="NoFixtureTest" tests="3" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
  145. <testcase name="RecordProperty" status="run" result="completed" time="*" timestamp="*" classname="NoFixtureTest">
  146. <properties>
  147. <property name="key" value="1"/>
  148. </properties>
  149. </testcase>
  150. <testcase name="ExternalUtilityThatCallsRecordIntValuedProperty" status="run" result="completed" time="*" timestamp="*" classname="NoFixtureTest">
  151. <properties>
  152. <property name="key_for_utility_int" value="1"/>
  153. </properties>
  154. </testcase>
  155. <testcase name="ExternalUtilityThatCallsRecordStringValuedProperty" status="run" result="completed" time="*" timestamp="*" classname="NoFixtureTest">
  156. <properties>
  157. <property name="key_for_utility_string" value="1"/>
  158. </properties>
  159. </testcase>
  160. </testsuite>
  161. <testsuite name="Single/ValueParamTest" tests="4" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
  162. <testcase name="HasValueParamAttribute/0" value_param="33" status="run" result="completed" time="*" timestamp="*" classname="Single/ValueParamTest" />
  163. <testcase name="HasValueParamAttribute/1" value_param="42" status="run" result="completed" time="*" timestamp="*" classname="Single/ValueParamTest" />
  164. <testcase name="AnotherTestThatHasValueParamAttribute/0" value_param="33" status="run" result="completed" time="*" timestamp="*" classname="Single/ValueParamTest" />
  165. <testcase name="AnotherTestThatHasValueParamAttribute/1" value_param="42" status="run" result="completed" time="*" timestamp="*" classname="Single/ValueParamTest" />
  166. </testsuite>
  167. <testsuite name="TypedTest/0" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
  168. <testcase name="HasTypeParamAttribute" type_param="*" status="run" result="completed" time="*" timestamp="*" classname="TypedTest/0" />
  169. </testsuite>
  170. <testsuite name="TypedTest/1" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
  171. <testcase name="HasTypeParamAttribute" type_param="*" status="run" result="completed" time="*" timestamp="*" classname="TypedTest/1" />
  172. </testsuite>
  173. <testsuite name="Single/TypeParameterizedTestSuite/0" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
  174. <testcase name="HasTypeParamAttribute" type_param="*" status="run" result="completed" time="*" timestamp="*" classname="Single/TypeParameterizedTestSuite/0" />
  175. </testsuite>
  176. <testsuite name="Single/TypeParameterizedTestSuite/1" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
  177. <testcase name="HasTypeParamAttribute" type_param="*" status="run" result="completed" time="*" timestamp="*" classname="Single/TypeParameterizedTestSuite/1" />
  178. </testsuite>
  179. </testsuites>""" % {
  180. 'stack': STACK_TRACE_TEMPLATE
  181. }
  182. EXPECTED_FILTERED_TEST_XML = """<?xml version="1.0" encoding="UTF-8"?>
  183. <testsuites tests="1" failures="0" disabled="0" errors="0" time="*"
  184. timestamp="*" name="AllTests" ad_hoc_property="42">
  185. <testsuite name="SuccessfulTest" tests="1" failures="0" disabled="0" skipped="0"
  186. errors="0" time="*" timestamp="*">
  187. <testcase name="Succeeds" status="run" result="completed" time="*" timestamp="*" classname="SuccessfulTest"/>
  188. </testsuite>
  189. </testsuites>"""
  190. EXPECTED_SHARDED_TEST_XML = """<?xml version="1.0" encoding="UTF-8"?>
  191. <testsuites tests="3" failures="0" disabled="0" errors="0" time="*" timestamp="*" name="AllTests" ad_hoc_property="42">
  192. <testsuite name="SuccessfulTest" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
  193. <testcase name="Succeeds" status="run" result="completed" time="*" timestamp="*" classname="SuccessfulTest"/>
  194. </testsuite>
  195. <testsuite name="PropertyRecordingTest" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*" SetUpTestSuite="yes" TearDownTestSuite="aye">
  196. <testcase name="IntValuedProperty" status="run" result="completed" time="*" timestamp="*" classname="PropertyRecordingTest">
  197. <properties>
  198. <property name="key_int" value="1"/>
  199. </properties>
  200. </testcase>
  201. </testsuite>
  202. <testsuite name="Single/ValueParamTest" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
  203. <testcase name="HasValueParamAttribute/0" value_param="33" status="run" result="completed" time="*" timestamp="*" classname="Single/ValueParamTest" />
  204. </testsuite>
  205. </testsuites>"""
  206. EXPECTED_NO_TEST_XML = """<?xml version="1.0" encoding="UTF-8"?>
  207. <testsuites tests="0" failures="0" disabled="0" errors="0" time="*"
  208. timestamp="*" name="AllTests">
  209. <testsuite name="NonTestSuiteFailure" tests="1" failures="1" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
  210. <testcase name="" status="run" result="completed" time="*" timestamp="*" classname="">
  211. <failure message="gtest_no_test_unittest.cc:*&#x0A;Expected equality of these values:&#x0A; 1&#x0A; 2" type=""><![CDATA[gtest_no_test_unittest.cc:*
  212. Expected equality of these values:
  213. 1
  214. 2%(stack)s]]></failure>
  215. </testcase>
  216. </testsuite>
  217. </testsuites>""" % {
  218. 'stack': STACK_TRACE_TEMPLATE
  219. }
  220. GTEST_PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath(GTEST_PROGRAM_NAME)
  221. SUPPORTS_TYPED_TESTS = 'TypedTest' in gtest_test_utils.Subprocess(
  222. [GTEST_PROGRAM_PATH, GTEST_LIST_TESTS_FLAG], capture_stderr=False).output
  223. class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
  224. """
  225. Unit test for Google Test's XML output functionality.
  226. """
  227. # This test currently breaks on platforms that do not support typed and
  228. # type-parameterized tests, so we don't run it under them.
  229. if SUPPORTS_TYPED_TESTS:
  230. def testNonEmptyXmlOutput(self):
  231. """
  232. Runs a test program that generates a non-empty XML output, and
  233. tests that the XML output is expected.
  234. """
  235. self._TestXmlOutput(GTEST_PROGRAM_NAME, EXPECTED_NON_EMPTY_XML, 1)
  236. def testNoTestXmlOutput(self):
  237. """Verifies XML output for a Google Test binary without actual tests.
  238. Runs a test program that generates an XML output for a binary without tests,
  239. and tests that the XML output is expected.
  240. """
  241. self._TestXmlOutput('gtest_no_test_unittest', EXPECTED_NO_TEST_XML, 0)
  242. def testTimestampValue(self):
  243. """Checks whether the timestamp attribute in the XML output is valid.
  244. Runs a test program that generates an empty XML output, and checks if
  245. the timestamp attribute in the testsuites tag is valid.
  246. """
  247. actual = self._GetXmlOutput('gtest_no_test_unittest', [], {}, 0)
  248. date_time_str = actual.documentElement.getAttributeNode('timestamp').value
  249. # datetime.strptime() is only available in Python 2.5+ so we have to
  250. # parse the expected datetime manually.
  251. match = re.match(r'(\d+)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)', date_time_str)
  252. self.assertTrue(
  253. re.match,
  254. 'XML datettime string %s has incorrect format' % date_time_str)
  255. date_time_from_xml = datetime.datetime(
  256. year=int(match.group(1)), month=int(match.group(2)),
  257. day=int(match.group(3)), hour=int(match.group(4)),
  258. minute=int(match.group(5)), second=int(match.group(6)))
  259. time_delta = abs(datetime.datetime.now() - date_time_from_xml)
  260. # timestamp value should be near the current local time
  261. self.assertTrue(time_delta < datetime.timedelta(seconds=600),
  262. 'time_delta is %s' % time_delta)
  263. actual.unlink()
  264. def testDefaultOutputFile(self):
  265. """
  266. Confirms that Google Test produces an XML output file with the expected
  267. default name if no name is explicitly specified.
  268. """
  269. output_file = os.path.join(gtest_test_utils.GetTempDir(),
  270. GTEST_DEFAULT_OUTPUT_FILE)
  271. gtest_prog_path = gtest_test_utils.GetTestExecutablePath(
  272. 'gtest_no_test_unittest')
  273. try:
  274. os.remove(output_file)
  275. except OSError:
  276. e = sys.exc_info()[1]
  277. if e.errno != errno.ENOENT:
  278. raise
  279. p = gtest_test_utils.Subprocess(
  280. [gtest_prog_path, '%s=xml' % GTEST_OUTPUT_FLAG],
  281. working_dir=gtest_test_utils.GetTempDir())
  282. self.assert_(p.exited)
  283. self.assertEquals(0, p.exit_code)
  284. self.assert_(os.path.isfile(output_file))
  285. def testSuppressedXmlOutput(self):
  286. """
  287. Tests that no XML file is generated if the default XML listener is
  288. shut down before RUN_ALL_TESTS is invoked.
  289. """
  290. xml_path = os.path.join(gtest_test_utils.GetTempDir(),
  291. GTEST_PROGRAM_NAME + 'out.xml')
  292. if os.path.isfile(xml_path):
  293. os.remove(xml_path)
  294. command = [GTEST_PROGRAM_PATH,
  295. '%s=xml:%s' % (GTEST_OUTPUT_FLAG, xml_path),
  296. '--shut_down_xml']
  297. p = gtest_test_utils.Subprocess(command)
  298. if p.terminated_by_signal:
  299. # p.signal is available only if p.terminated_by_signal is True.
  300. self.assertFalse(
  301. p.terminated_by_signal,
  302. '%s was killed by signal %d' % (GTEST_PROGRAM_NAME, p.signal))
  303. else:
  304. self.assert_(p.exited)
  305. self.assertEquals(1, p.exit_code,
  306. "'%s' exited with code %s, which doesn't match "
  307. 'the expected exit code %s.'
  308. % (command, p.exit_code, 1))
  309. self.assert_(not os.path.isfile(xml_path))
  310. def testFilteredTestXmlOutput(self):
  311. """Verifies XML output when a filter is applied.
  312. Runs a test program that executes only some tests and verifies that
  313. non-selected tests do not show up in the XML output.
  314. """
  315. self._TestXmlOutput(GTEST_PROGRAM_NAME, EXPECTED_FILTERED_TEST_XML, 0,
  316. extra_args=['%s=SuccessfulTest.*' % GTEST_FILTER_FLAG])
  317. def testShardedTestXmlOutput(self):
  318. """Verifies XML output when run using multiple shards.
  319. Runs a test program that executes only one shard and verifies that tests
  320. from other shards do not show up in the XML output.
  321. """
  322. self._TestXmlOutput(
  323. GTEST_PROGRAM_NAME,
  324. EXPECTED_SHARDED_TEST_XML,
  325. 0,
  326. extra_env={SHARD_INDEX_ENV_VAR: '0',
  327. TOTAL_SHARDS_ENV_VAR: '10'})
  328. def _GetXmlOutput(self, gtest_prog_name, extra_args, extra_env,
  329. expected_exit_code):
  330. """
  331. Returns the xml output generated by running the program gtest_prog_name.
  332. Furthermore, the program's exit code must be expected_exit_code.
  333. """
  334. xml_path = os.path.join(gtest_test_utils.GetTempDir(),
  335. gtest_prog_name + 'out.xml')
  336. gtest_prog_path = gtest_test_utils.GetTestExecutablePath(gtest_prog_name)
  337. command = ([gtest_prog_path, '%s=xml:%s' % (GTEST_OUTPUT_FLAG, xml_path)] +
  338. extra_args)
  339. environ_copy = os.environ.copy()
  340. if extra_env:
  341. environ_copy.update(extra_env)
  342. p = gtest_test_utils.Subprocess(command, env=environ_copy)
  343. if p.terminated_by_signal:
  344. self.assert_(False,
  345. '%s was killed by signal %d' % (gtest_prog_name, p.signal))
  346. else:
  347. self.assert_(p.exited)
  348. self.assertEquals(expected_exit_code, p.exit_code,
  349. "'%s' exited with code %s, which doesn't match "
  350. 'the expected exit code %s.'
  351. % (command, p.exit_code, expected_exit_code))
  352. actual = minidom.parse(xml_path)
  353. return actual
  354. def _TestXmlOutput(self, gtest_prog_name, expected_xml,
  355. expected_exit_code, extra_args=None, extra_env=None):
  356. """
  357. Asserts that the XML document generated by running the program
  358. gtest_prog_name matches expected_xml, a string containing another
  359. XML document. Furthermore, the program's exit code must be
  360. expected_exit_code.
  361. """
  362. actual = self._GetXmlOutput(gtest_prog_name, extra_args or [],
  363. extra_env or {}, expected_exit_code)
  364. expected = minidom.parseString(expected_xml)
  365. self.NormalizeXml(actual.documentElement)
  366. self.AssertEquivalentNodes(expected.documentElement,
  367. actual.documentElement)
  368. expected.unlink()
  369. actual.unlink()
  370. if __name__ == '__main__':
  371. os.environ['GTEST_STACK_TRACE_DEPTH'] = '1'
  372. gtest_test_utils.Main()