forked from hhvm/hhast
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoFixingLinterTestTrait.hack
More file actions
49 lines (40 loc) · 1.54 KB
/
Copy pathAutoFixingLinterTestTrait.hack
File metadata and controls
49 lines (40 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
namespace Facebook\HHAST;
use type Facebook\HackTest\DataProvider;
use function Facebook\HHAST\TestLib\expect;
use namespace HH\Lib\Str;
trait AutoFixingLinterTestTrait<Terror as SingleRuleLintError> {
require extends TestCase;
use LinterTestTrait;
<<__Override>>
abstract protected function getLinter(string $file): AutoFixingLinter<Terror>;
<<DataProvider('getDirtyFixtures')>>
final public function testAutofix(string $example): void {
$example = $this->getFullFixtureName($example);
$in = __DIR__.'/examples/'.$example.'.in';
$out = Str\strip_suffix($in, '.in').'.autofix.out';
\copy($in, $out);
$linter = $this->getLinter($out);
/*HHAST_FIXME[DontUseAsioJoin]*/
$all_errors = vec(\HH\Asio\join($linter->getLintErrorsAsync()));
$code = $linter->getFixedFile($all_errors)->getContents();
// Provide raw output for easier debugging
\file_put_contents($out, $code);
expect($code)->toMatchExpectFileWithInputFile(
$example.'.autofix.expect',
$example.'.in',
);
$linter = $this->getLinter(__DIR__.'/examples/'.$example.'.autofix.expect');
/*HHAST_FIXME[DontUseAsioJoin]*/
$errors = \HH\Asio\join($linter->getLintErrorsAsync());
$re_fixed = $linter->getFixedFile($errors)->getContents();
expect($re_fixed)->toBeSame($code, 'Not all fixable errors were fixed');
}
}