Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Added test and suite names to the output.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkauppila committed Jun 9, 2011
1 parent 6993481 commit 606e828
Showing 1 changed file with 47 additions and 15 deletions.
62 changes: 47 additions & 15 deletions test/test-automation/runner.c
Expand Up @@ -44,6 +44,9 @@ static int execute_inproc = 0;
static int only_selected_test = 0;
//!< Flag for executing only the selected test suite
static int only_selected_suite = 0;
//!< Flag for executing only tests that contain certain string in their name
static int only_tests_with_string = 0;


//!< Size of the test and suite name buffers
#define NAME_BUFFER_SIZE 1024
Expand All @@ -52,6 +55,9 @@ char selected_test_name[NAME_BUFFER_SIZE];
//!< Name of the selected suite
char selected_suite_name[NAME_BUFFER_SIZE];

//!< substring of test case name
char testcase_name_substring[NAME_BUFFER_SIZE];


//! Default directory of the test suites
#define DEFAULT_TEST_DIRECTORY "tests/"
Expand Down Expand Up @@ -331,6 +337,7 @@ printUsage() {
printf(" --in-proc Executes tests in-process\n");
printf(" -t --test TEST Executes only tests with given name\n");
printf(" -s --suite SUITE Executes only the given test suite\n");
//! \todo add --test-name-contains

printf(" -h --help Print this help\n");
}
Expand Down Expand Up @@ -371,6 +378,21 @@ ParseOptions(int argc, char *argv[])
memset(selected_test_name, 0, NAME_BUFFER_SIZE);
strcpy(selected_test_name, testName);
}
else if(SDL_strcmp(arg, "--test-name-contains") == 0 || SDL_strcmp(arg, "-ts") == 0) {
only_tests_with_string = 1;
char *substring = NULL;

if( (i + 1) < argc) {
substring = argv[++i];
} else {
printf("runner: substring of test name is missing\n");
printUsage();
exit(1);
}

memset(testcase_name_substring, 0, NAME_BUFFER_SIZE);
strcpy(testcase_name_substring, substring);
}
else if(SDL_strcmp(arg, "--suite") == 0 || SDL_strcmp(arg, "-s") == 0) {
only_selected_suite = 1;

Expand Down Expand Up @@ -418,14 +440,21 @@ LoadTestCases(TestSuiteReference *suites) {

// Do the filtering
if(FilterTestCase(testReference)) {
//!< \todo deallocate these
TestCaseItem *item = SDL_malloc(sizeof(TestCaseItem));
memset(item, 0, sizeof(TestCaseItem));

item->testCaseInit = testCaseInit;
item->testCase = testCase;
item->testCaseQuit = testCaseQuit;

int length = strlen(suiteReference->name) + 1;
item->suiteName = SDL_malloc(length);
strcpy(item->suiteName, suiteReference->name);

length = strlen(testReference->name) + 1;
item->testName = SDL_malloc(length);
strcpy(item->testName, testReference->name);

// prepend the list
item->next = testCases;
testCases = item;
Expand All @@ -445,6 +474,9 @@ void
UnloadTestCases(TestCaseItem *item) {
TestCaseItem *ref = item;
while(ref) {
SDL_free(ref->testName);
SDL_free(ref->suiteName);

TestCaseItem *temp = ref->next;
SDL_free(ref);
ref = temp;
Expand All @@ -455,24 +487,26 @@ UnloadTestCases(TestCaseItem *item) {

/*!
* \todo add comment
*
* \return Non-zero means test will be added to execution list, zero means opposite
*/
int
FilterTestCase(TestCaseReference *testReference) {
//int retVal = 1;
int retVal = 1;

if(testReference->enabled == TEST_DISABLED) {
//retVal = 0;
return 0;
retVal = 0;
}

if(1 && strstr(testReference->name, "rect") != NULL) {
//retVal = 1;
return 1;
} else {
return 0;
if(only_tests_with_string) {
if(strstr(testReference->name, testcase_name_substring) != NULL) {
retVal = 1;
} else {
retVal = 0;
}
}

return 1;
return retVal;
}

/*!
Expand Down Expand Up @@ -535,10 +569,8 @@ main(int argc, char *argv[])
TestSuiteReference *suites = ScanForTestSuites(DEFAULT_TEST_DIRECTORY, extension);
suites = LoadTestSuites(suites);

// load tests and filter them
TestCaseItem *testCases = LoadTestCases(suites);

// end result: list of tests to run
TestCaseItem *testItem = NULL;
for(testItem = testCases; testItem; testItem = testItem->next) {
int retVal = ExecuteTest(testItem);
Expand All @@ -547,13 +579,13 @@ main(int argc, char *argv[])
failureCount++;
if(retVal == 2) {
//printf("%s (in %s): FAILED -> No asserts\n", reference->name, testSuiteName);
printf("%s (in %s): FAILED -> No asserts\n", "<test name>", "<suite name>");
printf("%s (in %s): FAILED -> No asserts\n", testItem->testName, testItem->suiteName);
} else {
printf("%s (in %s): FAILED\n", "<test name>", "<suite name>");
printf("%s (in %s): FAILED\n", testItem->testName, testItem->suiteName);
}
} else {
passCount++;
printf("%s (in %s): ok\n", "<test name>", "<suite name>");
printf("%s (in %s): ok\n", testItem->testName, testItem->suiteName);
}

printf("\n");
Expand Down

0 comments on commit 606e828

Please sign in to comment.