2013-09-23 14:32:34 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Uses xUnit (http://xunit.codeplex.com/) to test C# code.
|
|
|
|
*
|
|
|
|
* Assumes that when modifying a file with a path like `SomeAssembly/MyFile.cs`,
|
|
|
|
* that the test assembly that verifies the functionality of `SomeAssembly` is
|
|
|
|
* located at `SomeAssembly.Tests`.
|
|
|
|
*
|
|
|
|
* @concrete-extensible
|
|
|
|
*/
|
2014-07-21 23:49:15 +02:00
|
|
|
class XUnitTestEngine extends ArcanistUnitTestEngine {
|
2013-09-23 14:32:34 +02:00
|
|
|
|
|
|
|
protected $runtimeEngine;
|
|
|
|
protected $buildEngine;
|
|
|
|
protected $testEngine;
|
|
|
|
protected $projectRoot;
|
|
|
|
protected $xunitHintPath;
|
2013-11-22 23:32:48 +01:00
|
|
|
protected $discoveryRules;
|
2013-09-23 14:32:34 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This test engine supports running all tests.
|
|
|
|
*/
|
|
|
|
protected function supportsRunAllTests() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-07-09 01:12:13 +02:00
|
|
|
* Determines what executables and test paths to use. Between platforms this
|
|
|
|
* also changes whether the test engine is run under .NET or Mono. It also
|
|
|
|
* ensures that all of the required binaries are available for the tests to
|
|
|
|
* run successfully.
|
2013-09-23 14:32:34 +02:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2013-11-26 08:00:44 +01:00
|
|
|
protected function loadEnvironment() {
|
2013-09-23 14:32:34 +02:00
|
|
|
$this->projectRoot = $this->getWorkingCopy()->getProjectRoot();
|
|
|
|
|
|
|
|
// Determine build engine.
|
2014-05-23 22:53:05 +02:00
|
|
|
if (Filesystem::binaryExists('msbuild')) {
|
|
|
|
$this->buildEngine = 'msbuild';
|
|
|
|
} else if (Filesystem::binaryExists('xbuild')) {
|
|
|
|
$this->buildEngine = 'xbuild';
|
2013-09-23 14:32:34 +02:00
|
|
|
} else {
|
2014-05-23 22:53:05 +02:00
|
|
|
throw new Exception('Unable to find msbuild or xbuild in PATH!');
|
2013-09-23 14:32:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Determine runtime engine (.NET or Mono).
|
|
|
|
if (phutil_is_windows()) {
|
2014-05-23 22:53:05 +02:00
|
|
|
$this->runtimeEngine = '';
|
|
|
|
} else if (Filesystem::binaryExists('mono')) {
|
|
|
|
$this->runtimeEngine = Filesystem::resolveBinary('mono');
|
2013-09-23 14:32:34 +02:00
|
|
|
} else {
|
2014-05-23 22:53:05 +02:00
|
|
|
throw new Exception('Unable to find Mono and you are not on Windows!');
|
2013-09-23 14:32:34 +02:00
|
|
|
}
|
|
|
|
|
2013-11-22 23:32:48 +01:00
|
|
|
// Read the discovery rules.
|
|
|
|
$this->discoveryRules =
|
|
|
|
$this->getConfigurationManager()->getConfigFromAnySource(
|
|
|
|
'unit.csharp.discovery');
|
|
|
|
if ($this->discoveryRules === null) {
|
|
|
|
throw new Exception(
|
2014-05-23 22:53:05 +02:00
|
|
|
'You must configure discovery rules to map C# files '.
|
|
|
|
'back to test projects (`unit.csharp.discovery` in .arcconfig).');
|
2013-11-22 23:32:48 +01:00
|
|
|
}
|
|
|
|
|
2013-09-23 14:32:34 +02:00
|
|
|
// Determine xUnit test runner path.
|
|
|
|
if ($this->xunitHintPath === null) {
|
2013-10-22 22:58:32 +02:00
|
|
|
$this->xunitHintPath =
|
|
|
|
$this->getConfigurationManager()->getConfigFromAnySource(
|
2013-11-22 23:32:48 +01:00
|
|
|
'unit.csharp.xunit.binary');
|
2013-09-23 14:32:34 +02:00
|
|
|
}
|
2013-11-22 23:32:48 +01:00
|
|
|
$xunit = $this->projectRoot.DIRECTORY_SEPARATOR.$this->xunitHintPath;
|
|
|
|
if (file_exists($xunit) && $this->xunitHintPath !== null) {
|
2013-09-23 14:32:34 +02:00
|
|
|
$this->testEngine = Filesystem::resolvePath($xunit);
|
2014-05-23 22:53:05 +02:00
|
|
|
} else if (Filesystem::binaryExists('xunit.console.clr4.exe')) {
|
|
|
|
$this->testEngine = 'xunit.console.clr4.exe';
|
2013-09-23 14:32:34 +02:00
|
|
|
} else {
|
|
|
|
throw new Exception(
|
2014-07-09 01:12:13 +02:00
|
|
|
"Unable to locate xUnit console runner. Configure ".
|
2013-11-26 08:00:44 +01:00
|
|
|
"it with the `unit.csharp.xunit.binary' option in .arcconfig");
|
2013-09-23 14:32:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-07-09 01:12:13 +02:00
|
|
|
* Main entry point for the test engine. Determines what assemblies to build
|
|
|
|
* and test based on the files that have changed.
|
2013-09-23 14:32:34 +02:00
|
|
|
*
|
|
|
|
* @return array Array of test results.
|
|
|
|
*/
|
|
|
|
public function run() {
|
|
|
|
|
|
|
|
$this->loadEnvironment();
|
|
|
|
|
|
|
|
if ($this->getRunAllTests()) {
|
2013-11-22 23:32:48 +01:00
|
|
|
$paths = id(new FileFinder($this->projectRoot))->find();
|
2013-09-23 14:32:34 +02:00
|
|
|
} else {
|
|
|
|
$paths = $this->getPaths();
|
2013-11-22 23:32:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->runAllTests($this->mapPathsToResults($paths));
|
|
|
|
}
|
2013-09-23 14:32:34 +02:00
|
|
|
|
2013-11-22 23:32:48 +01:00
|
|
|
/**
|
|
|
|
* Applies the discovery rules to the set of paths specified.
|
|
|
|
*
|
|
|
|
* @param array Array of paths.
|
|
|
|
* @return array Array of paths to test projects and assemblies.
|
|
|
|
*/
|
|
|
|
public function mapPathsToResults(array $paths) {
|
|
|
|
$results = array();
|
|
|
|
foreach ($this->discoveryRules as $regex => $targets) {
|
|
|
|
$regex = str_replace('/', '\\/', $regex);
|
2013-09-23 14:32:34 +02:00
|
|
|
foreach ($paths as $path) {
|
2013-11-22 23:32:48 +01:00
|
|
|
if (preg_match('/'.$regex.'/', $path) === 1) {
|
|
|
|
foreach ($targets as $target) {
|
|
|
|
// Index 0 is the test project (.csproj file)
|
|
|
|
// Index 1 is the output assembly (.dll file)
|
|
|
|
$project = preg_replace('/'.$regex.'/', $target[0], $path);
|
|
|
|
$project = $this->projectRoot.DIRECTORY_SEPARATOR.$project;
|
|
|
|
$assembly = preg_replace('/'.$regex.'/', $target[1], $path);
|
|
|
|
$assembly = $this->projectRoot.DIRECTORY_SEPARATOR.$assembly;
|
|
|
|
if (file_exists($project)) {
|
|
|
|
$project = Filesystem::resolvePath($project);
|
|
|
|
$assembly = Filesystem::resolvePath($assembly);
|
|
|
|
|
|
|
|
// Check to ensure uniqueness.
|
|
|
|
$exists = false;
|
|
|
|
foreach ($results as $existing) {
|
|
|
|
if ($existing['assembly'] === $assembly) {
|
|
|
|
$exists = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$exists) {
|
|
|
|
$results[] = array(
|
|
|
|
'project' => $project,
|
2014-07-09 01:12:13 +02:00
|
|
|
'assembly' => $assembly,
|
|
|
|
);
|
2013-11-22 23:32:48 +01:00
|
|
|
}
|
|
|
|
}
|
2013-09-23 14:32:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-11-22 23:32:48 +01:00
|
|
|
return $results;
|
2013-09-23 14:32:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds and runs the specified test assemblies.
|
|
|
|
*
|
2013-11-22 23:32:48 +01:00
|
|
|
* @param array Array of paths to test project files.
|
2013-09-23 14:32:34 +02:00
|
|
|
* @return array Array of test results.
|
|
|
|
*/
|
2013-11-22 23:32:48 +01:00
|
|
|
public function runAllTests(array $test_projects) {
|
|
|
|
if (empty($test_projects)) {
|
2013-09-23 14:32:34 +02:00
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$results = array();
|
|
|
|
$results[] = $this->generateProjects();
|
|
|
|
if ($this->resultsContainFailures($results)) {
|
|
|
|
return array_mergev($results);
|
|
|
|
}
|
2013-11-22 23:32:48 +01:00
|
|
|
$results[] = $this->buildProjects($test_projects);
|
2013-09-23 14:32:34 +02:00
|
|
|
if ($this->resultsContainFailures($results)) {
|
|
|
|
return array_mergev($results);
|
|
|
|
}
|
2013-11-22 23:32:48 +01:00
|
|
|
$results[] = $this->testAssemblies($test_projects);
|
2013-09-23 14:32:34 +02:00
|
|
|
|
|
|
|
return array_mergev($results);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether or not a current set of results contains any failures.
|
|
|
|
* This is needed since we build the assemblies as part of the unit tests, but
|
|
|
|
* we can't run any of the unit tests if the build fails.
|
|
|
|
*
|
|
|
|
* @param array Array of results to check.
|
|
|
|
* @return bool If there are any failures in the results.
|
|
|
|
*/
|
|
|
|
private function resultsContainFailures(array $results) {
|
|
|
|
$results = array_mergev($results);
|
|
|
|
foreach ($results as $result) {
|
|
|
|
if ($result->getResult() != ArcanistUnitTestResult::RESULT_PASS) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the `Build` directory exists, we assume that this is a multi-platform
|
2014-07-09 01:12:13 +02:00
|
|
|
* project that requires generation of C# project files. Because we want to
|
2013-09-23 14:32:34 +02:00
|
|
|
* test that the generation and subsequent build is whole, we need to
|
|
|
|
* regenerate any projects in case the developer has added files through an
|
|
|
|
* IDE and then forgotten to add them to the respective `.definitions` file.
|
|
|
|
* By regenerating the projects we ensure that any missing definition entries
|
|
|
|
* will cause the build to fail.
|
|
|
|
*
|
|
|
|
* @return array Array of test results.
|
|
|
|
*/
|
|
|
|
private function generateProjects() {
|
|
|
|
// No "Build" directory; so skip generation of projects.
|
2014-05-23 22:53:05 +02:00
|
|
|
if (!is_dir(Filesystem::resolvePath($this->projectRoot.'/Build'))) {
|
2013-09-23 14:32:34 +02:00
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
2013-11-22 23:32:48 +01:00
|
|
|
// No "Protobuild.exe" file; so skip generation of projects.
|
|
|
|
if (!is_file(Filesystem::resolvePath(
|
2014-05-23 22:53:05 +02:00
|
|
|
$this->projectRoot.'/Protobuild.exe'))) {
|
2013-11-22 23:32:48 +01:00
|
|
|
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
2013-09-23 14:32:34 +02:00
|
|
|
// Work out what platform the user is building for already.
|
2014-05-23 22:53:05 +02:00
|
|
|
$platform = phutil_is_windows() ? 'Windows' : 'Linux';
|
2013-09-23 14:32:34 +02:00
|
|
|
$files = Filesystem::listDirectory($this->projectRoot);
|
|
|
|
foreach ($files as $file) {
|
2014-05-23 22:53:05 +02:00
|
|
|
if (strtolower(substr($file, -4)) == '.sln') {
|
|
|
|
$parts = explode('.', $file);
|
2013-09-23 14:32:34 +02:00
|
|
|
$platform = $parts[count($parts) - 2];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$regenerate_start = microtime(true);
|
|
|
|
$regenerate_future = new ExecFuture(
|
2014-05-23 22:53:05 +02:00
|
|
|
'%C Protobuild.exe --resync %s',
|
2013-09-23 14:32:34 +02:00
|
|
|
$this->runtimeEngine,
|
|
|
|
$platform);
|
|
|
|
$regenerate_future->setCWD(Filesystem::resolvePath(
|
|
|
|
$this->projectRoot));
|
|
|
|
$results = array();
|
|
|
|
$result = new ArcanistUnitTestResult();
|
|
|
|
$result->setName("(regenerate projects for $platform)");
|
|
|
|
|
|
|
|
try {
|
|
|
|
$regenerate_future->resolvex();
|
|
|
|
$result->setResult(ArcanistUnitTestResult::RESULT_PASS);
|
|
|
|
} catch(CommandException $exc) {
|
|
|
|
if ($exc->getError() > 1) {
|
|
|
|
throw $exc;
|
|
|
|
}
|
|
|
|
$result->setResult(ArcanistUnitTestResult::RESULT_FAIL);
|
|
|
|
$result->setUserdata($exc->getStdout());
|
|
|
|
}
|
|
|
|
|
|
|
|
$result->setDuration(microtime(true) - $regenerate_start);
|
|
|
|
$results[] = $result;
|
|
|
|
return $results;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build the projects relevant for the specified test assemblies and return
|
2014-07-09 01:12:13 +02:00
|
|
|
* the results of the builds as test results. This build also passes the
|
2013-09-23 14:32:34 +02:00
|
|
|
* "SkipTestsOnBuild" parameter when building the projects, so that MSBuild
|
|
|
|
* conditionals can be used to prevent any tests running as part of the
|
|
|
|
* build itself (since the unit tester is about to run each of the tests
|
|
|
|
* individually).
|
|
|
|
*
|
|
|
|
* @param array Array of test assemblies.
|
|
|
|
* @return array Array of test results.
|
|
|
|
*/
|
|
|
|
private function buildProjects(array $test_assemblies) {
|
|
|
|
$build_futures = array();
|
|
|
|
$build_failed = false;
|
|
|
|
$build_start = microtime(true);
|
|
|
|
$results = array();
|
|
|
|
foreach ($test_assemblies as $test_assembly) {
|
|
|
|
$build_future = new ExecFuture(
|
2014-05-23 22:53:05 +02:00
|
|
|
'%C %s',
|
2013-09-23 14:32:34 +02:00
|
|
|
$this->buildEngine,
|
2014-05-23 22:53:05 +02:00
|
|
|
'/p:SkipTestsOnBuild=True');
|
2013-09-23 14:32:34 +02:00
|
|
|
$build_future->setCWD(Filesystem::resolvePath(
|
2013-11-22 23:32:48 +01:00
|
|
|
dirname($test_assembly['project'])));
|
|
|
|
$build_futures[$test_assembly['project']] = $build_future;
|
2013-09-23 14:32:34 +02:00
|
|
|
}
|
|
|
|
$iterator = Futures($build_futures)->limit(1);
|
|
|
|
foreach ($iterator as $test_assembly => $future) {
|
|
|
|
$result = new ArcanistUnitTestResult();
|
2014-05-23 22:53:05 +02:00
|
|
|
$result->setName('(build) '.$test_assembly);
|
2013-09-23 14:32:34 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
$future->resolvex();
|
|
|
|
$result->setResult(ArcanistUnitTestResult::RESULT_PASS);
|
|
|
|
} catch(CommandException $exc) {
|
|
|
|
if ($exc->getError() > 1) {
|
|
|
|
throw $exc;
|
|
|
|
}
|
|
|
|
$result->setResult(ArcanistUnitTestResult::RESULT_FAIL);
|
|
|
|
$result->setUserdata($exc->getStdout());
|
|
|
|
$build_failed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$result->setDuration(microtime(true) - $build_start);
|
|
|
|
$results[] = $result;
|
|
|
|
}
|
|
|
|
return $results;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-07-09 01:12:13 +02:00
|
|
|
* Build the future for running a unit test. This can be overridden to enable
|
|
|
|
* support for code coverage via another tool.
|
2013-09-23 14:32:34 +02:00
|
|
|
*
|
|
|
|
* @param string Name of the test assembly.
|
|
|
|
* @return array The future, output filename and coverage filename
|
|
|
|
* stored in an array.
|
|
|
|
*/
|
|
|
|
protected function buildTestFuture($test_assembly) {
|
|
|
|
// FIXME: Can't use TempFile here as xUnit doesn't like
|
2014-07-09 01:12:13 +02:00
|
|
|
// UNIX-style full paths. It sees the leading / as the
|
2013-09-23 14:32:34 +02:00
|
|
|
// start of an option flag, even when quoted.
|
2014-05-23 22:53:05 +02:00
|
|
|
$xunit_temp = Filesystem::readRandomCharacters(10).'.results.xml';
|
2013-09-23 14:32:34 +02:00
|
|
|
if (file_exists($xunit_temp)) {
|
|
|
|
unlink($xunit_temp);
|
|
|
|
}
|
|
|
|
$future = new ExecFuture(
|
2014-05-23 22:53:05 +02:00
|
|
|
'%C %s /xml %s',
|
|
|
|
trim($this->runtimeEngine.' '.$this->testEngine),
|
2013-11-22 23:32:48 +01:00
|
|
|
$test_assembly,
|
2013-09-23 14:32:34 +02:00
|
|
|
$xunit_temp);
|
2013-11-22 23:32:48 +01:00
|
|
|
$folder = Filesystem::resolvePath($this->projectRoot);
|
|
|
|
$future->setCWD($folder);
|
2014-05-23 22:53:05 +02:00
|
|
|
$combined = $folder.'/'.$xunit_temp;
|
2013-11-22 23:32:48 +01:00
|
|
|
if (phutil_is_windows()) {
|
2014-05-23 22:53:05 +02:00
|
|
|
$combined = $folder.'\\'.$xunit_temp;
|
2013-11-22 23:32:48 +01:00
|
|
|
}
|
|
|
|
return array($future, $combined, null);
|
2013-09-23 14:32:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run the xUnit test runner on each of the assemblies and parse the
|
|
|
|
* resulting XML.
|
|
|
|
*
|
|
|
|
* @param array Array of test assemblies.
|
|
|
|
* @return array Array of test results.
|
|
|
|
*/
|
|
|
|
private function testAssemblies(array $test_assemblies) {
|
|
|
|
$results = array();
|
|
|
|
|
|
|
|
// Build the futures for running the tests.
|
|
|
|
$futures = array();
|
|
|
|
$outputs = array();
|
|
|
|
$coverages = array();
|
|
|
|
foreach ($test_assemblies as $test_assembly) {
|
2013-11-22 23:32:48 +01:00
|
|
|
list($future_r, $xunit_temp, $coverage) =
|
|
|
|
$this->buildTestFuture($test_assembly['assembly']);
|
|
|
|
$futures[$test_assembly['assembly']] = $future_r;
|
|
|
|
$outputs[$test_assembly['assembly']] = $xunit_temp;
|
|
|
|
$coverages[$test_assembly['assembly']] = $coverage;
|
2013-09-23 14:32:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run all of the tests.
|
2013-11-22 23:32:48 +01:00
|
|
|
foreach (Futures($futures)->limit(8) as $test_assembly => $future) {
|
|
|
|
list($err, $stdout, $stderr) = $future->resolve();
|
2013-09-23 14:32:34 +02:00
|
|
|
|
|
|
|
if (file_exists($outputs[$test_assembly])) {
|
|
|
|
$result = $this->parseTestResult(
|
|
|
|
$outputs[$test_assembly],
|
|
|
|
$coverages[$test_assembly]);
|
|
|
|
$results[] = $result;
|
|
|
|
unlink($outputs[$test_assembly]);
|
|
|
|
} else {
|
2013-11-22 23:32:48 +01:00
|
|
|
// FIXME: There's a bug in Mono which causes a segmentation fault
|
|
|
|
// when xUnit.NET runs; this causes the XML file to not appear
|
2014-07-09 01:12:13 +02:00
|
|
|
// (depending on when the segmentation fault occurs). See
|
2013-11-22 23:32:48 +01:00
|
|
|
// https://bugzilla.xamarin.com/show_bug.cgi?id=16379
|
|
|
|
// for more information.
|
|
|
|
|
|
|
|
// Since it's not possible for the user to correct this error, we
|
|
|
|
// ignore the fact the tests didn't run here.
|
2013-09-23 14:32:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return array_mergev($results);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns null for this implementation as xUnit does not support code
|
2014-07-09 01:12:13 +02:00
|
|
|
* coverage directly. Override this method in another class to provide code
|
|
|
|
* coverage information (also see @{class:CSharpToolsUnitEngine}).
|
2013-09-23 14:32:34 +02:00
|
|
|
*
|
|
|
|
* @param string The name of the coverage file if one was provided by
|
|
|
|
* `buildTestFuture`.
|
|
|
|
* @return array Code coverage results, or null.
|
|
|
|
*/
|
|
|
|
protected function parseCoverageResult($coverage) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parses the test results from xUnit.
|
|
|
|
*
|
|
|
|
* @param string The name of the xUnit results file.
|
|
|
|
* @param string The name of the coverage file if one was provided by
|
2014-07-09 01:12:13 +02:00
|
|
|
* `buildTestFuture`. This is passed through to
|
2013-09-23 14:32:34 +02:00
|
|
|
* `parseCoverageResult`.
|
|
|
|
* @return array Test results.
|
|
|
|
*/
|
|
|
|
private function parseTestResult($xunit_tmp, $coverage) {
|
|
|
|
$xunit_dom = new DOMDocument();
|
|
|
|
$xunit_dom->loadXML(Filesystem::readFile($xunit_tmp));
|
|
|
|
|
|
|
|
$results = array();
|
2014-05-23 22:53:05 +02:00
|
|
|
$tests = $xunit_dom->getElementsByTagName('test');
|
2013-09-23 14:32:34 +02:00
|
|
|
foreach ($tests as $test) {
|
2014-05-23 22:53:05 +02:00
|
|
|
$name = $test->getAttribute('name');
|
|
|
|
$time = $test->getAttribute('time');
|
2013-09-23 14:32:34 +02:00
|
|
|
$status = ArcanistUnitTestResult::RESULT_UNSOUND;
|
2014-05-23 22:53:05 +02:00
|
|
|
switch ($test->getAttribute('result')) {
|
|
|
|
case 'Pass':
|
2013-09-23 14:32:34 +02:00
|
|
|
$status = ArcanistUnitTestResult::RESULT_PASS;
|
|
|
|
break;
|
2014-05-23 22:53:05 +02:00
|
|
|
case 'Fail':
|
2013-09-23 14:32:34 +02:00
|
|
|
$status = ArcanistUnitTestResult::RESULT_FAIL;
|
|
|
|
break;
|
2014-05-23 22:53:05 +02:00
|
|
|
case 'Skip':
|
2013-09-23 14:32:34 +02:00
|
|
|
$status = ArcanistUnitTestResult::RESULT_SKIP;
|
|
|
|
break;
|
|
|
|
}
|
2014-05-23 22:53:05 +02:00
|
|
|
$userdata = '';
|
|
|
|
$reason = $test->getElementsByTagName('reason');
|
|
|
|
$failure = $test->getElementsByTagName('failure');
|
2013-09-23 14:32:34 +02:00
|
|
|
if ($reason->length > 0 || $failure->length > 0) {
|
|
|
|
$node = ($reason->length > 0) ? $reason : $failure;
|
2014-05-23 22:53:05 +02:00
|
|
|
$message = $node->item(0)->getElementsByTagName('message');
|
2013-09-23 14:32:34 +02:00
|
|
|
if ($message->length > 0) {
|
|
|
|
$userdata = $message->item(0)->nodeValue;
|
|
|
|
}
|
2014-05-23 22:53:05 +02:00
|
|
|
$stacktrace = $node->item(0)->getElementsByTagName('stack-trace');
|
2013-09-23 14:32:34 +02:00
|
|
|
if ($stacktrace->length > 0) {
|
|
|
|
$userdata .= "\n".$stacktrace->item(0)->nodeValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = new ArcanistUnitTestResult();
|
|
|
|
$result->setName($name);
|
|
|
|
$result->setResult($status);
|
|
|
|
$result->setDuration($time);
|
|
|
|
$result->setUserData($userdata);
|
|
|
|
if ($coverage != null) {
|
|
|
|
$result->setCoverage($this->parseCoverageResult($coverage));
|
|
|
|
}
|
|
|
|
$results[] = $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $results;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|