Example #1
0
 protected function _doRun()
 {
     $short_opts = self::getShortOpts();
     $long_opts = self::getLongOpts();
     lmbTestGetopt::defineAndExtractConstants($this->argv);
     try {
         if ($this->posix_opts) {
             $options = lmbTestGetopt::getopt($this->argv, $short_opts, $long_opts);
         } else {
             $options = lmbTestGetopt::getopt2($this->argv, $short_opts, $long_opts);
         }
     } catch (Exception $e) {
         $this->_help(1);
     }
     $config_file = null;
     $cover_include = '';
     $cover_exclude = '';
     $cover_report_dir = null;
     foreach ($options[0] as $option) {
         switch ($option[0]) {
             case 'h':
             case '--help':
                 $this->_help(0);
                 break;
             case 'V':
             case '--verbose':
                 lmbTestOptions::set('verbose', true);
                 break;
             case 'v':
             case '--version':
                 $this->_version();
                 break;
             case 'c':
             case '--config':
                 $config_file = $option[1];
                 break;
             case 'I':
             case '--include':
                 lmbTestOptions::set('file_filter', $option[1]);
                 break;
             case 'G':
             case '--groups':
                 lmbTestOptions::set('groups_filter', array_map('trim', explode(',', trim($option[1]))));
                 break;
             case 'T':
             case '--tests':
                 lmbTestOptions::set('tests_filter', array_map('trim', explode(',', trim($option[1]))));
                 break;
             case 'M':
             case '--methods':
                 lmbTestOptions::set('methods_filter', array_map('trim', explode(',', trim($option[1]))));
                 break;
             case 'C':
             case '--cover':
                 $cover_include = $option[1];
                 break;
             case '--cover-report':
                 $cover_report_dir = $option[1];
                 break;
             case '--cover-exclude':
                 $cover_exclude = $option[1];
                 break;
         }
     }
     if (!$config_file) {
         $config_file = getenv('LIMB_TESTS_RUNNER_CONFIG');
     }
     if ($config_file) {
         if (!($php = @file_get_contents(realpath($config_file)))) {
             $this->_error("Could not read configuration file '{$config_file}'\n");
         }
         if (!$this->_phpLint($php, $error)) {
             $this->_error("Configuration file '{$config_file}' is invalid(check syntax)\n{$error}");
         }
         if (!(include_once realpath($config_file))) {
             $this->_error("Could not include configuration file '{$config_file}'\n");
         }
     }
     if (!is_array($options[1]) || !count($options[1])) {
         $paths = array('.');
     } else {
         $paths = $options[1];
     }
     if (!$cover_report_dir && defined('LIMB_TESTS_RUNNER_COVERAGE_REPORT_DIR')) {
         $cover_report_dir = LIMB_TESTS_RUNNER_COVERAGE_REPORT_DIR;
     }
     require_once dirname(__FILE__) . '/lmbTestRunner.class.php';
     $runner = new lmbTestRunner();
     if ($this->reporter) {
         $runner->setReporter($this->reporter);
     }
     if ($cover_include) {
         $runner->useCoverage($cover_include, $cover_exclude, $cover_report_dir);
     }
     try {
         require_once dirname(__FILE__) . '/lmbTestTreeGlobNode.class.php';
         $node = new lmbTestTreeGlobNode($paths);
         $res = $runner->run($node);
     } catch (lmbTestUserException $e) {
         $this->_error($e->getMessage());
     } catch (Exception $e) {
         $this->_error($e->__toString());
     }
     return $res;
 }
Example #2
0
 /**
  * @access private
  *
  */
 static function _parseShortOption($arg, $short_options, &$opts, &$args)
 {
     for ($i = 0; $i < strlen($arg); $i++) {
         $opt = $arg[$i];
         $opt_arg = null;
         /* Try to find the short option in the specifier string. */
         if (($spec = strstr($short_options, $opt)) === false || $arg[$i] == ':') {
             throw new Exception("unrecognized option -- {$opt}");
         }
         if (strlen($spec) > 1 && $spec[1] == ':') {
             if (strlen($spec) > 2 && $spec[2] == ':') {
                 if ($i + 1 < strlen($arg)) {
                     /* Option takes an optional argument. Use the remainder of
                        the arg string if there is anything left. */
                     $opts[] = array($opt, substr($arg, $i + 1));
                     break;
                 }
             } else {
                 /* Option requires an argument. Use the remainder of the arg
                    string if there is anything left. */
                 if ($i + 1 < strlen($arg)) {
                     $opts[] = array($opt, substr($arg, $i + 1));
                     break;
                 } else {
                     if (list(, $opt_arg) = each($args)) {
                         /* Else use the next argument. */
                         if (lmbTestGetopt::_isShortOpt($opt_arg) || lmbTestGetopt::_isLongOpt($opt_arg)) {
                             throw new Exception("option requires an argument -- {$opt}");
                         }
                     } else {
                         throw new Exception("option requires an argument -- {$opt}");
                     }
                 }
             }
         }
         $opts[] = array($opt, $opt_arg);
     }
 }