summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2017-01-10 20:22:26 (GMT)
committerTobias Markmann <tm@ayena.de>2017-01-11 18:23:48 (GMT)
commit3b0cde2e6dbf26a01a59b0004e4041199731cbc8 (patch)
tree0b2ba6addb161f1d3e437a64685ea797341a149b /QA/Checker
parenta0c339f80e4585341179edef1898defd21a0d36a (diff)
downloadswift-3b0cde2e6dbf26a01a59b0004e4041199731cbc8.zip
swift-3b0cde2e6dbf26a01a59b0004e4041199731cbc8.tar.bz2
Integrate googletest and googlemock libraries to 3rdParty
googletest and googlemock from release 1.8.0 have been copied to the 3rdParty folder. With this commit tests for Swift project can also written using googletest and googlemock APIs. The test runners will execute test suites written to either test library. Passing —-xml to a test runner will now create two test report XML files, namely $programName-report.cppunit.xml and $programName-report.gtest.xml. The ByteArrayTest has been converted to use googletest instead of googlemock to serve as an example and test the integration. Test-Information: Build all tests via ‘./scons test=all’ and verified all tests are run. Build all tests via ‘./scons test=all checker_report=1’ and verified that two report XML files are generated per test runner executed. Change-Id: I81a9fb2c7ea5612fc1b34eef70ed7e711bfeea81
Diffstat (limited to 'QA/Checker')
-rw-r--r--QA/Checker/SConscript1
-rw-r--r--QA/Checker/checker.cpp46
2 files changed, 44 insertions, 3 deletions
diff --git a/QA/Checker/SConscript b/QA/Checker/SConscript
index f8a3ce4..3b81ca4 100644
--- a/QA/Checker/SConscript
+++ b/QA/Checker/SConscript
@@ -20,4 +20,5 @@ if env["TEST"] :
checker_env.UseFlags(env["SWIFTEN_FLAGS"])
checker_env.UseFlags(env["BOOST_FLAGS"])
checker_env.UseFlags(env["CPPUNIT_FLAGS"])
+ checker_env.UseFlags(env["GOOGLETEST_FLAGS"])
checker_env.Library("Checker", ["checker.cpp", "IO.cpp"])
diff --git a/QA/Checker/checker.cpp b/QA/Checker/checker.cpp
index f1186cc..b23e7ff 100644
--- a/QA/Checker/checker.cpp
+++ b/QA/Checker/checker.cpp
@@ -4,7 +4,12 @@
* See the COPYING file for more information.
*/
+#include <cstdlib>
+#include <fstream>
#include <string>
+#include <sstream>
+
+#include <gtest/gtest.h>
#include <cppunit/BriefTestProgressListener.h>
#include <cppunit/TextOutputter.h>
@@ -39,10 +44,33 @@ int main(int argc, char* argv[]) {
testsToRun.push_back(param);
}
}
+
if (testsToRun.empty()) {
testsToRun.push_back("");
}
+ // generate output filenames for XML test output
+ std::string gtestOutputFilename;
+ std::string cppunitOutputFilename;
+
+ if (outputXML) {
+ auto programName = std::string(argv[0]);
+
+ std::stringstream outFileStringStreamGTest("");
+ outFileStringStreamGTest << "xml:" << programName << "-report.gtest.xml";
+ gtestOutputFilename = outFileStringStreamGTest.str();
+
+ std::stringstream outFileStringStreamCppUnit("");
+ outFileStringStreamCppUnit << programName << "-report.cppunit.xml";
+ cppunitOutputFilename = outFileStringStreamCppUnit.str();
+ }
+
+ if (outputXML && (std::getenv("GTEST_OUTPUT") == nullptr)) {
+ ::testing::GTEST_FLAG(output) = gtestOutputFilename;
+ }
+
+ ::testing::InitGoogleTest(&argc, argv);
+
// Set up the listeners
CppUnit::TestResult controller;
@@ -75,13 +103,25 @@ int main(int argc, char* argv[]) {
// Output the results
if (outputXML) {
- CppUnit::XmlOutputter outputter(&result, std::cout);
- outputter.write();
+ std::ofstream cppUnitXUnitOutputFile;
+ cppUnitXUnitOutputFile.open(cppunitOutputFilename, std::ofstream::out | std::ofstream::trunc);
+ if (cppUnitXUnitOutputFile.is_open()) {
+ CppUnit::XmlOutputter outputter(&result, cppUnitXUnitOutputFile);
+ outputter.write();
+ }
+ else {
+ std::cerr << "Failed to overwrite " << cppunitOutputFilename << " output file." << std::endl;
+ return 1;
+ }
}
else {
CppUnit::TextOutputter outputter(&result, std::cerr);
outputter.write();
}
- return result.wasSuccessful() ? 0 : 1;
+ auto googleTestWasSuccessful = RUN_ALL_TESTS() == 0 ? true : false;
+
+ auto cppUnitWasSuccessful = result.wasSuccessful() ? true : false;
+
+ return (googleTestWasSuccessful && cppUnitWasSuccessful) ? 0 : 1;
}