/** * Runs the test suite. */ public function run() { $results = array(); $command = '(mkdir -p build && cd build && cmake ..)'; $command .= '&& make -C build all'; $command .= '&& make -C build test'; // Execute the test command & time it. $timeStart = microtime(true); $future = new ExecFuture($command); do { $future->read(); sleep(0.5); } while (!$future->isReady()); list($error, $stdout, $stderr) = $future->resolve(); $timeEnd = microtime(true); // Create a unit test result structure. $result = new ArcanistUnitTestResult(); $result->setNamespace('DerpVision'); $result->setName('Core'); $result->setDuration($timeEnd - $timeStart); if ($error == 0) { $result->setResult(ArcanistUnitTestResult::RESULT_PASS); } else { $result->setResult(ArcanistUnitTestResult::RESULT_FAIL); $result->setUserData($stdout . $stderr); } $results[] = $result; return $results; }
private final function resultTest($test_result, $reason) { $coverage = $this->endCoverage(); $result = new ArcanistUnitTestResult(); $result->setCoverage($coverage); $result->setNamespace(get_class($this)); $result->setName($this->runningTest); $result->setLink($this->getLink($this->runningTest)); $result->setResult($test_result); $result->setDuration(microtime(true) - $this->testStartTime); $result->setUserData($reason); $this->results[] = $result; if ($this->renderer) { echo $this->renderer->renderUnitResult($result); } }
private function processCoverageResults($project_root, $results) { $time_start = microtime_float(); // generate annotated source files to find out which lines have // coverage // limit files to only those "*.py" files in getPaths() $pythonPathsStr = join(" ", $this->getPythonPaths()); $future = new ExecFuture("coverage annotate {$pythonPathsStr}"); $future->setCWD($project_root); try { $future->resolvex(); } catch (CommandException $exc) { if ($exc->getError() > 1) { // 'nose' returns 1 when tests are failing/broken. throw $exc; } } // store all the coverage results for this project $coverageArray = array(); $lines_total = 0; $lines_executable = 0; $lines_not_executable = 0; $lines_covered = 0; $lines_not_covered = 0; // walk through project directory, searching for all ",cover" files // that coverage.py left behind foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(".")) as $path) { // paths are given as "./path/to/file.py,cover", so match the // "path/to/file.py" part if (!preg_match(":^\\./(.*),cover\$:", $path, $matches)) { continue; } $srcFilePath = $matches[1]; $coverageStr = ""; foreach (file($path) as $coverLine) { /* python coverage > executed ! missing(not executed) - excluded phab coverage N Not executable. This is a comment or whitespace which should be ignored when computing test coverage. C Covered. This line has test coverage. U Uncovered. This line is executable but has no test coverage. X Unreachable. If your coverage analysis can detect unreachable code, you can report it here. */ $lines_total++; switch ($coverLine[0]) { case '>': $lines_covered++; $lines_executable++; $coverageStr .= 'C'; break; case '!': $lines_not_covered++; $lines_executable++; $coverageStr .= 'U'; break; case ' ': $lines_not_executable++; $coverageStr .= 'N'; break; case '-': $coverageStr .= 'X'; break; default: break; } } // delete the ,cover file unlink($path); // only add to coverage report if the path was originally // specified by arc if (in_array($srcFilePath, $this->getPaths())) { $coverageArray[$srcFilePath] = $coverageStr; } } $lines_percentage = bcdiv($lines_covered, $lines_executable, 4) * 100; $time_end = microtime_float(); $time = $time_end - $time_start; // python does not support per-test coverage results so just put all the coverage // in a single 'coverage test' $result = new ArcanistUnitTestResult(); $result->setNamespace('coverage'); $result->setName('coverage'); $result->setResult('pass'); $result->setDuration($time); $result->setUserData("coverage: {$lines_percentage}% executable: {$lines_executable} / covered: {$lines_covered}"); $result->setCoverage($coverageArray); $results[] = $result; return $results; }