make XmlUnitTestResultPrinter usable without filesystem
Make XmlUnitTestResultPrinter usable when GTEST_HAS_FILE_SYSTEM=0, though this should probably be another class extending XmlUnitTestResultPrinter instead - but feels like the preprocessor feature flag logic matches the existing code base.
This commit is contained in:
parent
36bd22a585
commit
4ac8c39200
@ -1020,7 +1020,9 @@ class EmptyTestEventListener : public TestEventListener {
|
|||||||
|
|
||||||
class XmlUnitTestResultPrinter : public EmptyTestEventListener {
|
class XmlUnitTestResultPrinter : public EmptyTestEventListener {
|
||||||
public:
|
public:
|
||||||
|
#if GTEST_HAS_FILE_SYSTEM
|
||||||
XmlUnitTestResultPrinter(const char* output_file);
|
XmlUnitTestResultPrinter(const char* output_file);
|
||||||
|
#endif // GTEST_HAS_FILE_SYSTEM
|
||||||
|
|
||||||
XmlUnitTestResultPrinter(std::ostream* output_stream);
|
XmlUnitTestResultPrinter(std::ostream* output_stream);
|
||||||
|
|
||||||
@ -1031,7 +1033,9 @@ class XmlUnitTestResultPrinter : public EmptyTestEventListener {
|
|||||||
void ListTestsMatchingFilter(const std::vector<TestSuite*>& test_suites);
|
void ListTestsMatchingFilter(const std::vector<TestSuite*>& test_suites);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
#if GTEST_HAS_FILE_SYSTEM
|
||||||
const std::string output_file_;
|
const std::string output_file_;
|
||||||
|
#endif // GTEST_HAS_FILE_SYSTEM
|
||||||
std::ostream* output_stream_;
|
std::ostream* output_stream_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2342,7 +2342,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(
|
||||||
@ -2359,7 +2358,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;
|
||||||
@ -3893,7 +3891,6 @@ 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:
|
||||||
@ -4414,7 +4411,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.
|
||||||
@ -5111,6 +5107,7 @@ void TestEventListeners::SuppressEventForwarding(bool suppress) {
|
|||||||
repeater_->set_forwarding_enabled(!suppress);
|
repeater_->set_forwarding_enabled(!suppress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if GTEST_HAS_FILE_SYSTEM
|
||||||
// Creates a new XmlUnitTestResultPrinter.
|
// Creates a new XmlUnitTestResultPrinter.
|
||||||
XmlUnitTestResultPrinter::XmlUnitTestResultPrinter(const char* output_file)
|
XmlUnitTestResultPrinter::XmlUnitTestResultPrinter(const char* output_file)
|
||||||
: output_file_(output_file) {
|
: output_file_(output_file) {
|
||||||
@ -5118,6 +5115,7 @@ XmlUnitTestResultPrinter::XmlUnitTestResultPrinter(const char* output_file)
|
|||||||
GTEST_LOG_(FATAL) << "XML output file may not be null";
|
GTEST_LOG_(FATAL) << "XML output file may not be null";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif // GTEST_HAS_FILE_SYSTEM
|
||||||
|
|
||||||
// Creates a new XmlUnitTestResultPrinter.
|
// Creates a new XmlUnitTestResultPrinter.
|
||||||
XmlUnitTestResultPrinter::XmlUnitTestResultPrinter(std::ostream* output_stream)
|
XmlUnitTestResultPrinter::XmlUnitTestResultPrinter(std::ostream* output_stream)
|
||||||
@ -5130,38 +5128,46 @@ XmlUnitTestResultPrinter::XmlUnitTestResultPrinter(std::ostream* output_stream)
|
|||||||
// Called after the unit test ends.
|
// Called after the unit test ends.
|
||||||
void XmlUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test,
|
void XmlUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test,
|
||||||
int /*iteration*/) {
|
int /*iteration*/) {
|
||||||
|
#if GTEST_HAS_FILE_SYSTEM
|
||||||
FILE* xmlout = 0;
|
FILE* xmlout = 0;
|
||||||
if(!output_stream_) {
|
if(!output_stream_) {
|
||||||
xmlout = internal::OpenFileForWriting(output_file_);
|
xmlout = internal::OpenFileForWriting(output_file_);
|
||||||
output_stream_ = new std::stringstream;
|
output_stream_ = new std::stringstream;
|
||||||
}
|
}
|
||||||
|
#endif // GTEST_HAS_FILE_SYSTEM
|
||||||
|
|
||||||
internal::XmlUnitTestResultPrinter::PrintXmlUnitTest(output_stream_, unit_test);
|
internal::XmlUnitTestResultPrinter::PrintXmlUnitTest(output_stream_, unit_test);
|
||||||
|
|
||||||
|
#if GTEST_HAS_FILE_SYSTEM
|
||||||
if(xmlout) {
|
if(xmlout) {
|
||||||
fprintf(xmlout, "%s", internal::StringStreamToString(static_cast<std::stringstream*>(output_stream_)).c_str());
|
fprintf(xmlout, "%s", internal::StringStreamToString(static_cast<std::stringstream*>(output_stream_)).c_str());
|
||||||
fclose(xmlout);
|
fclose(xmlout);
|
||||||
delete output_stream_;
|
delete output_stream_;
|
||||||
output_stream_ = 0;
|
output_stream_ = 0;
|
||||||
}
|
}
|
||||||
|
#endif // GTEST_HAS_FILE_SYSTEM
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlUnitTestResultPrinter::ListTestsMatchingFilter(
|
void XmlUnitTestResultPrinter::ListTestsMatchingFilter(
|
||||||
const std::vector<TestSuite*>& test_suites) {
|
const std::vector<TestSuite*>& test_suites) {
|
||||||
|
#if GTEST_HAS_FILE_SYSTEM
|
||||||
FILE* xmlout = 0;
|
FILE* xmlout = 0;
|
||||||
if(!output_stream_) {
|
if(!output_stream_) {
|
||||||
xmlout = internal::OpenFileForWriting(output_file_);
|
xmlout = internal::OpenFileForWriting(output_file_);
|
||||||
output_stream_ = new std::stringstream;
|
output_stream_ = new std::stringstream;
|
||||||
}
|
}
|
||||||
|
#endif // GTEST_HAS_FILE_SYSTEM
|
||||||
|
|
||||||
internal::XmlUnitTestResultPrinter::PrintXmlTestsList(output_stream_, test_suites);
|
internal::XmlUnitTestResultPrinter::PrintXmlTestsList(output_stream_, test_suites);
|
||||||
|
|
||||||
|
#if GTEST_HAS_FILE_SYSTEM
|
||||||
if(xmlout) {
|
if(xmlout) {
|
||||||
fprintf(xmlout, "%s", internal::StringStreamToString(static_cast<std::stringstream*>(output_stream_)).c_str());
|
fprintf(xmlout, "%s", internal::StringStreamToString(static_cast<std::stringstream*>(output_stream_)).c_str());
|
||||||
fclose(xmlout);
|
fclose(xmlout);
|
||||||
delete output_stream_;
|
delete output_stream_;
|
||||||
output_stream_ = 0;
|
output_stream_ = 0;
|
||||||
}
|
}
|
||||||
|
#endif // GTEST_HAS_FILE_SYSTEM
|
||||||
}
|
}
|
||||||
|
|
||||||
// class UnitTest
|
// class UnitTest
|
||||||
|
Loading…
Reference in New Issue
Block a user