From 1d00c3e8d1ad84262912581f09a21e11f94b8bc5 Mon Sep 17 00:00:00 2001 From: s1lentq Date: Mon, 28 Sep 2015 19:43:31 +0600 Subject: [PATCH] Implemented notify of warning about failure tests --- .../groovy/gradlecpp/CppUnitTestPlugin.groovy | 18 +++- .../include/cppunitlite/Assertions.h | 4 +- dep/cppunitlite/include/cppunitlite/Failure.h | 6 +- dep/cppunitlite/include/cppunitlite/Test.h | 3 + .../include/cppunitlite/TestResult.h | 4 + dep/cppunitlite/src/Assertions.cpp | 4 +- dep/cppunitlite/src/GradleAdapter.cpp | 25 ++++++ dep/cppunitlite/src/Test.cpp | 4 +- dep/cppunitlite/src/TestResult.cpp | 22 +++-- rehlds/unittests/crc32c_tests.cpp | 10 +-- rehlds/unittests/mathlib_tests.cpp | 90 ++----------------- 11 files changed, 86 insertions(+), 104 deletions(-) diff --git a/buildSrc/src/main/groovy/gradlecpp/CppUnitTestPlugin.groovy b/buildSrc/src/main/groovy/gradlecpp/CppUnitTestPlugin.groovy index 394460e..3616c90 100644 --- a/buildSrc/src/main/groovy/gradlecpp/CppUnitTestPlugin.groovy +++ b/buildSrc/src/main/groovy/gradlecpp/CppUnitTestPlugin.groovy @@ -25,6 +25,7 @@ class CppUnitTestPlugin implements Plugin { private static class TestExecStatus { boolean successful + boolean warning int exitCode String output long durationMsec @@ -119,7 +120,8 @@ class CppUnitTestPlugin implements Plugin { return new TestExecStatus( exitCode: exitVal, - successful: (exitVal == 0), + successful: (exitVal == 0 || exitVal == 3), + warning: (exitVal == 3), output: sout.toString(), durationMsec: endTime - startTime, cmdLine: cmdParams.join(' '), @@ -201,6 +203,7 @@ class CppUnitTestPlugin implements Plugin { println "Running ${root.test.size()} tests..." TeamCityIntegration.suiteStarted("unitTests.${libBin.name}") int failCount = 0; + int warnCount = 0; root.test.list().each { testInfo -> def testName = '' + testInfo.@name.text() def testGroup = '' + testInfo.@group.text() @@ -223,7 +226,14 @@ class CppUnitTestPlugin implements Plugin { failCount++ } else { if (!TeamCityIntegration.writeOutput) { - println " OK" + + if (testExecStatus.warning) { + println " WARNING" + dumpTestExecStatus(testExecStatus) + warnCount++ + } + else + println " OK" } } @@ -236,6 +246,10 @@ class CppUnitTestPlugin implements Plugin { if (failCount) { throw new GradleException("CPP unit tests: ${failCount} tests failed"); } + + else if (warnCount) { + println "CPP unit tests: ${warnCount} tests warnings"; + } } }) } diff --git a/dep/cppunitlite/include/cppunitlite/Assertions.h b/dep/cppunitlite/include/cppunitlite/Assertions.h index 7379e71..df0adc9 100644 --- a/dep/cppunitlite/include/cppunitlite/Assertions.h +++ b/dep/cppunitlite/include/cppunitlite/Assertions.h @@ -7,8 +7,8 @@ public: static void StringEquals(std::string message, std::string expected, std::string actual, const char* fileName, long lineNumber); static void StringEquals(std::string message, const char* expected, const char* actual, const char* fileName, long lineNumber); - - static void ConditionFailed(std::string message, std::string condition, const char* fileName, long lineNumber); + + static void ConditionFailed(std::string message, std::string condition, const char* fileName, long lineNumber, bool onlyWarning = false); static void LongEquals(std::string message, long expected, long actual, const char* fileName, long lineNumber); diff --git a/dep/cppunitlite/include/cppunitlite/Failure.h b/dep/cppunitlite/include/cppunitlite/Failure.h index 90a8e94..c024291 100644 --- a/dep/cppunitlite/include/cppunitlite/Failure.h +++ b/dep/cppunitlite/include/cppunitlite/Failure.h @@ -6,12 +6,13 @@ class TestFailException : public std::exception { public: - TestFailException(std::string message, std::string fileName, long lineNumber) { + TestFailException(std::string message, std::string fileName, long lineNumber, bool onlyWarning = false) { std::stringstream ss; ss << message << " at " << fileName << " line " << lineNumber; this->message = ss.str(); this->fileName = fileName; this->lineNumber = lineNumber; + this->warning = onlyWarning; } virtual ~TestFailException() throw() { @@ -21,6 +22,7 @@ public: std::string message; std::string fileName; long lineNumber; + bool warning; virtual const char * what() const throw() { return message.c_str(); @@ -35,6 +37,7 @@ public: this->message = e.message; this->fileName = e.fileName; this->lineNumber = e.lineNumber; + this->warning = e.warning; } Failure (std::string message, std::string testName) { @@ -48,6 +51,7 @@ public: std::string message; std::string fileName; long lineNumber; + bool warning; }; diff --git a/dep/cppunitlite/include/cppunitlite/Test.h b/dep/cppunitlite/include/cppunitlite/Test.h index e6c8d8f..2f153d2 100644 --- a/dep/cppunitlite/include/cppunitlite/Test.h +++ b/dep/cppunitlite/include/cppunitlite/Test.h @@ -55,6 +55,9 @@ protected: } \ } +#define CHECK_WARNING_OUT(msg, condition) { if (!(condition)) { Assertions::ConditionFailed(msg,#condition, __FILE__, __LINE__, true); return; \ + } \ +} #define ZSTR_EQUAL(msg,expected,actual) { \ Assertions::StringEquals((msg), (expected), (actual), __FILE__, __LINE__); \ diff --git a/dep/cppunitlite/include/cppunitlite/TestResult.h b/dep/cppunitlite/include/cppunitlite/TestResult.h index 86a9646..83a6d03 100644 --- a/dep/cppunitlite/include/cppunitlite/TestResult.h +++ b/dep/cppunitlite/include/cppunitlite/TestResult.h @@ -13,6 +13,10 @@ public: int getFailureCount() { return failureCount; } + int getWarningCount() { + return warningCount; + } private: int failureCount; + int warningCount; }; diff --git a/dep/cppunitlite/src/Assertions.cpp b/dep/cppunitlite/src/Assertions.cpp index 223a2b7..3564d2c 100644 --- a/dep/cppunitlite/src/Assertions.cpp +++ b/dep/cppunitlite/src/Assertions.cpp @@ -26,10 +26,10 @@ void Assertions::StringEquals(std::string message, const char* expected, const c } } -void Assertions::ConditionFailed(std::string message, std::string condition, const char* fileName, long lineNumber) { +void Assertions::ConditionFailed(std::string message, std::string condition, const char* fileName, long lineNumber, bool onlyWarning) { std::stringstream ss; ss << message << " (condition failed: " << condition << ")"; - throw TestFailException(ss.str(), std::string(fileName), lineNumber); + throw TestFailException(ss.str(), std::string(fileName), lineNumber, onlyWarning); } void Assertions::LongEquals(std::string message, long expected, long actual, const char* fileName, long lineNumber) { diff --git a/dep/cppunitlite/src/GradleAdapter.cpp b/dep/cppunitlite/src/GradleAdapter.cpp index 9c6cc23..42917b9 100644 --- a/dep/cppunitlite/src/GradleAdapter.cpp +++ b/dep/cppunitlite/src/GradleAdapter.cpp @@ -53,6 +53,9 @@ int GradleAdapter::runTest(const char* groupName, const char* testName) { if (result.getFailureCount()) { return 1; } + else if (result.getWarningCount()) { + return 3; + } else { return 0; } @@ -61,6 +64,7 @@ int GradleAdapter::runTest(const char* groupName, const char* testName) { int GradleAdapter::runGroup(const char* groupName) { Test* curTest = TestRegistry::getFirstTest(); int ranTests = 0; + int warnTest = 0; while (curTest != NULL) { if (strcmp(groupName, curTest->getGroup())) { curTest = curTest->getNext(); @@ -75,6 +79,11 @@ int GradleAdapter::runGroup(const char* groupName) { return 1; } + if (result.getWarningCount()) { + + warnTest++; + } + curTest = curTest->getNext(); } @@ -83,6 +92,11 @@ int GradleAdapter::runGroup(const char* groupName) { return 2; } + if (warnTest > 0) { + printf("There were no test failures, but with warnings: %d; Tests executed: %d\n", warnTest, ranTests); + return 3; + } + printf("There were no test failures; Tests executed: %d\n", ranTests); return 0; } @@ -90,6 +104,7 @@ int GradleAdapter::runGroup(const char* groupName) { int GradleAdapter::runAllTests() { Test* curTest = TestRegistry::getFirstTest(); int ranTests = 0; + int warnTest = 0; while (curTest != NULL) { TestResult result; curTest->run(result); @@ -99,9 +114,19 @@ int GradleAdapter::runAllTests() { return 1; } + if (result.getWarningCount()) { + + warnTest++; + } + curTest = curTest->getNext(); } + if (warnTest > 0) { + printf("There were no test failures, but with warnings: %d; Tests executed: %d\n", warnTest, ranTests); + return 3; + } + printf("There were no test failures; Tests executed: %d\n", ranTests); return 0; } diff --git a/dep/cppunitlite/src/Test.cpp b/dep/cppunitlite/src/Test.cpp index a39d5d7..216aec8 100644 --- a/dep/cppunitlite/src/Test.cpp +++ b/dep/cppunitlite/src/Test.cpp @@ -30,8 +30,8 @@ void Test::setNext(Test *test) void Test::run(TestResult &result) { try { runInternal(); - } catch (TestFailException *e) { - result.addFailure(Failure(*e, name_)); + } catch (TestFailException &e) { + result.addFailure(Failure(e, name_)); } catch (std::exception &e) { std::stringstream ss; ss << "unexpected exception " << e.what(); diff --git a/dep/cppunitlite/src/TestResult.cpp b/dep/cppunitlite/src/TestResult.cpp index e593767..b418b6c 100644 --- a/dep/cppunitlite/src/TestResult.cpp +++ b/dep/cppunitlite/src/TestResult.cpp @@ -7,7 +7,7 @@ TestResult::TestResult () - : failureCount (0) + : failureCount (0), warningCount (0) { } @@ -16,13 +16,17 @@ void TestResult::testsStarted () { } - void TestResult::addFailure (const Failure& failure) { std::stringstream ss; - ss << "Failure in test '" << failure.testName << "' :" << failure.message; + ss << (failure.warning ? "Warning in test '" : "Failure in test '") << failure.testName << "' :" << failure.message; std::cout << ss.str() << std::endl; std::cout.flush(); - failureCount++; + + if (failure.warning) { + warningCount++; + } + else + failureCount++; } @@ -30,9 +34,17 @@ void TestResult::testsEnded () { std::stringstream ss; if (failureCount > 0) { ss << "There were " << failureCount << " failures"; - } else { + if (warningCount > 0) { + ss << ", and " << warningCount << " warnings"; + } + } + else if (warningCount > 0) { + ss << "There were " << warningCount << " warnings"; + } + else { ss << "There were no test failures"; } + std::cout << ss.str() << std::endl; std::cout.flush(); } diff --git a/rehlds/unittests/crc32c_tests.cpp b/rehlds/unittests/crc32c_tests.cpp index 7c7c044..885e7b8 100644 --- a/rehlds/unittests/crc32c_tests.cpp +++ b/rehlds/unittests/crc32c_tests.cpp @@ -6,15 +6,7 @@ TEST(CRC32C_Hash, CRC32C, 1000) { Sys_CheckCpuInstructionsSupport(); - //CHECK("SSE4.1 Support", cpuinfo.sse4_1); - if (!cpuinfo.sse4_2) - { - std::stringstream ss; - ss << "Test '" __FUNCTION__ "' not runned: sse 4.2 doesn't supported"; - std::cout << ss.str() << std::endl; - std::cout.flush(); - return; - } + CHECK_WARNING_OUT("SSE4.1 Support", cpuinfo.sse4_1); struct testdata_t { const char* src; diff --git a/rehlds/unittests/mathlib_tests.cpp b/rehlds/unittests/mathlib_tests.cpp index 203e0f6..ceeb62c 100644 --- a/rehlds/unittests/mathlib_tests.cpp +++ b/rehlds/unittests/mathlib_tests.cpp @@ -5,15 +5,7 @@ TEST(AngleVectorsTest, MathLib, 1000) { Sys_CheckCpuInstructionsSupport(); - //CHECK("SSE4.1 Support", cpuinfo.sse4_1); - if (!cpuinfo.sse4_1) - { - std::stringstream ss; - ss << "Test '" __FUNCTION__ "' not runned: sse 4.1 doesn't supported"; - std::cout << ss.str() << std::endl; - std::cout.flush(); - return; - } + CHECK_WARNING_OUT("SSE4.1 Support", cpuinfo.sse4_1); struct testdata_t { vec3_t angles; @@ -50,15 +42,7 @@ TEST(AngleVectorsTest, MathLib, 1000) { TEST(AngleVectorsTransposeTest, MathLib, 1000) { Sys_CheckCpuInstructionsSupport(); - //CHECK("SSE4.1 Support", cpuinfo.sse4_1); - if (!cpuinfo.sse4_1) - { - std::stringstream ss; - ss << "Test '" __FUNCTION__ "' not runned: sse 4.1 doesn't supported"; - std::cout << ss.str() << std::endl; - std::cout.flush(); - return; - } + CHECK_WARNING_OUT("SSE4.1 Support", cpuinfo.sse4_1); struct testdata_t { vec3_t angles; @@ -95,15 +79,7 @@ TEST(AngleVectorsTransposeTest, MathLib, 1000) { TEST(AngleMatrixTest, MathLib, 1000) { Sys_CheckCpuInstructionsSupport(); - //CHECK("SSE4.1 Support", cpuinfo.sse4_1); - if (!cpuinfo.sse4_1) - { - std::stringstream ss; - ss << "Test '" __FUNCTION__ "' not runned: sse 4.1 doesn't supported"; - std::cout << ss.str() << std::endl; - std::cout.flush(); - return; - } + CHECK_WARNING_OUT("SSE4.1 Support", cpuinfo.sse4_1); struct testdata_t { vec3_t angles; @@ -145,15 +121,7 @@ TEST(AngleMatrixTest, MathLib, 1000) { TEST(DotProductTest, MathLib, 1000) { Sys_CheckCpuInstructionsSupport(); - //CHECK("SSE4.1 Support", cpuinfo.sse4_1); - if (!cpuinfo.sse4_1) - { - std::stringstream ss; - ss << "Test '" __FUNCTION__ "' not runned: sse 4.1 doesn't supported"; - std::cout << ss.str() << std::endl; - std::cout.flush(); - return; - } + CHECK_WARNING_OUT("SSE4.1 Support", cpuinfo.sse4_1); struct testdata_t { vec3_t v1; @@ -179,15 +147,7 @@ TEST(DotProductTest, MathLib, 1000) { TEST(CrossProductTest, MathLib, 1000) { Sys_CheckCpuInstructionsSupport(); - //CHECK("SSE4.1 Support", cpuinfo.sse4_1); - if (!cpuinfo.sse4_1) - { - std::stringstream ss; - ss << "Test '" __FUNCTION__ "' not runned: sse 4.1 doesn't supported"; - std::cout << ss.str() << std::endl; - std::cout.flush(); - return; - } + CHECK_WARNING_OUT("SSE4.1 Support", cpuinfo.sse4_1); struct testdata_t { vec3_t v1; @@ -217,15 +177,7 @@ TEST(CrossProductTest, MathLib, 1000) { TEST(LengthTest, MathLib, 1000) { Sys_CheckCpuInstructionsSupport(); - //CHECK("SSE4.1 Support", cpuinfo.sse4_1); - if (!cpuinfo.sse4_1) - { - std::stringstream ss; - ss << "Test '" __FUNCTION__ "' not runned: sse 4.1 doesn't supported"; - std::cout << ss.str() << std::endl; - std::cout.flush(); - return; - } + CHECK_WARNING_OUT("SSE4.1 Support", cpuinfo.sse4_1); struct testdata_t { vec3_t v; @@ -250,15 +202,7 @@ TEST(LengthTest, MathLib, 1000) { TEST(Length2DTest, MathLib, 1000) { Sys_CheckCpuInstructionsSupport(); - //CHECK("SSE4.1 Support", cpuinfo.sse4_1); - if (!cpuinfo.sse4_1) - { - std::stringstream ss; - ss << "Test '" __FUNCTION__ "' not runned: sse 4.1 doesn't supported"; - std::cout << ss.str() << std::endl; - std::cout.flush(); - return; - } + CHECK_WARNING_OUT("SSE4.1 Support", cpuinfo.sse4_1); struct testdata_t { vec3_t v; @@ -283,15 +227,7 @@ TEST(Length2DTest, MathLib, 1000) { TEST(VectorNormalizeTest, MathLib, 1000) { Sys_CheckCpuInstructionsSupport(); - //CHECK("SSE4.1 Support", cpuinfo.sse4_1); - if (!cpuinfo.sse4_1) - { - std::stringstream ss; - ss << "Test '" __FUNCTION__ "' not runned: sse 4.1 doesn't supported"; - std::cout << ss.str() << std::endl; - std::cout.flush(); - return; - } + CHECK_WARNING_OUT("SSE4.1 Support", cpuinfo.sse4_1); struct testdata_t { vec3_t vecIn; @@ -322,15 +258,7 @@ TEST(VectorNormalizeTest, MathLib, 1000) { TEST(VectorAnglesTest, MathLib, 1000) { Sys_CheckCpuInstructionsSupport(); - //CHECK("SSE4.1 Support", cpuinfo.sse4_1); - if (!cpuinfo.sse4_1) - { - std::stringstream ss; - ss << "Test '" __FUNCTION__ "' not runned: sse 4.1 doesn't supported"; - std::cout << ss.str() << std::endl; - std::cout.flush(); - return; - } + CHECK_WARNING_OUT("SSE4.1 Support", cpuinfo.sse4_1); struct testdata_t { vec3_t forward;