]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Update C# tools unit test engine to work
authorJames Rhodes <jrhodes@redpointsoftware.com.au>
Tue, 26 Nov 2013 07:00:44 +0000 (18:00 +1100)
committerJames Rhodes <jrhodes@redpointsoftware.com.au>
Tue, 26 Nov 2013 07:00:44 +0000 (18:00 +1100)
Summary: This updates the C# tools unit test engine (the derived version of xUnit.NET test engine that supports code coverage) to work after the updates in D7594.

Test Plan:
Switched the test engine from 'XUnitTestEngine' to 'CSharpToolsTestEngine' and ran `arc unit --everything`.  The results were identical except that code coverage was provided.

Tested on Linux; will update or comment based on whether it works on Windows as well.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley

CC: Korvin, epriestley, aran
Differential Revision: https://secure.phabricator.com/D7640

src/unit/engine/CSharpToolsTestEngine.php
src/unit/engine/XUnitTestEngine.php

index 34f8e511ea18d8d7e06d3c61cb922862231ab94c..9b85257a9d461a68723662a788244a4a8c20eb47 100644 (file)
@@ -23,12 +23,9 @@ final class CSharpToolsTestEngine extends XUnitTestEngine {
    * of configuration values and to pull in the cstools config for
    * code coverage.
    */
-  protected function loadEnvironment(
-    $config_item = 'unit.csharp.xunit.binary') {
+  protected function loadEnvironment() {
 
     $config = $this->getConfigurationManager();
-    $this->xunitHintPath =
-      $config->getConfigFromAnySource('unit.csharp.xunit.binary');
     $this->cscoverHintPath =
       $config->getConfigFromAnySource('unit.csharp.cscover.binary');
     $this->matchRegex =
@@ -36,7 +33,7 @@ final class CSharpToolsTestEngine extends XUnitTestEngine {
     $this->excludedFiles =
       $config->getConfigFromAnySource('unit.csharp.coverage.excluded');
 
-    parent::loadEnvironment($config_item);
+    parent::loadEnvironment();
 
     if ($this->getEnableCoverage() === false) {
       return;
@@ -48,7 +45,7 @@ final class CSharpToolsTestEngine extends XUnitTestEngine {
         "Unable to locate cscover.  Configure it with ".
         "the `unit.csharp.coverage.binary' option in .arcconfig");
     }
-    $cscover = $this->projectRoot."/".$this->cscoverHintPath;
+    $cscover = $this->projectRoot.DIRECTORY_SEPARATOR.$this->cscoverHintPath;
     if (file_exists($cscover)) {
       $this->coverEngine = Filesystem::resolvePath($cscover);
     } else {
@@ -98,7 +95,7 @@ final class CSharpToolsTestEngine extends XUnitTestEngine {
     // FIXME: Can't use TempFile here as xUnit doesn't like
     // UNIX-style full paths.  It sees the leading / as the
     // start of an option flag, even when quoted.
-    $xunit_temp = $test_assembly.".results.xml";
+    $xunit_temp = Filesystem::readRandomCharacters(10).".results.xml";
     if (file_exists($xunit_temp)) {
       unlink($xunit_temp);
     }
@@ -109,22 +106,22 @@ final class CSharpToolsTestEngine extends XUnitTestEngine {
     if ($xunit_cmd === "") {
       $xunit_cmd = $this->testEngine;
       $xunit_args = csprintf(
-        "%s /xml %s /silent",
-        $test_assembly.".dll",
+        "%s /xml %s",
+        $test_assembly,
         $xunit_temp);
     } else {
       $xunit_args = csprintf(
-        "%s %s /xml %s /silent",
+        "%s %s /xml %s",
         $this->testEngine,
-        $test_assembly.".dll",
+        $test_assembly,
         $xunit_temp);
     }
-    $assembly_dir = $test_assembly."/bin/Debug/";
+    $assembly_dir = dirname($test_assembly);
     $assemblies_to_instrument = array();
     foreach (Filesystem::listDirectory($assembly_dir) as $file) {
       if (substr($file, -4) == ".dll" || substr($file, -4) == ".exe") {
         if ($this->assemblyShouldBeInstrumented($file)) {
-          $assemblies_to_instrument[] = $assembly_dir.$file;
+          $assemblies_to_instrument[] = $assembly_dir.DIRECTORY_SEPARATOR.$file;
         }
       }
     }
@@ -142,7 +139,7 @@ final class CSharpToolsTestEngine extends XUnitTestEngine {
     $future->setCWD(Filesystem::resolvePath($this->projectRoot));
     return array(
       $future,
-      $this->projectRoot."/".$assembly_dir.$xunit_temp,
+      $assembly_dir.DIRECTORY_SEPARATOR.$xunit_temp,
       $cover_temp);
   }
 
@@ -245,7 +242,8 @@ final class CSharpToolsTestEngine extends XUnitTestEngine {
     }
 
     foreach ($files as $file) {
-      $absolute_file = $this->projectRoot."/".$file;
+      $absolute_file = Filesystem::resolvePath(
+        $this->projectRoot.DIRECTORY_SEPARATOR.$file);
 
       // get total line count in file
       $line_count = count(file($absolute_file));
index db18bbefc4bf5a87e3dd6aa49c6398117bf13c3d..003382446bdb01153758030b84076fc5a9859c74 100644 (file)
@@ -34,7 +34,7 @@ class XUnitTestEngine extends ArcanistBaseUnitTestEngine {
    *
    * @return void
    */
-  protected function loadEnvironment($config_item = 'unit.xunit.binary') {
+  protected function loadEnvironment() {
     $this->projectRoot = $this->getWorkingCopy()->getProjectRoot();
 
     // Determine build engine.
@@ -79,7 +79,7 @@ class XUnitTestEngine extends ArcanistBaseUnitTestEngine {
     } else {
       throw new Exception(
         "Unable to locate xUnit console runner.  Configure ".
-        "it with the `$config_item' option in .arcconfig");
+        "it with the `unit.csharp.xunit.binary' option in .arcconfig");
     }
   }