2
0
mirror of https://github.com/rehlds/rehlds.git synced 2025-01-01 01:25:38 +03:00

Merge pull request #69 from s1lentq/master

Implemented notify of warning about failure tests
This commit is contained in:
theAsmodai 2015-09-28 16:59:52 +03:00
commit 7975be530d
11 changed files with 86 additions and 104 deletions

View File

@ -25,6 +25,7 @@ class CppUnitTestPlugin implements Plugin<Project> {
private static class TestExecStatus {
boolean successful
boolean warning
int exitCode
String output
long durationMsec
@ -119,7 +120,8 @@ class CppUnitTestPlugin implements Plugin<Project> {
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<Project> {
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<Project> {
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<Project> {
if (failCount) {
throw new GradleException("CPP unit tests: ${failCount} tests failed");
}
else if (warnCount) {
println "CPP unit tests: ${warnCount} tests warnings";
}
}
})
}

View File

@ -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);

View File

@ -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;
};

View File

@ -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__); \

View File

@ -13,6 +13,10 @@ public:
int getFailureCount() {
return failureCount;
}
int getWarningCount() {
return warningCount;
}
private:
int failureCount;
int warningCount;
};

View File

@ -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) {

View File

@ -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;
}

View File

@ -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();

View File

@ -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();
}

View File

@ -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;

View File

@ -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;