Thu, 15 Jan 2015 15:55:04 +0100
Back out 97036ab72558 which inappropriately compared turds to third parties.
michael@0 | 1 | #!/usr/bin/env python |
michael@0 | 2 | # |
michael@0 | 3 | # Copyright 2008, Google Inc. |
michael@0 | 4 | # All rights reserved. |
michael@0 | 5 | # |
michael@0 | 6 | # Redistribution and use in source and binary forms, with or without |
michael@0 | 7 | # modification, are permitted provided that the following conditions are |
michael@0 | 8 | # met: |
michael@0 | 9 | # |
michael@0 | 10 | # * Redistributions of source code must retain the above copyright |
michael@0 | 11 | # notice, this list of conditions and the following disclaimer. |
michael@0 | 12 | # * Redistributions in binary form must reproduce the above |
michael@0 | 13 | # copyright notice, this list of conditions and the following disclaimer |
michael@0 | 14 | # in the documentation and/or other materials provided with the |
michael@0 | 15 | # distribution. |
michael@0 | 16 | # * Neither the name of Google Inc. nor the names of its |
michael@0 | 17 | # contributors may be used to endorse or promote products derived from |
michael@0 | 18 | # this software without specific prior written permission. |
michael@0 | 19 | # |
michael@0 | 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
michael@0 | 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
michael@0 | 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
michael@0 | 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
michael@0 | 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
michael@0 | 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
michael@0 | 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
michael@0 | 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
michael@0 | 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
michael@0 | 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
michael@0 | 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
michael@0 | 31 | |
michael@0 | 32 | """Unit test for the gtest_xml_output module.""" |
michael@0 | 33 | |
michael@0 | 34 | __author__ = "keith.ray@gmail.com (Keith Ray)" |
michael@0 | 35 | |
michael@0 | 36 | import os |
michael@0 | 37 | from xml.dom import minidom, Node |
michael@0 | 38 | |
michael@0 | 39 | import gtest_test_utils |
michael@0 | 40 | import gtest_xml_test_utils |
michael@0 | 41 | |
michael@0 | 42 | |
michael@0 | 43 | GTEST_OUTPUT_SUBDIR = "xml_outfiles" |
michael@0 | 44 | GTEST_OUTPUT_1_TEST = "gtest_xml_outfile1_test_" |
michael@0 | 45 | GTEST_OUTPUT_2_TEST = "gtest_xml_outfile2_test_" |
michael@0 | 46 | |
michael@0 | 47 | EXPECTED_XML_1 = """<?xml version="1.0" encoding="UTF-8"?> |
michael@0 | 48 | <testsuites tests="1" failures="0" disabled="0" errors="0" time="*" timestamp="*" name="AllTests"> |
michael@0 | 49 | <testsuite name="PropertyOne" tests="1" failures="0" disabled="0" errors="0" time="*"> |
michael@0 | 50 | <testcase name="TestSomeProperties" status="run" time="*" classname="PropertyOne" SetUpProp="1" TestSomeProperty="1" TearDownProp="1" /> |
michael@0 | 51 | </testsuite> |
michael@0 | 52 | </testsuites> |
michael@0 | 53 | """ |
michael@0 | 54 | |
michael@0 | 55 | EXPECTED_XML_2 = """<?xml version="1.0" encoding="UTF-8"?> |
michael@0 | 56 | <testsuites tests="1" failures="0" disabled="0" errors="0" time="*" timestamp="*" name="AllTests"> |
michael@0 | 57 | <testsuite name="PropertyTwo" tests="1" failures="0" disabled="0" errors="0" time="*"> |
michael@0 | 58 | <testcase name="TestSomeProperties" status="run" time="*" classname="PropertyTwo" SetUpProp="2" TestSomeProperty="2" TearDownProp="2" /> |
michael@0 | 59 | </testsuite> |
michael@0 | 60 | </testsuites> |
michael@0 | 61 | """ |
michael@0 | 62 | |
michael@0 | 63 | |
michael@0 | 64 | class GTestXMLOutFilesTest(gtest_xml_test_utils.GTestXMLTestCase): |
michael@0 | 65 | """Unit test for Google Test's XML output functionality.""" |
michael@0 | 66 | |
michael@0 | 67 | def setUp(self): |
michael@0 | 68 | # We want the trailing '/' that the last "" provides in os.path.join, for |
michael@0 | 69 | # telling Google Test to create an output directory instead of a single file |
michael@0 | 70 | # for xml output. |
michael@0 | 71 | self.output_dir_ = os.path.join(gtest_test_utils.GetTempDir(), |
michael@0 | 72 | GTEST_OUTPUT_SUBDIR, "") |
michael@0 | 73 | self.DeleteFilesAndDir() |
michael@0 | 74 | |
michael@0 | 75 | def tearDown(self): |
michael@0 | 76 | self.DeleteFilesAndDir() |
michael@0 | 77 | |
michael@0 | 78 | def DeleteFilesAndDir(self): |
michael@0 | 79 | try: |
michael@0 | 80 | os.remove(os.path.join(self.output_dir_, GTEST_OUTPUT_1_TEST + ".xml")) |
michael@0 | 81 | except os.error: |
michael@0 | 82 | pass |
michael@0 | 83 | try: |
michael@0 | 84 | os.remove(os.path.join(self.output_dir_, GTEST_OUTPUT_2_TEST + ".xml")) |
michael@0 | 85 | except os.error: |
michael@0 | 86 | pass |
michael@0 | 87 | try: |
michael@0 | 88 | os.rmdir(self.output_dir_) |
michael@0 | 89 | except os.error: |
michael@0 | 90 | pass |
michael@0 | 91 | |
michael@0 | 92 | def testOutfile1(self): |
michael@0 | 93 | self._TestOutFile(GTEST_OUTPUT_1_TEST, EXPECTED_XML_1) |
michael@0 | 94 | |
michael@0 | 95 | def testOutfile2(self): |
michael@0 | 96 | self._TestOutFile(GTEST_OUTPUT_2_TEST, EXPECTED_XML_2) |
michael@0 | 97 | |
michael@0 | 98 | def _TestOutFile(self, test_name, expected_xml): |
michael@0 | 99 | gtest_prog_path = gtest_test_utils.GetTestExecutablePath(test_name) |
michael@0 | 100 | command = [gtest_prog_path, "--gtest_output=xml:%s" % self.output_dir_] |
michael@0 | 101 | p = gtest_test_utils.Subprocess(command, |
michael@0 | 102 | working_dir=gtest_test_utils.GetTempDir()) |
michael@0 | 103 | self.assert_(p.exited) |
michael@0 | 104 | self.assertEquals(0, p.exit_code) |
michael@0 | 105 | |
michael@0 | 106 | # TODO(wan@google.com): libtool causes the built test binary to be |
michael@0 | 107 | # named lt-gtest_xml_outfiles_test_ instead of |
michael@0 | 108 | # gtest_xml_outfiles_test_. To account for this possibillity, we |
michael@0 | 109 | # allow both names in the following code. We should remove this |
michael@0 | 110 | # hack when Chandler Carruth's libtool replacement tool is ready. |
michael@0 | 111 | output_file_name1 = test_name + ".xml" |
michael@0 | 112 | output_file1 = os.path.join(self.output_dir_, output_file_name1) |
michael@0 | 113 | output_file_name2 = 'lt-' + output_file_name1 |
michael@0 | 114 | output_file2 = os.path.join(self.output_dir_, output_file_name2) |
michael@0 | 115 | self.assert_(os.path.isfile(output_file1) or os.path.isfile(output_file2), |
michael@0 | 116 | output_file1) |
michael@0 | 117 | |
michael@0 | 118 | expected = minidom.parseString(expected_xml) |
michael@0 | 119 | if os.path.isfile(output_file1): |
michael@0 | 120 | actual = minidom.parse(output_file1) |
michael@0 | 121 | else: |
michael@0 | 122 | actual = minidom.parse(output_file2) |
michael@0 | 123 | self.NormalizeXml(actual.documentElement) |
michael@0 | 124 | self.AssertEquivalentNodes(expected.documentElement, |
michael@0 | 125 | actual.documentElement) |
michael@0 | 126 | expected.unlink() |
michael@0 | 127 | actual.unlink() |
michael@0 | 128 | |
michael@0 | 129 | |
michael@0 | 130 | if __name__ == "__main__": |
michael@0 | 131 | os.environ["GTEST_STACK_TRACE_DEPTH"] = "0" |
michael@0 | 132 | gtest_test_utils.Main() |