Commit 2c0fc6d4 authored by zhanyong.wan's avatar zhanyong.wan
Browse files

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 @@
#if GTEST_HAS_DEATH_TEST && GTEST_OS_WINDOWS
#include <io.h>
#elif GTEST_HAS_DEATH_TEST
#include <unistd.h>
#endif // GTEST_HAS_DEATH_TEST && GTEST_OS_WINDOWS
namespace testing {
......@@ -196,17 +198,17 @@ class InternalRunDeathTestFlag {
InternalRunDeathTestFlag(const String& file,
int line,
int index,
int status_fd)
: file_(file), line_(line), index_(index), status_fd_(status_fd) {}
int write_fd)
: file_(file), line_(line), index_(index), write_fd_(write_fd) {}
~InternalRunDeathTestFlag() {
if (status_fd_ >= 0)
if (write_fd_ >= 0)
// Suppress MSVC complaints about POSIX functions.
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4996)
#endif // _MSC_VER
close(status_fd_);
close(write_fd_);
#ifdef _MSC_VER
#pragma warning(pop)
#endif // _MSC_VER
......@@ -215,13 +217,13 @@ class InternalRunDeathTestFlag {
String file() const { return file_; }
int line() const { return line_; }
int index() const { return index_; }
int status_fd() const { return status_fd_; }
int write_fd() const { return write_fd_; }
private:
String file_;
int line_;
int index_;
int status_fd_;
int write_fd_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(InternalRunDeathTestFlag);
};
......
This diff is collapsed.
......@@ -1325,7 +1325,7 @@ void ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv);
// Returns the message describing the last system error, regardless of the
// platform.
String GetLastSystemErrorMessage();
String GetLastErrnoDescription();
#if GTEST_OS_WINDOWS
// Provides leak-safe Windows kernel handle ownership.
......
......@@ -3044,7 +3044,7 @@ internal::String XmlUnitTestResultPrinter::EscapeXml(const char* str,
//
// 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
// <testcase name="test-name"> <-- corresponds to a TestInfo object
// <failure message="...">...</failure>
......@@ -3053,7 +3053,7 @@ internal::String XmlUnitTestResultPrinter::EscapeXml(const char* str,
// <-- individual assertion failures
// </testcase>
// </testsuite>
// </testsuite>
// </testsuites>
namespace internal {
......@@ -3137,7 +3137,7 @@ void XmlUnitTestResultPrinter::PrintXmlUnitTest(FILE* out,
const internal::UnitTestImpl* const impl = unit_test->impl();
fprintf(out, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
fprintf(out,
"<testsuite tests=\"%d\" failures=\"%d\" disabled=\"%d\" "
"<testsuites tests=\"%d\" failures=\"%d\" disabled=\"%d\" "
"errors=\"0\" time=\"%s\" ",
impl->total_test_count(),
impl->failed_test_count(),
......@@ -3150,7 +3150,7 @@ void XmlUnitTestResultPrinter::PrintXmlUnitTest(FILE* out,
case_node = case_node->next()) {
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
......
......@@ -65,7 +65,7 @@ using testing::Message;
using testing::internal::DeathTest;
using testing::internal::DeathTestFactory;
using testing::internal::FilePath;
using testing::internal::GetLastSystemErrorMessage;
using testing::internal::GetLastErrnoDescription;
using testing::internal::ParseNaturalNumber;
using testing::internal::String;
......@@ -990,20 +990,13 @@ TEST(StreamingAssertionsDeathTest, DeathTest) {
}, "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.
TEST(GetLastSystemErrorMessageTest, GetLastSystemErrorMessageWorks) {
#if GTEST_OS_WINDOWS
::SetLastError(ERROR_FILE_NOT_FOUND);
EXPECT_STRNE("", GetLastSystemErrorMessage().c_str());
::SetLastError(0);
EXPECT_STREQ("", GetLastSystemErrorMessage().c_str());
#else
TEST(GetLastErrnoDescription, GetLastErrnoDescriptionWorks) {
errno = ENOENT;
EXPECT_STRNE("", GetLastSystemErrorMessage().c_str());
EXPECT_STRNE("", GetLastErrnoDescription().c_str());
errno = 0;
EXPECT_STREQ("", GetLastSystemErrorMessage().c_str());
#endif
EXPECT_STREQ("", GetLastErrnoDescription().c_str());
}
#if GTEST_OS_WINDOWS
......
......@@ -48,19 +48,19 @@ GTEST_OUTPUT_1_TEST = "gtest_xml_outfile1_test_"
GTEST_OUTPUT_2_TEST = "gtest_xml_outfile2_test_"
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="*">
<testcase name="TestSomeProperties" status="run" time="*" classname="PropertyOne" SetUpProp="1" TestSomeProperty="1" TearDownProp="1" />
</testsuite>
</testsuite>
</testsuites>
"""
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="*">
<testcase name="TestSomeProperties" status="run" time="*" classname="PropertyTwo" SetUpProp="2" TestSomeProperty="2" TearDownProp="2" />
</testsuite>
</testsuite>
</testsuites>
"""
......
......@@ -48,7 +48,7 @@ GTEST_OUTPUT_FLAG = "--gtest_output"
GTEST_DEFAULT_OUTPUT_FILE = "test_detail.xml"
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="*">
<testcase name="Succeeds" status="run" time="*" classname="SuccessfulTest"/>
</testsuite>
......@@ -85,12 +85,12 @@ Expected: 2]]></failure>
<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"/>
</testsuite>
</testsuite>"""
</testsuites>"""
EXPECTED_EMPTY_XML = """<?xml version="1.0" encoding="UTF-8"?>
<testsuite tests="0" failures="0" disabled="0" errors="0" time="*" name="AllTests">
</testsuite>"""
<testsuites tests="0" failures="0" disabled="0" errors="0" time="*" name="AllTests">
</testsuites>"""
class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
......
......@@ -92,6 +92,7 @@ class GTestXMLTestCase(unittest.TestCase):
self.AssertEquivalentNodes(child, actual_children[child_id])
identifying_attribute = {
"testsuites": "name",
"testsuite": "name",
"testcase": "name",
"failure": "message",
......@@ -101,14 +102,14 @@ class GTestXMLTestCase(unittest.TestCase):
"""
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
children. For <testsuite> and <testcase> elements, the ID is the
value of their "name" attribute; for <failure> elements, it is the
value of the "message" attribute; for CDATA section node, it is
"detail". An exception is raised if any element other than the
above four is encountered, if two child elements with the same
identifying attributes are encountered, or if any other type of
node is encountered, other than Text nodes containing only
whitespace.
children. For <testsuites>, <testsuite> and <testcase> elements,
the ID is the value of their "name" attribute; for <failure>
elements, it is the value of the "message" attribute; for CDATA
section node, it is "detail". An exception is raised if any
element other than the above four is encountered, if two child
elements with the same identifying attributes are encountered, or
if any other type of node is encountered, other than Text nodes
containing only whitespace.
"""
children = {}
......@@ -133,16 +134,16 @@ class GTestXMLTestCase(unittest.TestCase):
Normalizes Google Test's XML output to eliminate references to transient
information that may change from run to run.
* The "time" attribute of <testsuite> and <testcase> elements is
replaced with a single asterisk, if it contains only digit
characters.
* The "time" attribute of <testsuites>, <testsuite> and <testcase>
elements is replaced with a single asterisk, if it contains
only digit characters.
* The line number reported in the first line of the "message"
attribute of <failure> elements is replaced with a single asterisk.
* The directory names in file paths 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.value = re.sub(r"^\d+(\.\d+)?$", "*", time.value)
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