Changeset View
Changeset View
Standalone View
Standalone View
src/lint/linter/__tests__/ArcanistLinterTestCase.php
| Show First 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | private function lintFile($file, ArcanistLinter $linter) { | ||||
| $exception_message = false; | $exception_message = false; | ||||
| $caught_exception = false; | $caught_exception = false; | ||||
| try { | try { | ||||
| $tmp = new TempFile($basename); | $tmp = new TempFile($basename); | ||||
| Filesystem::writeFile($tmp, $data); | Filesystem::writeFile($tmp, $data); | ||||
| $full_path = (string)$tmp; | $full_path = (string)$tmp; | ||||
| $mode = idx($config, 'mode'); | $mode = idx($config, 'mode', 0644); | ||||
| if ($mode) { | if ($mode) { | ||||
| Filesystem::changePermissions($tmp, octdec($mode)); | Filesystem::changePermissions($tmp, octdec($mode)); | ||||
| } | } | ||||
| $dir = dirname($full_path); | $path_name = idx($config, 'path', $basename); | ||||
| $path = basename($full_path); | |||||
| $working_copy = ArcanistWorkingCopyIdentity::newFromRootAndConfigFile( | $path = id(new ArcanistWorkingCopyPath()) | ||||
| $dir, | ->setPath($path_name) | ||||
| null, | ->setMode($mode) | ||||
| pht('Unit Test')); | ->setData($data); | ||||
| $configuration_manager = new ArcanistConfigurationManager(); | |||||
| $configuration_manager->setWorkingCopyIdentity($working_copy); | |||||
| $engine = new ArcanistUnitTestableLintEngine(); | |||||
| $engine->setWorkingCopy($working_copy); | |||||
| $engine->setConfigurationManager($configuration_manager); | |||||
epriestley: Note that we no longer need any of: a working copy; or a configuration manager; or a "testable"… | |||||
| $path_name = idx($config, 'path', $path); | |||||
| $engine->setPaths(array($path_name)); | |||||
| $linter->addPath($path_name); | |||||
| $linter->addData($path_name, $data); | |||||
| foreach (idx($config, 'config', array()) as $key => $value) { | foreach (idx($config, 'config', array()) as $key => $value) { | ||||
| $linter->setLinterConfigurationValue($key, $value); | $linter->setLinterConfigurationValue($key, $value); | ||||
| } | } | ||||
| $engine->addLinter($linter); | $messages = $linter->lintPaths(array($path)); | ||||
| $engine->addFileData($path_name, $data); | |||||
| $results = $engine->run(); | $result = id(new ArcanistLintResult()) | ||||
| $this->assertEqual( | ->setData($data); | ||||
| 1, | foreach ($messages as $message) { | ||||
| count($results), | $result->addMessage($message); | ||||
| pht('Expect one result returned by linter.')); | } | ||||
| $results = array($result); | |||||
| $assert_stopped = idx($config, 'stopped'); | $assert_stopped = idx($config, 'stopped'); | ||||
| if ($assert_stopped !== null) { | if ($assert_stopped !== null) { | ||||
| $this->assertEqual( | $this->assertEqual( | ||||
| $assert_stopped, | $assert_stopped, | ||||
| $linter->didStopAllLinters(), | $linter->didStopAllLinters(), | ||||
| $assert_stopped | $assert_stopped | ||||
| ? pht('Expect linter to be stopped.') | ? pht('Expect linter to be stopped.') | ||||
| : pht('Expect linter to not be stopped.')); | : pht('Expect linter to not be stopped.')); | ||||
| } | } | ||||
| $result = reset($results); | $result = reset($results); | ||||
| $patcher = ArcanistLintPatcher::newFromArcanistLintResult($result); | $patcher = ArcanistLintPatcher::newFromArcanistLintResult($result); | ||||
| $after_lint = $patcher->getModifiedFileContent(); | $after_lint = $patcher->getModifiedFileContent(); | ||||
| } catch (PhutilTestTerminatedException $ex) { | } catch (PhutilTestTerminatedException $ex) { | ||||
| throw $ex; | throw $ex; | ||||
| } catch (Exception $exception) { | } catch (Exception $exception) { | ||||
| $caught_exception = true; | $caught_exception = true; | ||||
| if ($exception instanceof PhutilAggregateException) { | if ($exception instanceof PhutilAggregateException) { | ||||
| $caught_exception = false; | $caught_exception = false; | ||||
| ▲ Show 20 Lines • Show All 110 Lines • Show Last 20 Lines | |||||
Note that we no longer need any of: a working copy; or a configuration manager; or a "testable" engine to test linters. Although some other simplifications also help permit this, switching to ArcanistWorkingCopyPath as a standalone object is the biggest enabler since linters no longer need to rely on being able to call through chains of parent objects -- like $this->getEngine()->getWorkingCopy()->getRepositoryAPI()->getFileData(...) or whatever -- to pull data.