]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Further improvements to test discovery
authorJoshua Spence <josh@joshuaspence.com>
Sun, 14 Jun 2015 21:23:17 +0000 (07:23 +1000)
committerJoshua Spence <josh@joshuaspence.com>
Sun, 14 Jun 2015 21:23:17 +0000 (07:23 +1000)
Summary: I found another issue with T8042... it seems that tests from the root directory (i.e. `src/__tests__` are not being discovered properly). The handling of this case (`$library_path` being the library root directory) can probably be improved, and I am open to suggestions. Depends on D13202.

Test Plan: Added to existing test cases.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin, epriestley

Differential Revision: https://secure.phabricator.com/D13185

src/unit/engine/PhutilUnitTestEngine.php
src/unit/engine/__tests__/PhutilUnitTestEngineTestCase.php

index 4f4e1e9a914932a77f10dab81492ec14b21b9a7b..7509b30040e2ef7d5f0ea6c84e57eba35f1933fe 100644 (file)
@@ -197,20 +197,21 @@ final class PhutilUnitTestEngine extends ArcanistUnitTestEngine {
         continue;
       }
 
-      if ($path == $library_root) {
-        $paths[$library_name.':.'] = array(
-          'library' => $library_name,
-          'path'    => '__tests__/',
-        );
-        continue;
+      foreach (Filesystem::walkToRoot($path, $library_root) as $subpath) {
+        if ($subpath == $library_root) {
+          $paths[$library_name.':.'] = array(
+            'library' => $library_name,
+            'path'    => '__tests__/',
+          );
+        } else {
+          $library_subpath = Filesystem::readablePath($subpath, $library_root);
+
+          $paths[$library_name.':'.$library_subpath] = array(
+            'library' => $library_name,
+            'path'    => $library_subpath.'/__tests__/',
+          );
+        }
       }
-
-      do {
-        $paths[$library_name.':'.$library_path] = array(
-          'library' => $library_name,
-          'path'    => $library_path.'/__tests__/',
-        );
-      } while (($library_path = dirname($library_path)) != '.');
     }
 
     return $paths;
index 2576bdd2c88456f44c0c6b4c40270cafcade7356..8706562758687d3042637a04b3817f1451661c51 100644 (file)
@@ -142,6 +142,7 @@ final class PhutilUnitTestEngineTestCase extends PhutilTestCase {
 
           dirname(dirname(__FILE__)).'/__tests__/',
           dirname(dirname(dirname(__FILE__))).'/__tests__/',
+          phutil_get_library_root('arcanist').'/__tests__/',
         ),
       ),
       'normal directory' => array(
@@ -151,25 +152,26 @@ final class PhutilUnitTestEngineTestCase extends PhutilTestCase {
         array(
           dirname(dirname(__FILE__)).'/__tests__/',
           dirname(dirname(dirname(__FILE__))).'/__tests__/',
+          phutil_get_library_root('arcanist').'/__tests__/',
         ),
       ),
       'library root' => array(
-        array(phutil_get_library_root()),
-        array(phutil_get_library_root().'/__tests__/'),
+        array(phutil_get_library_root('arcanist')),
+        array(phutil_get_library_root('arcanist').'/__tests__/'),
       ),
     );
 
     $test_engine = id(new PhutilUnitTestEngine())
       ->setWorkingCopy($this->getWorkingCopy());
 
+    $library = phutil_get_current_library_name();
+    $library_root = phutil_get_library_root($library);
+
     foreach ($tests as $name => $test) {
-      list($paths, $tests) = $test;
+      list($paths, $test_paths) = $test;
       $expected = array();
 
-      foreach ($tests as $path) {
-        $library_root = phutil_get_library_root_for_path($path);
-        $library = phutil_get_library_name_for_root($library_root);
-
+      foreach ($test_paths as $path) {
         $expected[] = array(
           'library' => $library,
           'path' => Filesystem::readablePath($path, $library_root),