]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Improve test discovery with PhutilUnitTestEngine
authorJoshua Spence <josh@joshuaspence.com>
Wed, 3 Jun 2015 11:07:17 +0000 (21:07 +1000)
committerJoshua Spence <josh@joshuaspence.com>
Wed, 3 Jun 2015 11:07:17 +0000 (21:07 +1000)
Summary:
Ref T8042. Tests were not being discovered in two different scenarios:

  # Files modified at the same level as the library root directory.
  # "Normal" directories like `src/unit/engine`.

This regression was caused by D12689.

Test Plan: Added unit tests.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T8042

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

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

index 58cf52dff1f1850c886ac356f1857d191735761f..4f4e1e9a914932a77f10dab81492ec14b21b9a7b 100644 (file)
@@ -197,12 +197,20 @@ final class PhutilUnitTestEngine extends ArcanistUnitTestEngine {
         continue;
       }
 
-      while (($library_path = dirname($library_path)) != '.') {
+      if ($path == $library_root) {
+        $paths[$library_name.':.'] = array(
+          'library' => $library_name,
+          'path'    => '__tests__/',
+        );
+        continue;
+      }
+
+      do {
         $paths[$library_name.':'.$library_path] = array(
           'library' => $library_name,
           'path'    => $library_path.'/__tests__/',
         );
-      }
+      } while (($library_path = dirname($library_path)) != '.');
     }
 
     return $paths;
index 11c132d9d6dcfbe7ca3d50b1981c84a2e8283ed6..2576bdd2c88456f44c0c6b4c40270cafcade7356 100644 (file)
@@ -122,29 +122,47 @@ final class PhutilUnitTestEngineTestCase extends PhutilTestCase {
 
   public function testGetTestPaths() {
     $tests = array(
-      array(
+      'empty' => array(
         array(),
         array(),
       ),
 
-      array(
+      'test file' => array(
         array(__FILE__),
         array(__FILE__),
       ),
 
-      array(
-        array(dirname(__FILE__)),
+      'test directory' => array(
+        array(
+          dirname(__FILE__),
+        ),
+        array(
+          // This is odd, but harmless.
+          dirname(dirname(__FILE__)).'/__tests__/__tests__/',
+
+          dirname(dirname(__FILE__)).'/__tests__/',
+          dirname(dirname(dirname(__FILE__))).'/__tests__/',
+        ),
+      ),
+      'normal directory' => array(
+        array(
+          dirname(dirname(__FILE__)),
+        ),
         array(
           dirname(dirname(__FILE__)).'/__tests__/',
           dirname(dirname(dirname(__FILE__))).'/__tests__/',
         ),
       ),
+      'library root' => array(
+        array(phutil_get_library_root()),
+        array(phutil_get_library_root().'/__tests__/'),
+      ),
     );
 
     $test_engine = id(new PhutilUnitTestEngine())
       ->setWorkingCopy($this->getWorkingCopy());
 
-    foreach ($tests as $test) {
+    foreach ($tests as $name => $test) {
       list($paths, $tests) = $test;
       $expected = array();
 
@@ -159,7 +177,10 @@ final class PhutilUnitTestEngineTestCase extends PhutilTestCase {
       }
 
       $test_engine->setPaths($paths);
-      $this->assertEqual($expected, array_values($test_engine->getTestPaths()));
+      $this->assertEqual(
+        $expected,
+        array_values($test_engine->getTestPaths()),
+        pht('Test paths for: "%s"', $name));
     }
   }