From 66e3614f6934fc471e1ba48b310f6865b2f75a07 Mon Sep 17 00:00:00 2001 From: Joshua Spence Date: Thu, 9 Jan 2014 05:21:55 -0800 Subject: [PATCH] Allow `PhutilUnitTestEngine::getTestsForPaths` to return paths from the library root directory 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 | 29 ++++++++++++------------ 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/unit/engine/PhutilUnitTestEngine.php b/src/unit/engine/PhutilUnitTestEngine.php index dbd3c9d3..f722d107 100644 --- a/src/unit/engine/PhutilUnitTestEngine.php +++ b/src/unit/engine/PhutilUnitTestEngine.php @@ -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(); -- 2.43.0