diff --git a/go_test_engine/__phutil_library_init__.php b/go_test_engine/__phutil_library_init__.php new file mode 100644 index 0000000..08da3b4 --- /dev/null +++ b/go_test_engine/__phutil_library_init__.php @@ -0,0 +1,4 @@ + 2, + 'class' => array( + 'GoTestEngine' => 'src/GoTestEngine.php', + ), + 'function' => array(), + 'xmap' => array( + 'GoTestEngine' => 'ArcanistUnitTestEngine', + ), +)); diff --git a/go_test_engine/src/GoTestEngine.php b/go_test_engine/src/GoTestEngine.php new file mode 100644 index 0000000..c792def --- /dev/null +++ b/go_test_engine/src/GoTestEngine.php @@ -0,0 +1,19 @@ +getConfigurationManager()->getConfigFromAnySource('unit.engine.go.command'); + $future = new ExecFuture($command); + + do { + list($stdout, $stderr) = $future->read(); + echo $stdout; + echo $stderr; + sleep(0.5); + } while (!$future->isReady()); + + list($error, $stdout, $stderr) = $future->resolve(); + + $parser = new ArcanistGoTestResultParser(); + return $parser->parseTestResults("", $stdout); + } +} diff --git a/multi_test_engine/src/MultiTestEngine.php b/multi_test_engine/src/MultiTestEngine.php index 44060b0..0cd9bcb 100644 --- a/multi_test_engine/src/MultiTestEngine.php +++ b/multi_test_engine/src/MultiTestEngine.php @@ -10,20 +10,65 @@ public function run() { $results = array(); foreach ($engines as $engine_or_configuration) { + $include = false; + $includeReport = false; + $changedFileMatchesInclude = false; + if (is_array($engine_or_configuration)) { $engine_class = $engine_or_configuration['engine']; - foreach ($engine_or_configuration as $configuration => $value) { - if ($configuration != 'engine') { + if ($configuration != 'engine' && + $configuration != 'include' && + $configuration != 'include_report') { $config->setRuntimeConfig($configuration, $value); } + + switch($configuration) { + case 'include': + $include = $value; + break; + case 'include_report': + $includeReport = $value + break + } } } else { $engine_class = $engine_or_configuration; } $engine = $this->instantiateEngine($engine_class); - $results = array_merge($results, $engine->run()); + + // If a regex is configured we'll do a match on all changed files to see if there's a match + // before calling $engine->run() + if ($include) { + $include = '/' . $include . '/'; + foreach ($this->getPaths() as $path) { + if (preg_match($include, $path)) { + $changedFileMatchesInclude = true; + break; + } + } + } + + // No need to execute the unit tests, so bail - but do report that we skipped running tests. + if (!$changedFileMatchesInclude) { + $test_results = []; + // Be silent by default if no files match the include regex, but if the config + // includes a bit to see it, output a skip test result for visibility when + // no tests match the include regex. + if ($includeReport) { + $skip_test = new ArcanistUnitTestResult(); + $skip_test->setName("No changed files match " . $include . " - not running " . $engine_class); + $skip_test->setResult(ArcanistUnitTestResult::RESULT_SKIP); + $test_results[] = $skip_test; + } + + // Actually run the tests if we didn't already decide not to run them. + } else { + $test_results = $engine->run(); + } + + $results = array_merge($results, $test_results); } return $results;