Fixed problem in ScanForTestSuites concerning hidden
authorMarkus Kauppila <markus.kauppila@gmail.com>
Fri, 29 Jul 2011 18:18:37 +0300
changeset 5792 ec908de81ba5
parent 5791 a4e354dfcbfa
child 5793 e4b84f743a7e
Fixed problem in ScanForTestSuites concerning hidden files. Plus other little fixes.
test/test-automation/runner.c
--- a/test/test-automation/runner.c	Fri Jul 29 16:22:03 2011 +0300
+++ b/test/test-automation/runner.c	Fri Jul 29 18:18:37 2011 +0300
@@ -219,11 +219,12 @@
 	if(!directory) {
 		fprintf(stderr, "Failed to open test suite directory: %s\n", directoryName);
 		perror("Error message");
-		exit(1);
+		exit(2);
 	}
 
 	while(entry = readdir(directory)) {
-		if(strlen(entry->d_name) > 2) { // discards . and ..
+		 // discards . and .. and hidden files starting with .
+		if(strlen(entry->d_name) > 2 && entry->d_name[0] != '.') {
 			const char *delimiters = ".";
 			char *name = strtok(entry->d_name, delimiters);
 			char *ext = strtok(NULL, delimiters);
@@ -234,7 +235,7 @@
 				ok = SDL_strncmp(selected_suite_name, name, NAME_BUFFER_SIZE) == 0;
 			}
 
-			if(ok && SDL_strcmp(ext, extension)  == 0) {
+			if(ok && SDL_strncmp(ext, extension, SDL_strlen(extension))  == 0) {
 				// create test suite reference
 				TestSuiteReference *reference = (TestSuiteReference *) SDL_malloc(sizeof(TestSuiteReference));
 				if(reference == NULL) {
@@ -366,9 +367,8 @@
 
 		TestCaseReference *testReference = NULL;
 		int counter = 0;
-		for(testReference = tests[counter]; testReference; testReference = tests[++counter]) {
-
-			void *suite = suiteReference->library;
+ 		for(testReference = tests[counter]; testReference; testReference = tests[++counter]) {
+			//void *suite = suiteReference->library;
 
 			// Load test case functions
 			InitTestInvironmentFp initTestEnvironment = LoadInitTestInvironmentFunction(suiteReference->library);
@@ -874,7 +874,7 @@
 		int number = abs(utl_random(&randomContext));
 		char ch = (char) (number % (122 - 48)) + 48;
 
-		// Remove all the special characters so the run seed
+		// Skip all the special characters so the run seed
 		// can be used to form a valid filename.
 		// A lot more characters are skipped than necessary.
 		if(ch >= 58 && ch <= 64) {
@@ -1154,7 +1154,7 @@
     	  }
 
     	  memset(selected_test_name, 0, NAME_BUFFER_SIZE);
-    	  strcpy(selected_test_name, testName);
+    	  strncpy(selected_test_name, testName, NAME_BUFFER_SIZE);
       }
       else if(SDL_strcmp(arg, "--xsl") == 0) {
     	  xsl_enabled = 1;
@@ -1182,7 +1182,7 @@
     	  }
 
     	  memset(testcase_name_substring, 0, NAME_BUFFER_SIZE);
-    	  strcpy(testcase_name_substring, substring);
+    	  strncpy(testcase_name_substring, strdup(substring), NAME_BUFFER_SIZE);
       }
       else if(SDL_strcmp(arg, "--suite") == 0 || SDL_strcmp(arg, "-s") == 0) {
     	  only_selected_suite = 1;
@@ -1233,6 +1233,10 @@
 	memcpy(log_basename, (void *)DEFAULT_LOG_FILENAME, SDL_strlen(DEFAULT_LOG_FILENAME));
 	memcpy(log_directory, (void *)DEFAULT_LOG_DIRECTORY, SDL_strlen(DEFAULT_LOG_DIRECTORY));
 
+	memset(selected_test_name, 0, NAME_BUFFER_SIZE);
+	memset(selected_suite_name, 0, NAME_BUFFER_SIZE);
+	memset(testcase_name_substring, 0, NAME_BUFFER_SIZE);
+
 	ParseOptions(argc, argv);
 
 	char *testSuiteName = NULL;
@@ -1248,16 +1252,26 @@
 		runSeed = GenerateRunSeed(16);
 		if(runSeed == NULL) {
 			fprintf(stderr, "Error: Generating harness seed failed\n");
-			return 1;
+			return 2;
 		}
 	}
 
 	const Uint32 startTicks = SDL_GetTicks();
 
 	TestSuiteReference *suites = ScanForTestSuites(DEFAULT_TEST_DIRECTORY, extension);
+	if(suites == NULL) {
+		fprintf(stderr, "No test suites loaded.\n");
+		fprintf(stderr, "Compile you suites and install them to tests/\n");
+		return 2;
+	}
 	suites = LoadTestSuites(suites);
 
 	TestCase *testCases = LoadTestCases(suites);
+	if(testCases == NULL) {
+		fprintf(stderr, "Found zero test cases\n");
+		fprintf(stderr, "Check out your command line options\n");
+		return 2;
+	}
 
 	// if --show-tests option is given, only print tests and exit
 	if(only_print_tests) {
@@ -1271,13 +1285,13 @@
 
 	LoggerData *loggerData = SetUpLogger();
 
-	RunStarted(argc, argv, runSeed, time(0), loggerData);
-
 	if(log_stdout_enabled == 0) {
 		printf("Runner is executing the tests.\n");
 		printf("Test report is created to: %s\n", loggerData->filename);
 	}
 
+	RunStarted(argc, argv, runSeed, time(0), loggerData);
+
 	// logger data is no longer used
 	SDL_free(loggerData->filename);
 	SDL_free(loggerData);
@@ -1349,14 +1363,6 @@
 			TestEnded(testItem->testName, testItem->suiteName, retVal, time(0), testTotalRuntime);
 
 			currentIteration--;
-
-			/*
-			if(userExecKey != NULL) {
-				SDL_free(globalExecKey);
-			}
-			globalExecKey = NULL;
-			*/
-
 		}
 	}