Added command option --version
authorMarkus Kauppila <markus.kauppila@gmail.com>
Mon, 04 Jul 2011 20:46:06 +0300
changeset 5742 443d356b5af8
parent 5741 0e08b8021648
child 5743 3f79a693acd3
Added command option --version
test/test-automation/plain_logger.c
test/test-automation/runner.c
test/test-automation/xml_logger.c
--- a/test/test-automation/plain_logger.c	Mon Jul 04 17:23:20 2011 +0300
+++ b/test/test-automation/plain_logger.c	Mon Jul 04 20:46:06 2011 +0300
@@ -9,17 +9,24 @@
 #include "plain_logger.h"
 
 
+static int indentLevel;
+
 /*!
  * Prints out the output of the logger
  *
  * \param message The message to be printed out
  */
 int
-Output(const char *message, ...)
+Output(const int currentIdentLevel, const char *message, ...)
 {
 	va_list list;
 	va_start(list, message);
 
+	int ident = 0;
+	for( ; ident < currentIdentLevel; ++ident) {
+		fprintf(stdout, "  "); // \todo make configurable?
+	}
+
 	char buffer[1024];
 	SDL_vsnprintf(buffer, sizeof(buffer), message, list);
 
@@ -46,30 +53,32 @@
 PlainRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCount,
               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);
 
-	Output("%d tests passed", testPassCount);
-	Output("%d tests failed", testFailCount);
+	Output(indentLevel, "%d tests passed", testPassCount);
+	Output(indentLevel, "%d tests failed", testFailCount);
 }
 
 void
 PlainSuiteStarted(const char *suiteName, time_t eventTime)
 {
-	Output("Executing tests from %s", suiteName);
+	Output(indentLevel++, "Executing tests from %s", suiteName);
 }
 
 void
 PlainSuiteEnded(int testsPassed, int testsFailed, int testsSkipped,
            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
 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
@@ -78,12 +87,12 @@
 {
 	if(testResult) {
 		if(testResult == 2) {
-			Output("%s: failed -> no assert", testName);
+			Output(--indentLevel, "%s: failed -> no assert", testName);
 		} else {
-			Output("%s: failed", testName);
+			Output(--indentLevel, "%s: failed", testName);
 		}
 	} else {
-		Output("%s: ok", testName);
+		Output(--indentLevel, "%s: ok", testName);
 	}
 }
 
@@ -92,7 +101,7 @@
 		time_t eventTime)
 {
 	const char *result = (assertResult) ? "passed" : "failed";
-	Output("%s: %s", assertName, assertMessage);
+	Output(indentLevel, "%s: %s", assertName, assertMessage);
 }
 
 void
@@ -100,20 +109,20 @@
 		int actualValue, int excpected, time_t eventTime)
 {
 	const char *result = (assertResult) ? "passed" : "failed";
-	Output("%s %d: %s", assertName, assertResult, assertMessage);
+	Output(indentLevel, "%s %d: %s", assertName, assertResult, assertMessage);
 }
 
 void
 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);
 }
 
 void
 PlainLog(const char *logMessage, time_t eventTime)
 {
-	Output("%s %d", logMessage, eventTime);
+	Output(indentLevel, "%s %d", logMessage, eventTime);
 }
 
 #endif
--- a/test/test-automation/runner.c	Mon Jul 04 17:23:20 2011 +0300
+++ b/test/test-automation/runner.c	Mon Jul 04 20:46:06 2011 +0300
@@ -28,6 +28,8 @@
 
 #include <sys/types.h>
 
+#include "config.h"
+
 #include "SDL_test.h"
 #include "logger.h"
 
@@ -547,7 +549,7 @@
  * Prints usage information
  */
 void
-printUsage() {
+PrintUsage() {
 	  printf("Usage: ./runner [--in-proc] [--suite SUITE] [--test TEST]\n");
 	  printf("                [--name-contains SUBSTR] [--show-tests]\n");
 	  printf("                [--xml] [--xsl [STYLESHEET]] [--help]\n");
@@ -597,7 +599,7 @@
     		  testName = argv[++i];
     	  }  else {
     		  printf("runner: test name is missing\n");
-    		  printUsage();
+    		  PrintUsage();
     		  exit(1);
     	  }
 
@@ -625,7 +627,7 @@
     		  substring = argv[++i];
     	  }  else {
     		  printf("runner: substring of test name is missing\n");
-    		  printUsage();
+    		  PrintUsage();
     		  exit(1);
     	  }
 
@@ -640,20 +642,24 @@
     		  suiteName = argv[++i];
     	  }  else {
     		  printf("runner: suite name is missing\n");
-    		  printUsage();
+    		  PrintUsage();
     		  exit(1);
     	  }
 
     	  memset(selected_suite_name, 0, NAME_BUFFER_SIZE);
     	  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) {
-    	  printUsage();
+    	  PrintUsage();
     	  exit(0);
       }
       else {
     	  printf("runner: unknown command '%s'\n", arg);
-    	  printUsage();
+    	  PrintUsage();
     	  exit(0);
       }
    }
--- a/test/test-automation/xml_logger.c	Mon Jul 04 17:23:20 2011 +0300
+++ b/test/test-automation/xml_logger.c	Mon Jul 04 20:46:06 2011 +0300
@@ -85,7 +85,7 @@
 	if(ValidateString(message)) {
 		int ident = 0;
 		for( ; ident < currentIdentLevel && prevEOL; ++ident) {
-			printf("  "); // \todo make configurable?
+			fprintf(stdout, "  "); // \todo make configurable?
 		}
 
 		prevEOL = EOL;