Added test and suite names to the output.
1.1 --- a/test/test-automation/runner.c Thu Jun 09 16:37:51 2011 +0300
1.2 +++ b/test/test-automation/runner.c Thu Jun 09 17:13:33 2011 +0300
1.3 @@ -44,6 +44,9 @@
1.4 static int only_selected_test = 0;
1.5 //!< Flag for executing only the selected test suite
1.6 static int only_selected_suite = 0;
1.7 +//!< Flag for executing only tests that contain certain string in their name
1.8 +static int only_tests_with_string = 0;
1.9 +
1.10
1.11 //!< Size of the test and suite name buffers
1.12 #define NAME_BUFFER_SIZE 1024
1.13 @@ -52,6 +55,9 @@
1.14 //!< Name of the selected suite
1.15 char selected_suite_name[NAME_BUFFER_SIZE];
1.16
1.17 +//!< substring of test case name
1.18 +char testcase_name_substring[NAME_BUFFER_SIZE];
1.19 +
1.20
1.21 //! Default directory of the test suites
1.22 #define DEFAULT_TEST_DIRECTORY "tests/"
1.23 @@ -331,6 +337,7 @@
1.24 printf(" --in-proc Executes tests in-process\n");
1.25 printf(" -t --test TEST Executes only tests with given name\n");
1.26 printf(" -s --suite SUITE Executes only the given test suite\n");
1.27 + //! \todo add --test-name-contains
1.28
1.29 printf(" -h --help Print this help\n");
1.30 }
1.31 @@ -371,6 +378,21 @@
1.32 memset(selected_test_name, 0, NAME_BUFFER_SIZE);
1.33 strcpy(selected_test_name, testName);
1.34 }
1.35 + else if(SDL_strcmp(arg, "--test-name-contains") == 0 || SDL_strcmp(arg, "-ts") == 0) {
1.36 + only_tests_with_string = 1;
1.37 + char *substring = NULL;
1.38 +
1.39 + if( (i + 1) < argc) {
1.40 + substring = argv[++i];
1.41 + } else {
1.42 + printf("runner: substring of test name is missing\n");
1.43 + printUsage();
1.44 + exit(1);
1.45 + }
1.46 +
1.47 + memset(testcase_name_substring, 0, NAME_BUFFER_SIZE);
1.48 + strcpy(testcase_name_substring, substring);
1.49 + }
1.50 else if(SDL_strcmp(arg, "--suite") == 0 || SDL_strcmp(arg, "-s") == 0) {
1.51 only_selected_suite = 1;
1.52
1.53 @@ -418,7 +440,6 @@
1.54
1.55 // Do the filtering
1.56 if(FilterTestCase(testReference)) {
1.57 - //!< \todo deallocate these
1.58 TestCaseItem *item = SDL_malloc(sizeof(TestCaseItem));
1.59 memset(item, 0, sizeof(TestCaseItem));
1.60
1.61 @@ -426,6 +447,14 @@
1.62 item->testCase = testCase;
1.63 item->testCaseQuit = testCaseQuit;
1.64
1.65 + int length = strlen(suiteReference->name) + 1;
1.66 + item->suiteName = SDL_malloc(length);
1.67 + strcpy(item->suiteName, suiteReference->name);
1.68 +
1.69 + length = strlen(testReference->name) + 1;
1.70 + item->testName = SDL_malloc(length);
1.71 + strcpy(item->testName, testReference->name);
1.72 +
1.73 // prepend the list
1.74 item->next = testCases;
1.75 testCases = item;
1.76 @@ -445,6 +474,9 @@
1.77 UnloadTestCases(TestCaseItem *item) {
1.78 TestCaseItem *ref = item;
1.79 while(ref) {
1.80 + SDL_free(ref->testName);
1.81 + SDL_free(ref->suiteName);
1.82 +
1.83 TestCaseItem *temp = ref->next;
1.84 SDL_free(ref);
1.85 ref = temp;
1.86 @@ -455,24 +487,26 @@
1.87
1.88 /*!
1.89 * \todo add comment
1.90 + *
1.91 + * \return Non-zero means test will be added to execution list, zero means opposite
1.92 */
1.93 int
1.94 FilterTestCase(TestCaseReference *testReference) {
1.95 - //int retVal = 1;
1.96 + int retVal = 1;
1.97
1.98 if(testReference->enabled == TEST_DISABLED) {
1.99 - //retVal = 0;
1.100 - return 0;
1.101 + retVal = 0;
1.102 }
1.103
1.104 - if(1 && strstr(testReference->name, "rect") != NULL) {
1.105 - //retVal = 1;
1.106 - return 1;
1.107 - } else {
1.108 - return 0;
1.109 + if(only_tests_with_string) {
1.110 + if(strstr(testReference->name, testcase_name_substring) != NULL) {
1.111 + retVal = 1;
1.112 + } else {
1.113 + retVal = 0;
1.114 + }
1.115 }
1.116
1.117 - return 1;
1.118 + return retVal;
1.119 }
1.120
1.121 /*!
1.122 @@ -535,10 +569,8 @@
1.123 TestSuiteReference *suites = ScanForTestSuites(DEFAULT_TEST_DIRECTORY, extension);
1.124 suites = LoadTestSuites(suites);
1.125
1.126 - // load tests and filter them
1.127 TestCaseItem *testCases = LoadTestCases(suites);
1.128
1.129 - // end result: list of tests to run
1.130 TestCaseItem *testItem = NULL;
1.131 for(testItem = testCases; testItem; testItem = testItem->next) {
1.132 int retVal = ExecuteTest(testItem);
1.133 @@ -547,13 +579,13 @@
1.134 failureCount++;
1.135 if(retVal == 2) {
1.136 //printf("%s (in %s): FAILED -> No asserts\n", reference->name, testSuiteName);
1.137 - printf("%s (in %s): FAILED -> No asserts\n", "<test name>", "<suite name>");
1.138 + printf("%s (in %s): FAILED -> No asserts\n", testItem->testName, testItem->suiteName);
1.139 } else {
1.140 - printf("%s (in %s): FAILED\n", "<test name>", "<suite name>");
1.141 + printf("%s (in %s): FAILED\n", testItem->testName, testItem->suiteName);
1.142 }
1.143 } else {
1.144 passCount++;
1.145 - printf("%s (in %s): ok\n", "<test name>", "<suite name>");
1.146 + printf("%s (in %s): ok\n", testItem->testName, testItem->suiteName);
1.147 }
1.148
1.149 printf("\n");