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
# this target also includes building & running of 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
cmake $OPENRCT2_CMAKE_OPTS ..
# NOT the same variable as above

View File

@ -48,6 +48,11 @@ namespace TestPaint
void ResetSupportHeights();
}
enum Verbosity {
QUIET,
NORMAL,
};
extern "C"
{
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);
uint8 TestTrack::TestPaintTrackElement(uint8 rideType, uint8 trackType) {
uint8 TestTrack::TestPaintTrackElement(uint8 rideType, uint8 trackType, std::string *out) {
if (!Utils::rideSupportsTrackType(rideType, trackType)) {
return TEST_FAILED;
}
@ -246,7 +246,7 @@ uint8 TestTrack::TestPaintTrackElement(uint8 rideType, uint8 trackType) {
retVal = function(rideType, trackType, trackSequence, &error);
if (retVal != TEST_SUCCESS) {
printf("%s\n", error.c_str());
*out += error + "\n";
return retVal;
}
}

View File

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