Changeset View
Changeset View
Standalone View
Standalone View
arcanist/linter/TestsLinter.php
Show All 9 Lines | final class TestsLinter extends ArcanistExternalLinter { | ||||
} | } | ||||
public function getInfoURI() { | public function getInfoURI() { | ||||
return ''; | return ''; | ||||
} | } | ||||
public function getInfoDescription() { | public function getInfoDescription() { | ||||
return pht('Check the unit tests for duplicates and ensure the file name '. | return pht('Check the unit tests for duplicates and ensure the file name '. | ||||
'matches the boost test suite name.'); | 'matches the boost test suite name.'); | ||||
} | } | ||||
public function getLinterName() { | public function getLinterName() { | ||||
return 'lint-tests'; | return 'lint-tests'; | ||||
} | } | ||||
public function getLinterConfigurationName() { | public function getLinterConfigurationName() { | ||||
return 'lint-tests'; | return 'lint-tests'; | ||||
} | } | ||||
public function getLinterConfigurationOptions() { | public function getLinterConfigurationOptions() { | ||||
$options = array( | $options = array(); | ||||
); | |||||
return $options + parent::getLinterConfigurationOptions(); | return $options + parent::getLinterConfigurationOptions(); | ||||
} | } | ||||
public function getDefaultBinary() { | public function getDefaultBinary() { | ||||
return Filesystem::resolvePath( | return Filesystem::resolvePath('test/lint/lint-tests.sh', | ||||
'test/lint/lint-tests.sh', | |||||
$this->getProjectRoot()); | $this->getProjectRoot()); | ||||
} | } | ||||
public function shouldUseInterpreter() { | public function shouldUseInterpreter() { | ||||
return true; | return true; | ||||
} | } | ||||
public function getDefaultInterpreter() { | public function getDefaultInterpreter() { | ||||
return "bash"; | return "bash"; | ||||
} | } | ||||
public function getInstallInstructions() { | public function getInstallInstructions() { | ||||
return pht('The test/lint/lint-tests.sh script is part of the bitcoin-abc '. | return pht('The test/lint/lint-tests.sh script is part of the bitcoin-abc '. | ||||
'project'); | 'project'); | ||||
} | } | ||||
public function shouldExpectCommandErrors() { | public function shouldExpectCommandErrors() { | ||||
return false; | return false; | ||||
} | } | ||||
protected function getMandatoryFlags() { | protected function getMandatoryFlags() { | ||||
return array( | return array(); | ||||
); | |||||
} | } | ||||
protected function parseLinterOutput($path, $err, $stdout, $stderr) { | protected function parseLinterOutput($path, $err, $stdout, $stderr) { | ||||
/* | /* | ||||
* Stdout contains 2 sections: | * Stdout contains 2 sections: | ||||
* 1/ Section with name mismatches, in the form: | * 1/ Section with name mismatches, in the form: | ||||
* <file path>:BOOST_FIXTURE_TEST_SUITE(<test name>, ... | * <file path>:BOOST_FIXTURE_TEST_SUITE(<test name>, ... | ||||
* 2/ Section with duplicated test names: | * 2/ Section with duplicated test names: | ||||
* <test_name> | * <test_name> | ||||
*/ | */ | ||||
/* | /* | ||||
* Extract infos from the path | * Extract infos from the path | ||||
* | * | ||||
* Note: the files are already filtered by path thanks to the .arclint | * Note: the files are already filtered by path thanks to the .arclint | ||||
* configuration. If the file is not a test, the grep will find nothing and | * configuration. If the file is not a test, the grep will find nothing and | ||||
* there will be no error to parse. | * there will be no error to parse. | ||||
*/ | */ | ||||
$pathinfo = pathinfo($path); | $pathinfo = pathinfo($path); | ||||
$testName = $pathinfo['filename']; | $testName = $pathinfo['filename']; | ||||
$fileName = $pathinfo['basename']; | $fileName = $pathinfo['basename']; | ||||
$messages = []; | $messages = []; | ||||
/* Search for mismatch, using the line pattern */ | /* Search for mismatch, using the line pattern */ | ||||
$pattern = '/'.$fileName.':BOOST_FIXTURE_TEST_SUITE\(([\w]+)/'; | $pattern = '/'.$fileName.':BOOST_FIXTURE_TEST_SUITE\(([\w]+)/'; | ||||
$mismatch = preg_match($pattern, $stdout, $matches); | $mismatch = preg_match($pattern, $stdout, $matches); | ||||
if ($mismatch) { | if ($mismatch) { | ||||
/* | /* | ||||
* Expect a single result as we are testing against a single file. | * Expect a single result as we are testing against a single file. | ||||
* - $matches[0] contains the full mask | * - $matches[0] contains the full mask | ||||
* - $matches[1] contains the captured match | * - $matches[1] contains the captured match | ||||
*/ | */ | ||||
if (count($matches) != 2) { | if (count($matches) != 2) { | ||||
throw new Exception( | throw new Exception( | ||||
pht('Found multiple matches for a single file, lint-tests.sh output '. | pht('Found multiple matches for a single file, lint-tests.sh output '. | ||||
'is not formatted as expected, aborting.')); | 'is not formatted as expected, aborting.')); | ||||
} | } | ||||
$mismatchName = $matches[1]; | $mismatchName = $matches[1]; | ||||
$messages[] = id(new ArcanistLintMessage()) | $messages[] = id(new ArcanistLintMessage()) | ||||
->setGranularity(ArcanistLinter::GRANULARITY_FILE) | ->setGranularity(ArcanistLinter::GRANULARITY_FILE) | ||||
->setCode('TESTS') | ->setCode('TESTS') | ||||
->setPath($path) | ->setPath($path) | ||||
->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR) | ->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR) | ||||
->setName('Name mismatch') | ->setName('Name mismatch') | ||||
->setDescription( | ->setDescription( | ||||
'The Boost test suite name must match the file name (set to "'. | 'The Boost test suite name must match the file name (set to "'. | ||||
$mismatchName.'", should be "'.$testName.'").'); | $mismatchName.'", should be "'.$testName.'").'); | ||||
} | } | ||||
/* | /* | ||||
* Search for unicity, searching for test name alone on its line. | * Search for unicity, searching for test name alone on its line. | ||||
* The test name can be whether the one extracted from the file name or the | * The test name can be whether the one extracted from the file name or the | ||||
* one extracted from the BOOST_FIXTURE_TEST_SUITE content. | * one extracted from the BOOST_FIXTURE_TEST_SUITE content. | ||||
*/ | */ | ||||
if ($mismatch) { | if ($mismatch) { | ||||
$pattern = '/^'.$testName.'|'.$mismatchName.'$/'; | $pattern = '/^'.$testName.'|'.$mismatchName.'$/'; | ||||
} else { | } else { | ||||
$pattern = '/^'.$testName.'$/'; | $pattern = '/^'.$testName.'$/'; | ||||
} | } | ||||
$notUnique = preg_match($pattern, $stdout, $matches); | $notUnique = preg_match($pattern, $stdout, $matches); | ||||
/* | /* | ||||
* Do not check the number of matches here. | * Do not check the number of matches here. | ||||
* Because it is a test against unicity, there is a global search which can | * Because it is a test against unicity, there is a global search which can | ||||
* possibly return an output matching our expected test name AND our actual | * possibly return an output matching our expected test name AND our actual | ||||
* test name. This would be weird, but not impossible. | * test name. This would be weird, but not impossible. | ||||
* Just returning an error for the first one is enough, as the linter will | * Just returning an error for the first one is enough, as the linter will | ||||
* be rerun after the name is fix and the other match will then eventually | * be rerun after the name is fix and the other match will then eventually | ||||
* get catched. | * get catched. | ||||
*/ | */ | ||||
if ($notUnique) { | if ($notUnique) { | ||||
$messages[] = id(new ArcanistLintMessage()) | $messages[] = id(new ArcanistLintMessage()) | ||||
->setGranularity(ArcanistLinter::GRANULARITY_FILE) | ->setGranularity(ArcanistLinter::GRANULARITY_FILE) | ||||
->setCode('TESTS') | ->setCode('TESTS') | ||||
->setPath($path) | ->setPath($path) | ||||
->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR) | ->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR) | ||||
->setName('Duplicated name') | ->setName('Duplicated name') | ||||
->setDescription('The test name "'.$matches[0].'" already exists'); | ->setDescription('The test name "'.$matches[0].'" already exists'); | ||||
deadalnix: The indentation is wrong here and all similar patterns. | |||||
} | } | ||||
return $messages; | return $messages; | ||||
} | } | ||||
} | } | ||||
?> |
The indentation is wrong here and all similar patterns.