Commit 891b80a6 authored by Markus Kauppila's avatar Markus Kauppila

Added command option --version

parent ec1a464d
...@@ -9,17 +9,24 @@ ...@@ -9,17 +9,24 @@
#include "plain_logger.h" #include "plain_logger.h"
static int indentLevel;
/*! /*!
* Prints out the output of the logger * Prints out the output of the logger
* *
* \param message The message to be printed out * \param message The message to be printed out
*/ */
int int
Output(const char *message, ...) Output(const int currentIdentLevel, const char *message, ...)
{ {
va_list list; va_list list;
va_start(list, message); va_start(list, message);
int ident = 0;
for( ; ident < currentIdentLevel; ++ident) {
fprintf(stdout, " "); // \todo make configurable?
}
char buffer[1024]; char buffer[1024];
SDL_vsnprintf(buffer, sizeof(buffer), message, list); SDL_vsnprintf(buffer, sizeof(buffer), message, list);
...@@ -46,30 +53,32 @@ void ...@@ -46,30 +53,32 @@ void
PlainRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCount, PlainRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCount,
time_t endTime, double totalRuntime) time_t endTime, double totalRuntime)
{ {
Output("\nRan %d tests in %0.5f seconds from %d suites.", Output(indentLevel, "\nRan %d tests in %0.5f seconds from %d suites.",
testCount, totalRuntime, suiteCount); testCount, totalRuntime, suiteCount);
Output("%d tests passed", testPassCount); Output(indentLevel, "%d tests passed", testPassCount);
Output("%d tests failed", testFailCount); Output(indentLevel, "%d tests failed", testFailCount);
} }
void void
PlainSuiteStarted(const char *suiteName, time_t eventTime) PlainSuiteStarted(const char *suiteName, time_t eventTime)
{ {
Output("Executing tests from %s", suiteName); Output(indentLevel++, "Executing tests from %s", suiteName);
} }
void void
PlainSuiteEnded(int testsPassed, int testsFailed, int testsSkipped, PlainSuiteEnded(int testsPassed, int testsFailed, int testsSkipped,
time_t endTime, double totalRuntime) time_t endTime, double totalRuntime)
{ {
Output("Suite executed. %d passed, %d failed and %d skipped", testsPassed, testsFailed, testsSkipped); Output(--indentLevel, "Suite executed. %d passed, %d failed and %d skipped. Total runtime %0.5f seconds",
testsPassed, testsFailed, testsSkipped, totalRuntime);
Output(indentLevel, "");
} }
void void
PlainTestStarted(const char *testName, const char *suiteName, const char *testDescription, time_t startTime) PlainTestStarted(const char *testName, const char *suiteName, const char *testDescription, time_t startTime)
{ {
Output("%s (in %s) started", testName, suiteName); Output(indentLevel++, "%s (in %s) started", testName, suiteName);
} }
void void
...@@ -78,12 +87,12 @@ PlainTestEnded(const char *testName, const char *suiteName, ...@@ -78,12 +87,12 @@ PlainTestEnded(const char *testName, const char *suiteName,
{ {
if(testResult) { if(testResult) {
if(testResult == 2) { if(testResult == 2) {
Output("%s: failed -> no assert", testName); Output(--indentLevel, "%s: failed -> no assert", testName);
} else { } else {
Output("%s: failed", testName); Output(--indentLevel, "%s: failed", testName);
} }
} else { } else {
Output("%s: ok", testName); Output(--indentLevel, "%s: ok", testName);
} }
} }
...@@ -92,7 +101,7 @@ PlainAssert(const char *assertName, int assertResult, const char *assertMessage, ...@@ -92,7 +101,7 @@ PlainAssert(const char *assertName, int assertResult, const char *assertMessage,
time_t eventTime) time_t eventTime)
{ {
const char *result = (assertResult) ? "passed" : "failed"; const char *result = (assertResult) ? "passed" : "failed";
Output("%s: %s", assertName, assertMessage); Output(indentLevel, "%s: %s", assertName, assertMessage);
} }
void void
...@@ -100,20 +109,20 @@ PlainAssertWithValues(const char *assertName, int assertResult, const char *asse ...@@ -100,20 +109,20 @@ PlainAssertWithValues(const char *assertName, int assertResult, const char *asse
int actualValue, int excpected, time_t eventTime) int actualValue, int excpected, time_t eventTime)
{ {
const char *result = (assertResult) ? "passed" : "failed"; const char *result = (assertResult) ? "passed" : "failed";
Output("%s %d: %s", assertName, assertResult, assertMessage); Output(indentLevel, "%s %d: %s", assertName, assertResult, assertMessage);
} }
void void
PlainAssertSummary(int numAsserts, int numAssertsFailed, int numAssertsPass, time_t eventTime) PlainAssertSummary(int numAsserts, int numAssertsFailed, int numAssertsPass, time_t eventTime)
{ {
Output("Assert summary: %d failed, %d passed (total: %d)", Output(indentLevel, "Assert summary: %d failed, %d passed (total: %d)",
numAssertsFailed, numAssertsPass, numAsserts); numAssertsFailed, numAssertsPass, numAsserts);
} }
void void
PlainLog(const char *logMessage, time_t eventTime) PlainLog(const char *logMessage, time_t eventTime)
{ {
Output("%s %d", logMessage, eventTime); Output(indentLevel, "%s %d", logMessage, eventTime);
} }
#endif #endif
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
#include <sys/types.h> #include <sys/types.h>
#include "config.h"
#include "SDL_test.h" #include "SDL_test.h"
#include "logger.h" #include "logger.h"
...@@ -547,7 +549,7 @@ ExecuteTest(TestCase *testItem) { ...@@ -547,7 +549,7 @@ ExecuteTest(TestCase *testItem) {
* Prints usage information * Prints usage information
*/ */
void void
printUsage() { PrintUsage() {
printf("Usage: ./runner [--in-proc] [--suite SUITE] [--test TEST]\n"); printf("Usage: ./runner [--in-proc] [--suite SUITE] [--test TEST]\n");
printf(" [--name-contains SUBSTR] [--show-tests]\n"); printf(" [--name-contains SUBSTR] [--show-tests]\n");
printf(" [--xml] [--xsl [STYLESHEET]] [--help]\n"); printf(" [--xml] [--xsl [STYLESHEET]] [--help]\n");
...@@ -597,7 +599,7 @@ ParseOptions(int argc, char *argv[]) ...@@ -597,7 +599,7 @@ ParseOptions(int argc, char *argv[])
testName = argv[++i]; testName = argv[++i];
} else { } else {
printf("runner: test name is missing\n"); printf("runner: test name is missing\n");
printUsage(); PrintUsage();
exit(1); exit(1);
} }
...@@ -625,7 +627,7 @@ ParseOptions(int argc, char *argv[]) ...@@ -625,7 +627,7 @@ ParseOptions(int argc, char *argv[])
substring = argv[++i]; substring = argv[++i];
} else { } else {
printf("runner: substring of test name is missing\n"); printf("runner: substring of test name is missing\n");
printUsage(); PrintUsage();
exit(1); exit(1);
} }
...@@ -640,20 +642,24 @@ ParseOptions(int argc, char *argv[]) ...@@ -640,20 +642,24 @@ ParseOptions(int argc, char *argv[])
suiteName = argv[++i]; suiteName = argv[++i];
} else { } else {
printf("runner: suite name is missing\n"); printf("runner: suite name is missing\n");
printUsage(); PrintUsage();
exit(1); exit(1);
} }
memset(selected_suite_name, 0, NAME_BUFFER_SIZE); memset(selected_suite_name, 0, NAME_BUFFER_SIZE);
strcpy(selected_suite_name, suiteName); strcpy(selected_suite_name, suiteName);
} }
else if(SDL_strcmp(arg, "--version") == 0) {
fprintf(stdout, "SDL test harness (version %s)\n", PACKAGE_VERSION);
exit(0);
}
else if(SDL_strcmp(arg, "--help") == 0 || SDL_strcmp(arg, "-h") == 0) { else if(SDL_strcmp(arg, "--help") == 0 || SDL_strcmp(arg, "-h") == 0) {
printUsage(); PrintUsage();
exit(0); exit(0);
} }
else { else {
printf("runner: unknown command '%s'\n", arg); printf("runner: unknown command '%s'\n", arg);
printUsage(); PrintUsage();
exit(0); exit(0);
} }
} }
......
...@@ -85,7 +85,7 @@ XMLOutputter(const int currentIdentLevel, ...@@ -85,7 +85,7 @@ XMLOutputter(const int currentIdentLevel,
if(ValidateString(message)) { if(ValidateString(message)) {
int ident = 0; int ident = 0;
for( ; ident < currentIdentLevel && prevEOL; ++ident) { for( ; ident < currentIdentLevel && prevEOL; ++ident) {
printf(" "); // \todo make configurable? fprintf(stdout, " "); // \todo make configurable?
} }
prevEOL = EOL; prevEOL = EOL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment