Make testpaint a lot more quiet

This commit is contained in:
Marijn van der Werf 2016-10-19 01:55:18 +02:00
parent cdffaa0712
commit 1be2dd996c
5 changed files with 79 additions and 50 deletions

View File

@ -75,7 +75,7 @@ pushd build
# NOT the same variable as above # NOT the same variable as above
# this target also includes building & running of testpaint # this target also includes building & running of testpaint
make $OPENRCT2_MAKE_OPTS testpaint make $OPENRCT2_MAKE_OPTS testpaint
./testpaint --silent || if [[ $? -eq 1 ]] ; then echo Allowing failed tests to pass ; else false; fi ./testpaint --quiet || if [[ $? -eq 1 ]] ; then echo Allowing failed tests to pass ; else false; fi
else else
cmake $OPENRCT2_CMAKE_OPTS .. cmake $OPENRCT2_CMAKE_OPTS ..
# NOT the same variable as above # NOT the same variable as above

View File

@ -48,6 +48,11 @@ namespace TestPaint
void ResetSupportHeights(); void ResetSupportHeights();
} }
enum Verbosity {
QUIET,
NORMAL,
};
extern "C" extern "C"
{ {
int generatePaintCode(uint8 rideType); int generatePaintCode(uint8 rideType);

View File

@ -215,7 +215,7 @@ static uint8 TestTrackElementSideTunnels(uint8 rideType, uint8 trackType, uint8
static uint8 TestTrackElementVerticalTunnels(uint8 rideType, uint8 trackType, uint8 trackSequence, std::string *error); static uint8 TestTrackElementVerticalTunnels(uint8 rideType, uint8 trackType, uint8 trackSequence, std::string *error);
uint8 TestTrack::TestPaintTrackElement(uint8 rideType, uint8 trackType) { uint8 TestTrack::TestPaintTrackElement(uint8 rideType, uint8 trackType, std::string *out) {
if (!Utils::rideSupportsTrackType(rideType, trackType)) { if (!Utils::rideSupportsTrackType(rideType, trackType)) {
return TEST_FAILED; return TEST_FAILED;
} }
@ -246,7 +246,7 @@ uint8 TestTrack::TestPaintTrackElement(uint8 rideType, uint8 trackType) {
retVal = function(rideType, trackType, trackSequence, &error); retVal = function(rideType, trackType, trackSequence, &error);
if (retVal != TEST_SUCCESS) { if (retVal != TEST_SUCCESS) {
printf("%s\n", error.c_str()); *out += error + "\n";
return retVal; return retVal;
} }
} }

View File

@ -22,5 +22,5 @@
class TestTrack { class TestTrack {
public: public:
static uint8 TestPaintTrackElement(uint8 rideType, uint8 trackType); static uint8 TestPaintTrackElement(uint8 rideType, uint8 trackType, std::string *out);
}; };

View File

@ -49,6 +49,7 @@ enum CLIColour {
}; };
bool gTestColor = true; bool gTestColor = true;
Verbosity _verbosity = NORMAL;
static bool CStringEquals(const char *lhs, const char *rhs) { static bool CStringEquals(const char *lhs, const char *rhs) {
if (lhs == NULL) return rhs == NULL; if (lhs == NULL) return rhs == NULL;
@ -126,10 +127,9 @@ static WORD GetWindowsConsoleAttribute(CLIColour color, WORD defaultAttr)
#endif #endif
static void ColouredPrintF(CLIColour colour, const char* fmt, ...) static void Write_VA(Verbosity verbosity, CLIColour colour, const char *fmt, va_list args)
{ {
va_list args; if (_verbosity < verbosity) return;
va_start(args, fmt);
COLOUR_METHOD colourMethod = GetColourMethod(); COLOUR_METHOD colourMethod = GetColourMethod();
@ -148,6 +148,37 @@ static void ColouredPrintF(CLIColour colour, const char* fmt, ...)
SetConsoleTextAttribute(hStdOut, defaultAttr); SetConsoleTextAttribute(hStdOut, defaultAttr);
#endif #endif
} }
}
static void Write(Verbosity verbosity, CLIColour colour, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
Write_VA(verbosity, colour, fmt, args);
va_end(args);
}
static void Write(Verbosity verbosity, const char * fmt, ...)
{
va_list args;
va_start(args, fmt);
Write_VA(verbosity, DEFAULT, fmt, args);
va_end(args);
}
static void Write(CLIColour colour, const char * fmt, ...)
{
va_list args;
va_start(args, fmt);
Write_VA(NORMAL, colour, fmt, args);
va_end(args);
}
static void Write(const char * fmt, ...)
{
va_list args;
va_start(args, fmt);
Write_VA(NORMAL, DEFAULT, fmt, args);
va_end(args); va_end(args);
} }
@ -354,7 +385,7 @@ static void PrintRideTypes()
colour = CLIColour::GREEN; colour = CLIColour::GREEN;
} }
ColouredPrintF(colour, "%2d: %-30s%s\n", rideType, rideName, status); Write(colour, "%2d: %-30s%s\n", rideType, rideName, status);
} }
} }
@ -398,7 +429,6 @@ int main(int argc, char *argv[]) {
std::vector<TestCase> testCases; std::vector<TestCase> testCases;
bool silent = false;
bool generate = false; bool generate = false;
uint8 specificRideType = 0xFF; uint8 specificRideType = 0xFF;
for (int i = 0; i < argc; ++i) { for (int i = 0; i < argc; ++i) {
@ -406,8 +436,8 @@ int main(int argc, char *argv[]) {
if (strcmp(arg, "--gtest_color=no") == 0) { if (strcmp(arg, "--gtest_color=no") == 0) {
gTestColor = false; gTestColor = false;
} }
else if (strcmp(arg, "--silent") == 0) { else if (strcmp(arg, "--quiet") == 0) {
silent = true; _verbosity = Verbosity::QUIET;
} }
else if (strcmp(arg, "--ride-type") == 0) { else if (strcmp(arg, "--ride-type") == 0) {
if (i + 1 < argc) { if (i + 1 < argc) {
@ -466,11 +496,11 @@ int main(int argc, char *argv[]) {
testCount += tc.trackTypes.size(); testCount += tc.trackTypes.size();
} }
ColouredPrintF(CLIColour::GREEN, "[==========] "); Write(CLIColour::GREEN, "[==========] ");
printf("Running %d tests from %d test cases.\n", testCount, testCaseCount); Write("Running %d tests from %d test cases.\n", testCount, testCaseCount);
ColouredPrintF(CLIColour::GREEN, "[----------] "); Write(CLIColour::GREEN, "[----------] ");
printf("Global test environment set-up.\n"); Write("Global test environment set-up.\n");
openrct2_setup_rct2_segment(); openrct2_setup_rct2_segment();
PaintIntercept::InitHooks(); PaintIntercept::InitHooks();
@ -478,8 +508,8 @@ int main(int argc, char *argv[]) {
std::vector<utf8string> failures; std::vector<utf8string> failures;
for (auto &&tc : testCases) { for (auto &&tc : testCases) {
const utf8string rideTypeName = RideNames[tc.rideType]; const utf8string rideTypeName = RideNames[tc.rideType];
ColouredPrintF(CLIColour::GREEN, "[----------] "); Write(CLIColour::GREEN, "[----------] ");
printf("%d tests from %s\n", (int)tc.trackTypes.size(), rideTypeName); Write("%d tests from %s\n", (int)tc.trackTypes.size(), rideTypeName);
for (auto &&trackType : tc.trackTypes) { for (auto &&trackType : tc.trackTypes) {
utf8string trackTypeName; utf8string trackTypeName;
@ -489,71 +519,65 @@ int main(int argc, char *argv[]) {
trackTypeName = TrackNames[trackType]; trackTypeName = TrackNames[trackType];
} }
Write(CLIColour::GREEN, "[ RUN ] ");
Write("%s.%s\n", rideTypeName, trackTypeName);
if (!silent) { std::string out;
ColouredPrintF(CLIColour::GREEN, "[ RUN ] "); int retVal = TestTrack::TestPaintTrackElement(tc.rideType, trackType, &out);
printf("%s.%s\n", rideTypeName, trackTypeName); Write("%s", out.c_str());
}
int retVal = TestTrack::TestPaintTrackElement(tc.rideType, trackType);
switch (retVal) { switch (retVal) {
case TEST_SUCCESS: case TEST_SUCCESS:
if (!silent) { Write(CLIColour::GREEN, "[ OK ] ");
ColouredPrintF(CLIColour::GREEN, "[ OK ] "); Write("%s.%s (0 ms)\n", rideTypeName, trackTypeName);
printf("%s.%s (0 ms)\n", rideTypeName, trackTypeName);
}
successCount++; successCount++;
break; break;
case TEST_SKIPPED: case TEST_SKIPPED:
printf("Skipped\n"); Write("Skipped\n");
// Outputting this as OK because CLion only allows FAILED or OK // Outputting this as OK because CLion only allows FAILED or OK
ColouredPrintF(CLIColour::YELLOW, "[ OK ] "); Write(CLIColour::YELLOW, "[ OK ] ");
printf("%s.%s (0 ms)\n", rideTypeName, trackTypeName); Write("%s.%s (0 ms)\n", rideTypeName, trackTypeName);
successCount++; successCount++;
break; break;
case TEST_FAILED: case TEST_FAILED:
if (silent) {
ColouredPrintF(CLIColour::GREEN, "[ RUN ] ");
printf("%s.%s\n", rideTypeName, trackTypeName);
}
utf8string testCaseName = new utf8[64]; utf8string testCaseName = new utf8[64];
snprintf(testCaseName, 64, "%s.%s", rideTypeName, trackTypeName); snprintf(testCaseName, 64, "%s.%s", rideTypeName, trackTypeName);
ColouredPrintF(CLIColour::RED, "[ FAILED ] "); Write(CLIColour::RED, "[ FAILED ] ");
printf("%s (0 ms)\n", testCaseName); Write("%s (0 ms)\n", testCaseName);
failures.push_back(testCaseName); failures.push_back(testCaseName);
break; break;
} }
} }
ColouredPrintF(CLIColour::GREEN, "[----------] "); Write(CLIColour::GREEN, "[----------] ");
printf("%d tests from %s (0 ms total)\n", (int)tc.trackTypes.size(), rideTypeName); Write("%d tests from %s (0 ms total)\n", (int)tc.trackTypes.size(), rideTypeName);
} }
printf("\n"); Write("\n");
ColouredPrintF(CLIColour::GREEN, "[----------] "); Write(CLIColour::GREEN, "[----------] ");
printf("Global test environment tear-down\n"); Write("Global test environment tear-down\n");
ColouredPrintF(CLIColour::GREEN, "[==========] "); Write(CLIColour::GREEN, "[==========] ");
printf("%d tests from %d test cases ran. (0 ms total).\n", testCount, testCaseCount); Write("%d tests from %d test cases ran. (0 ms total).\n", testCount, testCaseCount);
ColouredPrintF(CLIColour::GREEN, "[ PASSED ] "); Write(Verbosity::QUIET, CLIColour::GREEN, "[ PASSED ] ");
printf("%d tests.\n", successCount); Write(Verbosity::QUIET, "%d tests.\n", successCount);
if (failures.size() > 0) { if (failures.size() > 0) {
ColouredPrintF(CLIColour::RED, "[ FAILED ] "); Write(Verbosity::QUIET, CLIColour::RED, "[ FAILED ] ");
printf("%d tests, listed below:\n", (int)failures.size()); Write(Verbosity::QUIET, "%d tests, listed below:\n", (int)failures.size());
for (auto &&failure : failures) { for (auto &&failure : failures) {
ColouredPrintF(CLIColour::RED, "[ FAILED ] "); Write(Verbosity::QUIET, CLIColour::RED, "[ FAILED ] ");
printf("%s\n", failure); Write(Verbosity::QUIET, "%s\n", failure);
delete [] failure; delete [] failure;
} }
printf("\n"); Write(Verbosity::QUIET, "\n");
printf("%d FAILED TESTS\n", (int)failures.size()); Write(Verbosity::QUIET, "%d FAILED TESTS\n", (int)failures.size());
return 1; return 1;
} }