Merge 4ac8c39200
into a866428a78
This commit is contained in:
commit
22bf4abd68
@ -1018,6 +1018,27 @@ class EmptyTestEventListener : public TestEventListener {
|
|||||||
void OnTestProgramEnd(const UnitTest& /*unit_test*/) override {}
|
void OnTestProgramEnd(const UnitTest& /*unit_test*/) override {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class XmlUnitTestResultPrinter : public EmptyTestEventListener {
|
||||||
|
public:
|
||||||
|
#if GTEST_HAS_FILE_SYSTEM
|
||||||
|
XmlUnitTestResultPrinter(const char* output_file);
|
||||||
|
#endif // GTEST_HAS_FILE_SYSTEM
|
||||||
|
|
||||||
|
XmlUnitTestResultPrinter(std::ostream* output_stream);
|
||||||
|
|
||||||
|
XmlUnitTestResultPrinter(const XmlUnitTestResultPrinter&) = delete;
|
||||||
|
XmlUnitTestResultPrinter& operator=(const XmlUnitTestResultPrinter&) = delete;
|
||||||
|
|
||||||
|
void OnTestIterationEnd(const UnitTest& unit_test, int iteration) override;
|
||||||
|
void ListTestsMatchingFilter(const std::vector<TestSuite*>& test_suites);
|
||||||
|
|
||||||
|
private:
|
||||||
|
#if GTEST_HAS_FILE_SYSTEM
|
||||||
|
const std::string output_file_;
|
||||||
|
#endif // GTEST_HAS_FILE_SYSTEM
|
||||||
|
std::ostream* output_stream_;
|
||||||
|
};
|
||||||
|
|
||||||
// TestEventListeners lets users add listeners to track events in Google Test.
|
// TestEventListeners lets users add listeners to track events in Google Test.
|
||||||
class GTEST_API_ TestEventListeners {
|
class GTEST_API_ TestEventListeners {
|
||||||
public:
|
public:
|
||||||
|
@ -2383,7 +2383,6 @@ static std::vector<std::string> GetReservedAttributesForElement(
|
|||||||
return std::vector<std::string>();
|
return std::vector<std::string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if GTEST_HAS_FILE_SYSTEM
|
|
||||||
// TODO(jdesprez): Merge the two getReserved attributes once skip is improved
|
// TODO(jdesprez): Merge the two getReserved attributes once skip is improved
|
||||||
// This function is only used when file systems are enabled.
|
// This function is only used when file systems are enabled.
|
||||||
static std::vector<std::string> GetReservedOutputAttributesForElement(
|
static std::vector<std::string> GetReservedOutputAttributesForElement(
|
||||||
@ -2400,7 +2399,6 @@ static std::vector<std::string> GetReservedOutputAttributesForElement(
|
|||||||
// This code is unreachable but some compilers may not realizes that.
|
// This code is unreachable but some compilers may not realizes that.
|
||||||
return std::vector<std::string>();
|
return std::vector<std::string>();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
static std::string FormatWordList(const std::vector<std::string>& words) {
|
static std::string FormatWordList(const std::vector<std::string>& words) {
|
||||||
Message word_list;
|
Message word_list;
|
||||||
@ -3928,14 +3926,10 @@ void TestEventRepeater::OnTestIterationEnd(const UnitTest& unit_test,
|
|||||||
|
|
||||||
// End TestEventRepeater
|
// End TestEventRepeater
|
||||||
|
|
||||||
#if GTEST_HAS_FILE_SYSTEM
|
|
||||||
// This class generates an XML output file.
|
// This class generates an XML output file.
|
||||||
class XmlUnitTestResultPrinter : public EmptyTestEventListener {
|
class XmlUnitTestResultPrinter : public EmptyTestEventListener {
|
||||||
public:
|
public:
|
||||||
explicit XmlUnitTestResultPrinter(const char* output_file);
|
XmlUnitTestResultPrinter() = delete;
|
||||||
|
|
||||||
void OnTestIterationEnd(const UnitTest& unit_test, int iteration) override;
|
|
||||||
void ListTestsMatchingFilter(const std::vector<TestSuite*>& test_suites);
|
|
||||||
|
|
||||||
// Prints an XML summary of all unit tests.
|
// Prints an XML summary of all unit tests.
|
||||||
static void PrintXmlTestsList(std::ostream* stream,
|
static void PrintXmlTestsList(std::ostream* stream,
|
||||||
@ -4018,40 +4012,9 @@ class XmlUnitTestResultPrinter : public EmptyTestEventListener {
|
|||||||
const TestResult& result,
|
const TestResult& result,
|
||||||
const std::string& indent);
|
const std::string& indent);
|
||||||
|
|
||||||
// The output file.
|
friend ::testing::XmlUnitTestResultPrinter;
|
||||||
const std::string output_file_;
|
|
||||||
|
|
||||||
XmlUnitTestResultPrinter(const XmlUnitTestResultPrinter&) = delete;
|
|
||||||
XmlUnitTestResultPrinter& operator=(const XmlUnitTestResultPrinter&) = delete;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Creates a new XmlUnitTestResultPrinter.
|
|
||||||
XmlUnitTestResultPrinter::XmlUnitTestResultPrinter(const char* output_file)
|
|
||||||
: output_file_(output_file) {
|
|
||||||
if (output_file_.empty()) {
|
|
||||||
GTEST_LOG_(FATAL) << "XML output file may not be null";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called after the unit test ends.
|
|
||||||
void XmlUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test,
|
|
||||||
int /*iteration*/) {
|
|
||||||
FILE* xmlout = OpenFileForWriting(output_file_);
|
|
||||||
std::stringstream stream;
|
|
||||||
PrintXmlUnitTest(&stream, unit_test);
|
|
||||||
fprintf(xmlout, "%s", StringStreamToString(&stream).c_str());
|
|
||||||
fclose(xmlout);
|
|
||||||
}
|
|
||||||
|
|
||||||
void XmlUnitTestResultPrinter::ListTestsMatchingFilter(
|
|
||||||
const std::vector<TestSuite*>& test_suites) {
|
|
||||||
FILE* xmlout = OpenFileForWriting(output_file_);
|
|
||||||
std::stringstream stream;
|
|
||||||
PrintXmlTestsList(&stream, test_suites);
|
|
||||||
fprintf(xmlout, "%s", StringStreamToString(&stream).c_str());
|
|
||||||
fclose(xmlout);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns an XML-escaped copy of the input string str. If is_attribute
|
// Returns an XML-escaped copy of the input string str. If is_attribute
|
||||||
// is true, the text is meant to appear as an attribute value, and
|
// is true, the text is meant to appear as an attribute value, and
|
||||||
// normalizable whitespace is preserved by replacing it with character
|
// normalizable whitespace is preserved by replacing it with character
|
||||||
@ -4483,7 +4446,6 @@ void XmlUnitTestResultPrinter::OutputXmlTestProperties(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// End XmlUnitTestResultPrinter
|
// End XmlUnitTestResultPrinter
|
||||||
#endif // GTEST_HAS_FILE_SYSTEM
|
|
||||||
|
|
||||||
#if GTEST_HAS_FILE_SYSTEM
|
#if GTEST_HAS_FILE_SYSTEM
|
||||||
// This class generates an JSON output file.
|
// This class generates an JSON output file.
|
||||||
@ -5227,6 +5189,69 @@ void TestEventListeners::SuppressEventForwarding(bool suppress) {
|
|||||||
repeater_->set_forwarding_enabled(!suppress);
|
repeater_->set_forwarding_enabled(!suppress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if GTEST_HAS_FILE_SYSTEM
|
||||||
|
// Creates a new XmlUnitTestResultPrinter.
|
||||||
|
XmlUnitTestResultPrinter::XmlUnitTestResultPrinter(const char* output_file)
|
||||||
|
: output_file_(output_file) {
|
||||||
|
if (output_file_.empty()) {
|
||||||
|
GTEST_LOG_(FATAL) << "XML output file may not be null";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif // GTEST_HAS_FILE_SYSTEM
|
||||||
|
|
||||||
|
// Creates a new XmlUnitTestResultPrinter.
|
||||||
|
XmlUnitTestResultPrinter::XmlUnitTestResultPrinter(std::ostream* output_stream)
|
||||||
|
: output_stream_(output_stream) {
|
||||||
|
if (!output_stream->good()) {
|
||||||
|
GTEST_LOG_(FATAL) << "XML output is not good";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called after the unit test ends.
|
||||||
|
void XmlUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test,
|
||||||
|
int /*iteration*/) {
|
||||||
|
#if GTEST_HAS_FILE_SYSTEM
|
||||||
|
FILE* xmlout = 0;
|
||||||
|
if(!output_stream_) {
|
||||||
|
xmlout = internal::OpenFileForWriting(output_file_);
|
||||||
|
output_stream_ = new std::stringstream;
|
||||||
|
}
|
||||||
|
#endif // GTEST_HAS_FILE_SYSTEM
|
||||||
|
|
||||||
|
internal::XmlUnitTestResultPrinter::PrintXmlUnitTest(output_stream_, unit_test);
|
||||||
|
|
||||||
|
#if GTEST_HAS_FILE_SYSTEM
|
||||||
|
if(xmlout) {
|
||||||
|
fprintf(xmlout, "%s", internal::StringStreamToString(static_cast<std::stringstream*>(output_stream_)).c_str());
|
||||||
|
fclose(xmlout);
|
||||||
|
delete output_stream_;
|
||||||
|
output_stream_ = 0;
|
||||||
|
}
|
||||||
|
#endif // GTEST_HAS_FILE_SYSTEM
|
||||||
|
}
|
||||||
|
|
||||||
|
void XmlUnitTestResultPrinter::ListTestsMatchingFilter(
|
||||||
|
const std::vector<TestSuite*>& test_suites) {
|
||||||
|
#if GTEST_HAS_FILE_SYSTEM
|
||||||
|
FILE* xmlout = 0;
|
||||||
|
if(!output_stream_) {
|
||||||
|
xmlout = internal::OpenFileForWriting(output_file_);
|
||||||
|
output_stream_ = new std::stringstream;
|
||||||
|
}
|
||||||
|
#endif // GTEST_HAS_FILE_SYSTEM
|
||||||
|
|
||||||
|
internal::XmlUnitTestResultPrinter::PrintXmlTestsList(output_stream_, test_suites);
|
||||||
|
|
||||||
|
#if GTEST_HAS_FILE_SYSTEM
|
||||||
|
if(xmlout) {
|
||||||
|
fprintf(xmlout, "%s", internal::StringStreamToString(static_cast<std::stringstream*>(output_stream_)).c_str());
|
||||||
|
fclose(xmlout);
|
||||||
|
delete output_stream_;
|
||||||
|
output_stream_ = 0;
|
||||||
|
}
|
||||||
|
#endif // GTEST_HAS_FILE_SYSTEM
|
||||||
|
}
|
||||||
|
|
||||||
// class UnitTest
|
// class UnitTest
|
||||||
|
|
||||||
// Gets the singleton UnitTest object. The first time this method is
|
// Gets the singleton UnitTest object. The first time this method is
|
||||||
@ -5728,7 +5753,7 @@ void UnitTestImpl::ConfigureXmlOutput() {
|
|||||||
const std::string& output_format = UnitTestOptions::GetOutputFormat();
|
const std::string& output_format = UnitTestOptions::GetOutputFormat();
|
||||||
#if GTEST_HAS_FILE_SYSTEM
|
#if GTEST_HAS_FILE_SYSTEM
|
||||||
if (output_format == "xml") {
|
if (output_format == "xml") {
|
||||||
listeners()->SetDefaultXmlGenerator(new XmlUnitTestResultPrinter(
|
listeners()->SetDefaultXmlGenerator(new ::testing::XmlUnitTestResultPrinter(
|
||||||
UnitTestOptions::GetAbsolutePathToOutputFile().c_str()));
|
UnitTestOptions::GetAbsolutePathToOutputFile().c_str()));
|
||||||
} else if (output_format == "json") {
|
} else if (output_format == "json") {
|
||||||
listeners()->SetDefaultXmlGenerator(new JsonUnitTestResultPrinter(
|
listeners()->SetDefaultXmlGenerator(new JsonUnitTestResultPrinter(
|
||||||
@ -6294,9 +6319,7 @@ void UnitTestImpl::ListTestsMatchingFilter() {
|
|||||||
OpenFileForWriting(UnitTestOptions::GetAbsolutePathToOutputFile());
|
OpenFileForWriting(UnitTestOptions::GetAbsolutePathToOutputFile());
|
||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
if (output_format == "xml") {
|
if (output_format == "xml") {
|
||||||
XmlUnitTestResultPrinter(
|
XmlUnitTestResultPrinter::PrintXmlTestsList(&stream, test_suites_);
|
||||||
UnitTestOptions::GetAbsolutePathToOutputFile().c_str())
|
|
||||||
.PrintXmlTestsList(&stream, test_suites_);
|
|
||||||
} else if (output_format == "json") {
|
} else if (output_format == "json") {
|
||||||
JsonUnitTestResultPrinter(
|
JsonUnitTestResultPrinter(
|
||||||
UnitTestOptions::GetAbsolutePathToOutputFile().c_str())
|
UnitTestOptions::GetAbsolutePathToOutputFile().c_str())
|
||||||
|
Loading…
Reference in New Issue
Block a user