Page MenuHomePhabricator
Paste P1934

PantsTestEngine.php
ActivePublic

Authored by cburroughs on Jan 29 2016, 6:58 PM.
<?php
final class PantsTestEngine extends ArcanistUnitTestEngine {
public function getEngineConfigurationName() {
return "pants";
}
public function run() {
$projectRoot = $this->getWorkingCopy()->getProjectRoot();
$xunit_dir = Filesystem::createTemporaryDirectory();
$future = $this->buildTestFuture($xunit_dir);
$future->setCWD($projectRoot);
list($err, $stdout, $stderr) = $future->resolve();
$results = array();
$xunit_files = glob(Filesystem::resolvePath($xunit_dir."/*.xml"));
foreach ($xunit_files as $xunit_file) {
$results[] = $this->parseTestResults($xunit_file);
}
Filesystem::remove($xunit_dir);
return array_mergev($results);
}
public function buildTestFuture($xunit_dir) {
$paths = $this->getPaths();
$cmd_line = csprintf('./pants test-changed --test-changed-include-dependees=transitive --test-changed-parent=origin/master --test-pytest-junit-xml-dir=%s', $xunit_dir);
return new ExecFuture('%C', $cmd_line);
}
public function parseTestResults($xunit_file) {
$parser = new ArcanistXUnitTestResultParser();
$results = $parser->parseTestResults(Filesystem::readFile($xunit_file));
return $results;
}
}