Refactoring runner.c. Added --help/-h command line option.
authorMarkus Kauppila <markus.kauppila@gmail.com>
Wed, 01 Jun 2011 12:29:19 +0300
changeset 567602a0f7889834
parent 5675 8513baf78c95
child 5677 ecb455bdc5a5
Refactoring runner.c. Added --help/-h command line option.
test/test-automation/runner.c
     1.1 --- a/test/test-automation/runner.c	Tue May 31 14:40:28 2011 +0300
     1.2 +++ b/test/test-automation/runner.c	Wed Jun 01 12:29:19 2011 +0300
     1.3 @@ -30,23 +30,43 @@
     1.4  //!< Function pointer to a test case function
     1.5  typedef int (*TestCase)(void *arg);
     1.6  
     1.7 +//!< Flag for executing tests in-process
     1.8 +static int execute_inproc = 0;
     1.9 +
    1.10  /*!
    1.11 - * Loads test suite which is implemented as dynamic library.
    1.12 + * Returns the name for the dynamic library
    1.13 + * which implements the test suite.
    1.14   *
    1.15 - * \return Pointer to loaded test suite, or NULL if library could not be loaded
    1.16 + * (in the future: scans the test/ directory and
    1.17 + * returns the names of the dynamic libraries
    1.18 + * implementing the test suites)
    1.19 + *
    1.20 + * \return Name of the dummy test suite
    1.21   */
    1.22 -void *
    1.23 -LoadTestSuite()
    1.24 -{
    1.25 +char *
    1.26 +ScanForTestSuites() {
    1.27  #if defined(linux) || defined( __linux)
    1.28  	char *libName = "tests/libtest.so";
    1.29  #else
    1.30  	char *libName = "tests/libtest.dylib";
    1.31  #endif
    1.32 +	return libName;
    1.33 +}
    1.34  
    1.35 -	void *library = SDL_LoadObject(libName);
    1.36 +
    1.37 +/*!
    1.38 + * Loads test suite which is implemented as dynamic library.
    1.39 + *
    1.40 + * \param test0,330
    1.41 + *
    1.42 + * \return Pointer to loaded test suite, or NULL if library could not be loaded
    1.43 + */
    1.44 +void *
    1.45 +LoadTestSuite(char *testSuiteName)
    1.46 +{
    1.47 +	void *library = SDL_LoadObject(testSuiteName);
    1.48  	if(library == NULL) {
    1.49 -		fprintf(stderr, "Loading %s failed\n", libName);
    1.50 +		fprintf(stderr, "Loading %s failed\n", testSuiteName);
    1.51  		fprintf(stderr, "%s\n", SDL_GetError());
    1.52  	}
    1.53  
    1.54 @@ -127,11 +147,11 @@
    1.55  	return returnValue;
    1.56  }
    1.57  
    1.58 -//!< Flag for executing tests in-process
    1.59 -static int execute_inproc = 0;
    1.60 -
    1.61  /*!
    1.62   * Parse command line arguments
    1.63 + *
    1.64 + * \param argc Count of command line arguments
    1.65 + * \param argv Array of commond lines arguments
    1.66   */
    1.67  void
    1.68  ParseOptions(int argc, char *argv[])
    1.69 @@ -140,9 +160,17 @@
    1.70  
    1.71     for (i = 1; i < argc; ++i) {
    1.72        const char *arg = argv[i];
    1.73 -      if (SDL_strcmp(arg, "--in-proc") == 0) {
    1.74 +      if(SDL_strcmp(arg, "--in-proc") == 0) {
    1.75           execute_inproc = 1;
    1.76        }
    1.77 +      else if(SDL_strcmp(arg, "--help") == 0 || SDL_strcmp(arg, "-h") == 0) {
    1.78 +    	  printf("Usage: ./runner [--in-proc] [--help]\n");
    1.79 +    	  printf("Options:\n");
    1.80 +    	  printf(" --in-proc        Executes tests in-process\n");
    1.81 +    	  printf(" --help           Print this help.:\n");
    1.82 +    	  exit(0);
    1.83 +      }
    1.84 +      // \todo print error for unknown option
    1.85     }
    1.86  }
    1.87  
    1.88 @@ -161,11 +189,10 @@
    1.89  
    1.90  	int failureCount = 0, passCount = 0;
    1.91  
    1.92 -	char *libName = "libtest";
    1.93 -
    1.94  	const Uint32 startTicks = SDL_GetTicks();
    1.95  
    1.96 -	void *suite = LoadTestSuite();
    1.97 +	char *testSuiteName = ScanForTestSuites();
    1.98 +	void *suite = LoadTestSuite(testSuiteName);
    1.99  	TestCaseReference **tests = QueryTestCases(suite);
   1.100  
   1.101  	TestCaseReference *reference = NULL;
   1.102 @@ -173,11 +200,11 @@
   1.103  
   1.104  	for(reference = tests[counter]; reference; reference = tests[++counter]) {
   1.105  		if(reference->enabled == TEST_DISABLED) {
   1.106 -			printf("Test %s (in %s) disabled. Omitting...\n", reference->name, libName);
   1.107 +			printf("Test %s (in %s) disabled. Omitting...\n", reference->name, testSuiteName);
   1.108  		} else {
   1.109  			char *testname = reference->name;
   1.110  
   1.111 -			printf("Running %s (in %s):\n", testname, libName);
   1.112 +			printf("Running %s (in %s):\n", testname, testSuiteName);
   1.113  
   1.114  			int retVal = 1;
   1.115  			if(execute_inproc) {
   1.116 @@ -198,10 +225,10 @@
   1.117  
   1.118  			if(retVal) {
   1.119  				failureCount++;
   1.120 -				printf("%s (in %s): FAILED\n", testname, libName);
   1.121 +				printf("%s (in %s): FAILED\n", testname, testSuiteName);
   1.122  			} else {
   1.123  				passCount++;
   1.124 -				printf("%s (in %s): ok\n", testname, libName);
   1.125 +				printf("%s (in %s): ok\n", testname, testSuiteName);
   1.126  			}
   1.127  		}
   1.128