From 3c3438714b43c2c67e7e0a1c0cc3eb1b01d69ea9 Mon Sep 17 00:00:00 2001 From: Joshua Spence Date: Mon, 15 Jun 2015 07:23:17 +1000 Subject: [PATCH] Further improvements to test discovery 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 | 27 ++++++++++--------- .../PhutilUnitTestEngineTestCase.php | 16 ++++++----- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/unit/engine/PhutilUnitTestEngine.php b/src/unit/engine/PhutilUnitTestEngine.php index 4f4e1e9a..7509b300 100644 --- a/src/unit/engine/PhutilUnitTestEngine.php +++ b/src/unit/engine/PhutilUnitTestEngine.php @@ -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); - do { - $paths[$library_name.':'.$library_path] = array( - 'library' => $library_name, - 'path' => $library_path.'/__tests__/', - ); - } while (($library_path = dirname($library_path)) != '.'); + $paths[$library_name.':'.$library_subpath] = array( + 'library' => $library_name, + 'path' => $library_subpath.'/__tests__/', + ); + } + } } return $paths; diff --git a/src/unit/engine/__tests__/PhutilUnitTestEngineTestCase.php b/src/unit/engine/__tests__/PhutilUnitTestEngineTestCase.php index 2576bdd2..87065627 100644 --- a/src/unit/engine/__tests__/PhutilUnitTestEngineTestCase.php +++ b/src/unit/engine/__tests__/PhutilUnitTestEngineTestCase.php @@ -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),