|
9 | 9 |
|
10 | 10 | namespace Facebook\HHAST\Tests; |
11 | 11 |
|
12 | | -use type Facebook\HackTest\HackTest; |
13 | 12 | use function Facebook\FBExpect\expect; |
14 | 13 | use type Facebook\HHAST\{ |
| 14 | + LinterCLITestTrait, |
15 | 15 | PreferRequireOnceLinter, |
16 | 16 | SingleRuleLintError, |
17 | 17 | SingleRuleLinter, |
| 18 | + TestCase, |
18 | 19 | }; |
19 | 20 | use type Facebook\HHAST\__Private\LintRunConfig; |
20 | 21 |
|
21 | 22 | abstract class EmptyBaseLinter extends SingleRuleLinter { |
22 | 23 | <<__Override>> |
23 | | - final public async function getLintErrorsAsync(): Awaitable<vec<SingleRuleLintError>> { |
| 24 | + final public async function getLintErrorsAsync( |
| 25 | + ): Awaitable<vec<SingleRuleLintError>> { |
24 | 26 | return vec[]; |
25 | 27 | } |
26 | 28 | final public function getConfigPublic(): ?this::TConfig { |
@@ -54,9 +56,13 @@ final class ConfigTypeIsNotSupportedByTypeAssertLinter extends EmptyBaseLinter { |
54 | 56 | const type TConfig = shape('impossible' => vec<nothing>); |
55 | 57 | } |
56 | 58 |
|
57 | | -final class LinterConfigTest extends HackTest { |
| 59 | +final class LinterConfigTest extends TestCase { |
| 60 | + use LinterCLITestTrait; |
| 61 | + |
| 62 | + const string TEST_DIRECTORY = __DIR__.'/../test-data'; |
| 63 | + |
58 | 64 | private static function getLintRunConfig(): LintRunConfig { |
59 | | - return LintRunConfig::getForPath(__DIR__.'/../test-data'); |
| 65 | + return LintRunConfig::getForPath(self::TEST_DIRECTORY); |
60 | 66 | } |
61 | 67 |
|
62 | 68 | public function testValidConfigForLinter(): void { |
@@ -87,6 +93,26 @@ final class LinterConfigTest extends HackTest { |
87 | 93 | )->toThrow(\Exception::class, 'is not of the correct type'); |
88 | 94 | } |
89 | 95 |
|
| 96 | + public async function testInvalidConfigForCLI(): Awaitable<void> { |
| 97 | + list($cli, $_, $stdout, $stderr) = |
| 98 | + $this->getCLI('--config-file', self::TEST_DIRECTORY.'/hhast-lint.json', self::TEST_DIRECTORY); |
| 99 | + $exit_code = await $cli->mainAsync(); |
| 100 | + expect($stderr->getBuffer())->toContainSubstring( |
| 101 | + 'A linter threw an exception:', |
| 102 | + ); |
| 103 | + expect($stderr->getBuffer())->toContainSubstring( |
| 104 | + 'Linter: Facebook\HHAST\Tests\InvalidConfigForLinter', |
| 105 | + ); |
| 106 | + expect($stderr->getBuffer())->toMatchRegExp( |
| 107 | + re'#File\\: .*/test-data/unparsable_php_file\\.php#', |
| 108 | + ); |
| 109 | + expect($stderr->getBuffer())->toContainSubstring( |
| 110 | + 'Message: Configuration for Facebook\HHAST\Tests\InvalidConfigForLinter is not of the correct type. See previous exception:', |
| 111 | + ); |
| 112 | + expect($exit_code)->toBeSame(2); |
| 113 | + expect($stdout->getBuffer())->toBeEmpty(); |
| 114 | + } |
| 115 | + |
90 | 116 | public function testLinterWithoutATConfigAndNoConfigSupplied(): void { |
91 | 117 | $lrc = static::getLintRunConfig(); |
92 | 118 |
|
|
0 commit comments