From f58642a8ab99249c3ee798be3df70b25022e0d62 Mon Sep 17 00:00:00 2001 From: Joshua Spence Date: Tue, 13 Jan 2015 06:42:09 +1100 Subject: [PATCH] Add unit tests for `ArcanistFilenameLinter` Summary: Self-explanatory. Test Plan: `arc unit` Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: Korvin, epriestley Differential Revision: https://secure.phabricator.com/D11341 --- src/__phutil_library_map__.php | 2 ++ src/lint/engine/ArcanistUnitTestableLintEngine.php | 2 +- .../__tests__/ArcanistFilenameLinterTestCase.php | 10 ++++++++++ src/lint/linter/__tests__/ArcanistLinterTestCase.php | 9 ++++++--- .../linter/__tests__/filename/bad_filename.lint-test | 5 +++++ .../linter/__tests__/filename/good_filename.lint-test | 4 ++++ 6 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 src/lint/linter/__tests__/ArcanistFilenameLinterTestCase.php create mode 100644 src/lint/linter/__tests__/filename/bad_filename.lint-test create mode 100644 src/lint/linter/__tests__/filename/good_filename.lint-test diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index e7c44504..f75c0a5a 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -74,6 +74,7 @@ phutil_register_library_map(array( 'ArcanistExternalLinterTestCase' => 'lint/linter/__tests__/ArcanistExternalLinterTestCase.php', 'ArcanistFeatureWorkflow' => 'workflow/ArcanistFeatureWorkflow.php', 'ArcanistFilenameLinter' => 'lint/linter/ArcanistFilenameLinter.php', + 'ArcanistFilenameLinterTestCase' => 'lint/linter/__tests__/ArcanistFilenameLinterTestCase.php', 'ArcanistFlagWorkflow' => 'workflow/ArcanistFlagWorkflow.php', 'ArcanistFlake8Linter' => 'lint/linter/ArcanistFlake8Linter.php', 'ArcanistFlake8LinterTestCase' => 'lint/linter/__tests__/ArcanistFlake8LinterTestCase.php', @@ -269,6 +270,7 @@ phutil_register_library_map(array( 'ArcanistExternalLinterTestCase' => 'ArcanistLinterTestCase', 'ArcanistFeatureWorkflow' => 'ArcanistWorkflow', 'ArcanistFilenameLinter' => 'ArcanistLinter', + 'ArcanistFilenameLinterTestCase' => 'ArcanistArcanistLinterTestCase', 'ArcanistFlagWorkflow' => 'ArcanistWorkflow', 'ArcanistFlake8Linter' => 'ArcanistExternalLinter', 'ArcanistFlake8LinterTestCase' => 'ArcanistExternalLinterTestCase', diff --git a/src/lint/engine/ArcanistUnitTestableLintEngine.php b/src/lint/engine/ArcanistUnitTestableLintEngine.php index af30a104..08393944 100644 --- a/src/lint/engine/ArcanistUnitTestableLintEngine.php +++ b/src/lint/engine/ArcanistUnitTestableLintEngine.php @@ -19,7 +19,7 @@ final class ArcanistUnitTestableLintEngine extends ArcanistLintEngine { } public function pathExists($path) { - if (idx($this->fileData, $path)) { + if (idx($this->fileData, $path) !== null) { return true; } return parent::pathExists($path); diff --git a/src/lint/linter/__tests__/ArcanistFilenameLinterTestCase.php b/src/lint/linter/__tests__/ArcanistFilenameLinterTestCase.php new file mode 100644 index 00000000..7b439888 --- /dev/null +++ b/src/lint/linter/__tests__/ArcanistFilenameLinterTestCase.php @@ -0,0 +1,10 @@ +executeTestsInDirectory(dirname(__FILE__).'/filename/'); + } + +} diff --git a/src/lint/linter/__tests__/ArcanistLinterTestCase.php b/src/lint/linter/__tests__/ArcanistLinterTestCase.php index 3b019f21..4de8005c 100644 --- a/src/lint/linter/__tests__/ArcanistLinterTestCase.php +++ b/src/lint/linter/__tests__/ArcanistLinterTestCase.php @@ -207,15 +207,18 @@ abstract class ArcanistLinterTestCase extends ArcanistPhutilTestCase { implode("\n", $raised)); foreach (array_diff_key($expect, $seen) as $missing => $ignored) { - list($sev, $line, $char) = explode(':', $missing); + $missing = explode(':', $missing); + $sev = array_shift($missing); + $pos = $missing; + $this->assertFailure( pht( "In '%s', expected lint to raise %s on line %d at char %d, ". "but no %s was raised. %s", $file, $sev, - $line, - $char, + idx($pos, 0), + idx($pos, 1), $sev, $raised)); } diff --git a/src/lint/linter/__tests__/filename/bad_filename.lint-test b/src/lint/linter/__tests__/filename/bad_filename.lint-test new file mode 100644 index 00000000..7eb7c745 --- /dev/null +++ b/src/lint/linter/__tests__/filename/bad_filename.lint-test @@ -0,0 +1,5 @@ +~~~~~~~~~~ +error:: +~~~~~~~~~~ +~~~~~~~~~~ +{"path": "bad@filename"} diff --git a/src/lint/linter/__tests__/filename/good_filename.lint-test b/src/lint/linter/__tests__/filename/good_filename.lint-test new file mode 100644 index 00000000..ceedd465 --- /dev/null +++ b/src/lint/linter/__tests__/filename/good_filename.lint-test @@ -0,0 +1,4 @@ +~~~~~~~~~~ +~~~~~~~~~~ +~~~~~~~~~~ +{"path": "good_filename"}