Commit 2c0fc6d4 by zhanyong.wan

Cleans up death test implementation (by Vlad Losev); changes the XML format to…

Cleans up death test implementation (by Vlad Losev); changes the XML format to be closer to junitreport (by Zhanyong Wan).
parent 1f8a50e4
...@@ -41,6 +41,8 @@ ...@@ -41,6 +41,8 @@
#if GTEST_HAS_DEATH_TEST && GTEST_OS_WINDOWS #if GTEST_HAS_DEATH_TEST && GTEST_OS_WINDOWS
#include <io.h> #include <io.h>
#elif GTEST_HAS_DEATH_TEST
#include <unistd.h>
#endif // GTEST_HAS_DEATH_TEST && GTEST_OS_WINDOWS #endif // GTEST_HAS_DEATH_TEST && GTEST_OS_WINDOWS
namespace testing { namespace testing {
...@@ -196,17 +198,17 @@ class InternalRunDeathTestFlag { ...@@ -196,17 +198,17 @@ class InternalRunDeathTestFlag {
InternalRunDeathTestFlag(const String& file, InternalRunDeathTestFlag(const String& file,
int line, int line,
int index, int index,
int status_fd) int write_fd)
: file_(file), line_(line), index_(index), status_fd_(status_fd) {} : file_(file), line_(line), index_(index), write_fd_(write_fd) {}
~InternalRunDeathTestFlag() { ~InternalRunDeathTestFlag() {
if (status_fd_ >= 0) if (write_fd_ >= 0)
// Suppress MSVC complaints about POSIX functions. // Suppress MSVC complaints about POSIX functions.
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(push) #pragma warning(push)
#pragma warning(disable: 4996) #pragma warning(disable: 4996)
#endif // _MSC_VER #endif // _MSC_VER
close(status_fd_); close(write_fd_);
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) #pragma warning(pop)
#endif // _MSC_VER #endif // _MSC_VER
...@@ -215,13 +217,13 @@ class InternalRunDeathTestFlag { ...@@ -215,13 +217,13 @@ class InternalRunDeathTestFlag {
String file() const { return file_; } String file() const { return file_; }
int line() const { return line_; } int line() const { return line_; }
int index() const { return index_; } int index() const { return index_; }
int status_fd() const { return status_fd_; } int write_fd() const { return write_fd_; }
private: private:
String file_; String file_;
int line_; int line_;
int index_; int index_;
int status_fd_; int write_fd_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(InternalRunDeathTestFlag); GTEST_DISALLOW_COPY_AND_ASSIGN_(InternalRunDeathTestFlag);
}; };
......
...@@ -1325,7 +1325,7 @@ void ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv); ...@@ -1325,7 +1325,7 @@ void ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv);
// Returns the message describing the last system error, regardless of the // Returns the message describing the last system error, regardless of the
// platform. // platform.
String GetLastSystemErrorMessage(); String GetLastErrnoDescription();
#if GTEST_OS_WINDOWS #if GTEST_OS_WINDOWS
// Provides leak-safe Windows kernel handle ownership. // Provides leak-safe Windows kernel handle ownership.
......
...@@ -3044,7 +3044,7 @@ internal::String XmlUnitTestResultPrinter::EscapeXml(const char* str, ...@@ -3044,7 +3044,7 @@ internal::String XmlUnitTestResultPrinter::EscapeXml(const char* str,
// //
// This is how Google Test concepts map to the DTD: // This is how Google Test concepts map to the DTD:
// //
// <testsuite name="AllTests"> <-- corresponds to a UnitTest object // <testsuites name="AllTests"> <-- corresponds to a UnitTest object
// <testsuite name="testcase-name"> <-- corresponds to a TestCase object // <testsuite name="testcase-name"> <-- corresponds to a TestCase object
// <testcase name="test-name"> <-- corresponds to a TestInfo object // <testcase name="test-name"> <-- corresponds to a TestInfo object
// <failure message="...">...</failure> // <failure message="...">...</failure>
...@@ -3053,7 +3053,7 @@ internal::String XmlUnitTestResultPrinter::EscapeXml(const char* str, ...@@ -3053,7 +3053,7 @@ internal::String XmlUnitTestResultPrinter::EscapeXml(const char* str,
// <-- individual assertion failures // <-- individual assertion failures
// </testcase> // </testcase>
// </testsuite> // </testsuite>
// </testsuite> // </testsuites>
namespace internal { namespace internal {
...@@ -3137,7 +3137,7 @@ void XmlUnitTestResultPrinter::PrintXmlUnitTest(FILE* out, ...@@ -3137,7 +3137,7 @@ void XmlUnitTestResultPrinter::PrintXmlUnitTest(FILE* out,
const internal::UnitTestImpl* const impl = unit_test->impl(); const internal::UnitTestImpl* const impl = unit_test->impl();
fprintf(out, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); fprintf(out, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
fprintf(out, fprintf(out,
"<testsuite tests=\"%d\" failures=\"%d\" disabled=\"%d\" " "<testsuites tests=\"%d\" failures=\"%d\" disabled=\"%d\" "
"errors=\"0\" time=\"%s\" ", "errors=\"0\" time=\"%s\" ",
impl->total_test_count(), impl->total_test_count(),
impl->failed_test_count(), impl->failed_test_count(),
...@@ -3150,7 +3150,7 @@ void XmlUnitTestResultPrinter::PrintXmlUnitTest(FILE* out, ...@@ -3150,7 +3150,7 @@ void XmlUnitTestResultPrinter::PrintXmlUnitTest(FILE* out,
case_node = case_node->next()) { case_node = case_node->next()) {
PrintXmlTestCase(out, case_node->element()); PrintXmlTestCase(out, case_node->element());
} }
fprintf(out, "</testsuite>\n"); fprintf(out, "</testsuites>\n");
} }
// Produces a string representing the test properties in a result as space // Produces a string representing the test properties in a result as space
......
...@@ -65,7 +65,7 @@ using testing::Message; ...@@ -65,7 +65,7 @@ using testing::Message;
using testing::internal::DeathTest; using testing::internal::DeathTest;
using testing::internal::DeathTestFactory; using testing::internal::DeathTestFactory;
using testing::internal::FilePath; using testing::internal::FilePath;
using testing::internal::GetLastSystemErrorMessage; using testing::internal::GetLastErrnoDescription;
using testing::internal::ParseNaturalNumber; using testing::internal::ParseNaturalNumber;
using testing::internal::String; using testing::internal::String;
...@@ -990,20 +990,13 @@ TEST(StreamingAssertionsDeathTest, DeathTest) { ...@@ -990,20 +990,13 @@ TEST(StreamingAssertionsDeathTest, DeathTest) {
}, "expected failure"); }, "expected failure");
} }
// Tests that GetLastSystemErrorMessage returns an empty string when the // Tests that GetLastErrnoDescription returns an empty string when the
// last error is 0 and non-empty string when it is non-zero. // last error is 0 and non-empty string when it is non-zero.
TEST(GetLastSystemErrorMessageTest, GetLastSystemErrorMessageWorks) { TEST(GetLastErrnoDescription, GetLastErrnoDescriptionWorks) {
#if GTEST_OS_WINDOWS
::SetLastError(ERROR_FILE_NOT_FOUND);
EXPECT_STRNE("", GetLastSystemErrorMessage().c_str());
::SetLastError(0);
EXPECT_STREQ("", GetLastSystemErrorMessage().c_str());
#else
errno = ENOENT; errno = ENOENT;
EXPECT_STRNE("", GetLastSystemErrorMessage().c_str()); EXPECT_STRNE("", GetLastErrnoDescription().c_str());
errno = 0; errno = 0;
EXPECT_STREQ("", GetLastSystemErrorMessage().c_str()); EXPECT_STREQ("", GetLastErrnoDescription().c_str());
#endif
} }
#if GTEST_OS_WINDOWS #if GTEST_OS_WINDOWS
......
...@@ -48,19 +48,19 @@ GTEST_OUTPUT_1_TEST = "gtest_xml_outfile1_test_" ...@@ -48,19 +48,19 @@ GTEST_OUTPUT_1_TEST = "gtest_xml_outfile1_test_"
GTEST_OUTPUT_2_TEST = "gtest_xml_outfile2_test_" GTEST_OUTPUT_2_TEST = "gtest_xml_outfile2_test_"
EXPECTED_XML_1 = """<?xml version="1.0" encoding="UTF-8"?> EXPECTED_XML_1 = """<?xml version="1.0" encoding="UTF-8"?>
<testsuite tests="1" failures="0" disabled="0" errors="0" time="*" name="AllTests"> <testsuites tests="1" failures="0" disabled="0" errors="0" time="*" name="AllTests">
<testsuite name="PropertyOne" tests="1" failures="0" disabled="0" errors="0" time="*"> <testsuite name="PropertyOne" tests="1" failures="0" disabled="0" errors="0" time="*">
<testcase name="TestSomeProperties" status="run" time="*" classname="PropertyOne" SetUpProp="1" TestSomeProperty="1" TearDownProp="1" /> <testcase name="TestSomeProperties" status="run" time="*" classname="PropertyOne" SetUpProp="1" TestSomeProperty="1" TearDownProp="1" />
</testsuite> </testsuite>
</testsuite> </testsuites>
""" """
EXPECTED_XML_2 = """<?xml version="1.0" encoding="UTF-8"?> EXPECTED_XML_2 = """<?xml version="1.0" encoding="UTF-8"?>
<testsuite tests="1" failures="0" disabled="0" errors="0" time="*" name="AllTests"> <testsuites tests="1" failures="0" disabled="0" errors="0" time="*" name="AllTests">
<testsuite name="PropertyTwo" tests="1" failures="0" disabled="0" errors="0" time="*"> <testsuite name="PropertyTwo" tests="1" failures="0" disabled="0" errors="0" time="*">
<testcase name="TestSomeProperties" status="run" time="*" classname="PropertyTwo" SetUpProp="2" TestSomeProperty="2" TearDownProp="2" /> <testcase name="TestSomeProperties" status="run" time="*" classname="PropertyTwo" SetUpProp="2" TestSomeProperty="2" TearDownProp="2" />
</testsuite> </testsuite>
</testsuite> </testsuites>
""" """
......
...@@ -48,7 +48,7 @@ GTEST_OUTPUT_FLAG = "--gtest_output" ...@@ -48,7 +48,7 @@ GTEST_OUTPUT_FLAG = "--gtest_output"
GTEST_DEFAULT_OUTPUT_FILE = "test_detail.xml" GTEST_DEFAULT_OUTPUT_FILE = "test_detail.xml"
EXPECTED_NON_EMPTY_XML = """<?xml version="1.0" encoding="UTF-8"?> EXPECTED_NON_EMPTY_XML = """<?xml version="1.0" encoding="UTF-8"?>
<testsuite tests="13" failures="2" disabled="2" errors="0" time="*" name="AllTests"> <testsuites tests="13" failures="2" disabled="2" errors="0" time="*" name="AllTests">
<testsuite name="SuccessfulTest" tests="1" failures="0" disabled="0" errors="0" time="*"> <testsuite name="SuccessfulTest" tests="1" failures="0" disabled="0" errors="0" time="*">
<testcase name="Succeeds" status="run" time="*" classname="SuccessfulTest"/> <testcase name="Succeeds" status="run" time="*" classname="SuccessfulTest"/>
</testsuite> </testsuite>
...@@ -85,12 +85,12 @@ Expected: 2]]></failure> ...@@ -85,12 +85,12 @@ Expected: 2]]></failure>
<testcase name="ExternalUtilityThatCallsRecordIntValuedProperty" status="run" time="*" classname="NoFixtureTest" key_for_utility_int="1"/> <testcase name="ExternalUtilityThatCallsRecordIntValuedProperty" status="run" time="*" classname="NoFixtureTest" key_for_utility_int="1"/>
<testcase name="ExternalUtilityThatCallsRecordStringValuedProperty" status="run" time="*" classname="NoFixtureTest" key_for_utility_string="1"/> <testcase name="ExternalUtilityThatCallsRecordStringValuedProperty" status="run" time="*" classname="NoFixtureTest" key_for_utility_string="1"/>
</testsuite> </testsuite>
</testsuite>""" </testsuites>"""
EXPECTED_EMPTY_XML = """<?xml version="1.0" encoding="UTF-8"?> EXPECTED_EMPTY_XML = """<?xml version="1.0" encoding="UTF-8"?>
<testsuite tests="0" failures="0" disabled="0" errors="0" time="*" name="AllTests"> <testsuites tests="0" failures="0" disabled="0" errors="0" time="*" name="AllTests">
</testsuite>""" </testsuites>"""
class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
......
...@@ -92,6 +92,7 @@ class GTestXMLTestCase(unittest.TestCase): ...@@ -92,6 +92,7 @@ class GTestXMLTestCase(unittest.TestCase):
self.AssertEquivalentNodes(child, actual_children[child_id]) self.AssertEquivalentNodes(child, actual_children[child_id])
identifying_attribute = { identifying_attribute = {
"testsuites": "name",
"testsuite": "name", "testsuite": "name",
"testcase": "name", "testcase": "name",
"failure": "message", "failure": "message",
...@@ -101,14 +102,14 @@ class GTestXMLTestCase(unittest.TestCase): ...@@ -101,14 +102,14 @@ class GTestXMLTestCase(unittest.TestCase):
""" """
Fetches all of the child nodes of element, a DOM Element object. Fetches all of the child nodes of element, a DOM Element object.
Returns them as the values of a dictionary keyed by the IDs of the Returns them as the values of a dictionary keyed by the IDs of the
children. For <testsuite> and <testcase> elements, the ID is the children. For <testsuites>, <testsuite> and <testcase> elements,
value of their "name" attribute; for <failure> elements, it is the the ID is the value of their "name" attribute; for <failure>
value of the "message" attribute; for CDATA section node, it is elements, it is the value of the "message" attribute; for CDATA
"detail". An exception is raised if any element other than the section node, it is "detail". An exception is raised if any
above four is encountered, if two child elements with the same element other than the above four is encountered, if two child
identifying attributes are encountered, or if any other type of elements with the same identifying attributes are encountered, or
node is encountered, other than Text nodes containing only if any other type of node is encountered, other than Text nodes
whitespace. containing only whitespace.
""" """
children = {} children = {}
...@@ -133,16 +134,16 @@ class GTestXMLTestCase(unittest.TestCase): ...@@ -133,16 +134,16 @@ class GTestXMLTestCase(unittest.TestCase):
Normalizes Google Test's XML output to eliminate references to transient Normalizes Google Test's XML output to eliminate references to transient
information that may change from run to run. information that may change from run to run.
* The "time" attribute of <testsuite> and <testcase> elements is * The "time" attribute of <testsuites>, <testsuite> and <testcase>
replaced with a single asterisk, if it contains only digit elements is replaced with a single asterisk, if it contains
characters. only digit characters.
* The line number reported in the first line of the "message" * The line number reported in the first line of the "message"
attribute of <failure> elements is replaced with a single asterisk. attribute of <failure> elements is replaced with a single asterisk.
* The directory names in file paths are removed. * The directory names in file paths are removed.
* The stack traces are removed. * The stack traces are removed.
""" """
if element.tagName in ("testsuite", "testcase"): if element.tagName in ("testsuites", "testsuite", "testcase"):
time = element.getAttributeNode("time") time = element.getAttributeNode("time")
time.value = re.sub(r"^\d+(\.\d+)?$", "*", time.value) time.value = re.sub(r"^\d+(\.\d+)?$", "*", time.value)
elif element.tagName == "failure": elif element.tagName == "failure":
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment