]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Allow `PhutilUnitTestEngine::getTestsForPaths` to return paths from the library root...
authorJoshua Spence <josh@joshuaspence.com>
Thu, 9 Jan 2014 13:21:55 +0000 (05:21 -0800)
committerepriestley <git@epriestley.com>
Thu, 9 Jan 2014 13:21:55 +0000 (05:21 -0800)
Summary: Currently, running `arc unit -- src/` returns with `No tests to run`, even if there are test classes in `src/__tests__/`. This diff changes this behaviour so that `arc unit -- src/` executes unit tests in `src/__tests__/`.

Test Plan: N/A. I suppose you could create a file `src/__tests__/SomeTestCase.php` and see for yourself.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley

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

src/unit/engine/PhutilUnitTestEngine.php

index dbd3c9d35fb58b68c0e43f033e97471f39107f29..f722d107cd0aa99b51adf25769a65ca69dd01e78 100644 (file)
@@ -133,25 +133,26 @@ final class PhutilUnitTestEngine extends ArcanistBaseUnitTestEngine {
       }
 
       if ($path == $library_root) {
-        continue;
-      }
-
-      if (!Filesystem::isDescendant($path, $library_root)) {
+        $look_here[$library_name.':.'] = array(
+          'library' => $library_name,
+          'path'    => '',
+        );
+      } else if (!Filesystem::isDescendant($path, $library_root)) {
         // We have encountered some kind of symlink maze -- for instance, $path
         // is some symlink living outside the library that links into some file
         // inside the library. Just ignore these cases, since the affected file
         // does not actually lie within the library.
         continue;
+      } else {
+        $library_path = Filesystem::readablePath($path, $library_root);
+        do {
+          $look_here[$library_name.':'.$library_path] = array(
+            'library' => $library_name,
+            'path'    => $library_path,
+          );
+          $library_path = dirname($library_path);
+        } while ($library_path != '.');
       }
-
-      $library_path = Filesystem::readablePath($path, $library_root);
-      do {
-        $look_here[$library_name.':'.$library_path] = array(
-          'library' => $library_name,
-          'path'    => $library_path,
-        );
-        $library_path = dirname($library_path);
-      } while ($library_path != '.');
     }
 
     // Look for any class that extends ArcanistPhutilTestCase inside a
@@ -171,7 +172,7 @@ final class PhutilUnitTestEngine extends ArcanistBaseUnitTestEngine {
       $symbols = id(new PhutilSymbolLoader())
         ->setType('class')
         ->setLibrary($library)
-        ->setPathPrefix($path.'/__tests__/')
+        ->setPathPrefix(($path ? $path.'/' : '').'__tests__/')
         ->setAncestorClass('ArcanistPhutilTestCase')
         ->setConcreteOnly(true)
         ->selectAndLoadSymbols();