mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-26 00:32:41 +01:00
Run phutil unit tests in v2 libraries
Summary: Move away from setModule(), to setPathPrefix(). Also simplify test location/selection. Depends on D2621. Test Plan: Ran "arc unit". Reviewers: vrana, btrahan Reviewed By: vrana CC: aran Maniphest Tasks: T1103 Differential Revision: https://secure.phabricator.com/D2622
This commit is contained in:
parent
d80c4f683e
commit
e214ea7b18
1 changed files with 21 additions and 52 deletions
|
@ -27,7 +27,8 @@ final class PhutilUnitTestEngine extends ArcanistBaseUnitTestEngine {
|
||||||
|
|
||||||
$bootloader = PhutilBootloader::getInstance();
|
$bootloader = PhutilBootloader::getInstance();
|
||||||
|
|
||||||
$affected_modules = array();
|
$look_here = array();
|
||||||
|
|
||||||
foreach ($this->getPaths() as $path) {
|
foreach ($this->getPaths() as $path) {
|
||||||
$library_root = phutil_get_library_root_for_path($path);
|
$library_root = phutil_get_library_root_for_path($path);
|
||||||
if (!$library_root) {
|
if (!$library_root) {
|
||||||
|
@ -67,67 +68,36 @@ final class PhutilUnitTestEngine extends ArcanistBaseUnitTestEngine {
|
||||||
|
|
||||||
$library_path = Filesystem::readablePath($path, $library_root);
|
$library_path = Filesystem::readablePath($path, $library_root);
|
||||||
do {
|
do {
|
||||||
// Add the module and all parent modules as affected modules, which
|
$look_here[$library_name.':'.$library_path] = array(
|
||||||
// means we'll look for __tests__ to run here and in any containing
|
'library' => $library_name,
|
||||||
// module.
|
'path' => $library_path,
|
||||||
$affected_modules[$library_name.':'.$library_path] = array(
|
|
||||||
'name' => $library_name,
|
|
||||||
'root' => $library_root,
|
|
||||||
'path' => $library_path,
|
|
||||||
);
|
);
|
||||||
$library_path = dirname($library_path);
|
$library_path = dirname($library_path);
|
||||||
} while ($library_path != '.');
|
} while ($library_path != '.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$tests = array();
|
// Look for any class that extends ArcanistPhutilTestCase inside a
|
||||||
foreach ($affected_modules as $library_info) {
|
// __tests__ directory in any parent directory of every affected file.
|
||||||
$library_name = $library_info['name'];
|
//
|
||||||
$library_root = $library_info['root'];
|
// The idea is that "infrastructure/__tests__/" tests defines general tests
|
||||||
$module = $library_info['path'];
|
// for all of "infrastructure/", and those tests run for any change in
|
||||||
|
// "infrastructure/". However, "infrastructure/concrete/rebar/__tests__/"
|
||||||
if (basename($module) == '__tests__') {
|
// defines more specific tests that run only when rebar/ (or some
|
||||||
// Okay, this is a __tests__ module.
|
// subdirectory) changes.
|
||||||
} else {
|
|
||||||
$exists = $bootloader->moduleExists(
|
|
||||||
$library_name,
|
|
||||||
$module.'/__tests__');
|
|
||||||
if ($exists) {
|
|
||||||
// This is a module which has a __tests__ module in it.
|
|
||||||
$module .= '/__tests__';
|
|
||||||
} else {
|
|
||||||
// Look for a parent named __tests__.
|
|
||||||
$rpos = strrpos($module, '/__tests__');
|
|
||||||
if ($rpos === false) {
|
|
||||||
// No tests to run since there is no child or parent module named
|
|
||||||
// __tests__.
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// Select the parent named __tests__.
|
|
||||||
$module = substr($module, 0, $rpos + strlen('/__tests__'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$module_key = $library_name.':'.$module;
|
|
||||||
$tests[$module_key] = array(
|
|
||||||
'library' => $library_name,
|
|
||||||
'root' => $library_root,
|
|
||||||
'module' => $module,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$tests) {
|
|
||||||
throw new ArcanistNoEffectException("No tests to run.");
|
|
||||||
}
|
|
||||||
|
|
||||||
$run_tests = array();
|
$run_tests = array();
|
||||||
foreach ($tests as $test) {
|
foreach ($look_here as $path_info) {
|
||||||
|
$library = $path_info['library'];
|
||||||
|
$path = $path_info['path'];
|
||||||
|
|
||||||
$symbols = id(new PhutilSymbolLoader())
|
$symbols = id(new PhutilSymbolLoader())
|
||||||
->setType('class')
|
->setType('class')
|
||||||
->setLibrary($test['library'])
|
->setLibrary($library)
|
||||||
->setModule($test['module'])
|
->setPathPrefix($path.'/__tests__/')
|
||||||
->setAncestorClass('ArcanistPhutilTestCase')
|
->setAncestorClass('ArcanistPhutilTestCase')
|
||||||
->setConcreteOnly(true)
|
->setConcreteOnly(true)
|
||||||
->selectAndLoadSymbols();
|
->selectAndLoadSymbols();
|
||||||
|
|
||||||
foreach ($symbols as $symbol) {
|
foreach ($symbols as $symbol) {
|
||||||
$run_tests[$symbol['name']] = true;
|
$run_tests[$symbol['name']] = true;
|
||||||
}
|
}
|
||||||
|
@ -135,8 +105,7 @@ final class PhutilUnitTestEngine extends ArcanistBaseUnitTestEngine {
|
||||||
$run_tests = array_keys($run_tests);
|
$run_tests = array_keys($run_tests);
|
||||||
|
|
||||||
if (!$run_tests) {
|
if (!$run_tests) {
|
||||||
throw new ArcanistNoEffectException(
|
throw new ArcanistNoEffectException("No tests to run.");
|
||||||
"No tests to run. You may need to rebuild the phutil library map.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$enable_coverage = $this->getEnableCoverage();
|
$enable_coverage = $this->getEnableCoverage();
|
||||||
|
|
Loading…
Reference in a new issue