|
4 | 4 |
|
5 | 5 | import 'dart:io'; |
6 | 6 |
|
7 | | -import 'package:analyzer/dart/analysis/analysis_context_collection.dart'; |
8 | | -import 'package:analyzer/dart/analysis/results.dart'; |
9 | 7 | import 'package:analyzer/error/error.dart'; |
10 | | -import 'package:analyzer/file_system/physical_file_system.dart'; |
11 | 8 | import 'package:analyzer/src/dart/analysis/analysis_options.dart'; |
12 | 9 | import 'package:analyzer/src/lint/io.dart'; |
13 | 10 | import 'package:analyzer/src/lint/registry.dart'; |
@@ -75,53 +72,22 @@ void defineRuleUnitTests() { |
75 | 72 | }); |
76 | 73 | } |
77 | 74 |
|
78 | | -void testRule(String ruleName, File file, {bool useMockSdk = true}) { |
| 75 | +void testRule(String ruleName, File file) { |
79 | 76 | test(ruleName, () async { |
80 | 77 | if (!file.existsSync()) { |
81 | 78 | throw Exception('No rule found defined at: ${file.path}'); |
82 | 79 | } |
83 | 80 |
|
84 | | - var errorInfos = |
85 | | - await _getErrorInfos(ruleName, file, useMockSdk: useMockSdk); |
86 | | - _validateExpectedLints(file, errorInfos); |
87 | | - }); |
88 | | -} |
89 | | - |
90 | | -Future<Iterable<AnalysisErrorInfo>> _getErrorInfos(String ruleName, File file, |
91 | | - {required bool useMockSdk}) async { |
92 | | - registerLintRules(); |
93 | | - var rule = Registry.ruleRegistry[ruleName]; |
94 | | - if (rule == null) { |
95 | | - fail('rule `$ruleName` is not registered; unable to test.'); |
96 | | - } |
| 81 | + registerLintRules(); |
| 82 | + var rule = Registry.ruleRegistry[ruleName]; |
| 83 | + if (rule == null) { |
| 84 | + fail('rule `$ruleName` is not registered; unable to test.'); |
| 85 | + } |
97 | 86 |
|
98 | | - if (useMockSdk) { |
99 | 87 | var driver = buildDriver(rule, file); |
100 | | - return await driver.lintFiles([file]); |
101 | | - } |
102 | | - |
103 | | - var path = p.normalize(file.absolute.path); |
104 | | - var collection = AnalysisContextCollection( |
105 | | - includedPaths: [path], |
106 | | - resourceProvider: PhysicalResourceProvider.INSTANCE, |
107 | | - ); |
108 | | - |
109 | | - var context = collection.contexts.first; |
110 | | - var contextFile = (context.currentSession.getFile(path) as FileResult).file; |
111 | | - var options = |
112 | | - context.getAnalysisOptionsForFile(contextFile) as AnalysisOptionsImpl; |
113 | | - options.lintRules = options.lintRules.toList(); |
114 | | - |
115 | | - // TODO(pq): consider a different way to configure lints |
116 | | - // https://github.com/dart-lang/sdk/issues/54045 |
117 | | - options.lintRules.add(rule); |
118 | | - options.lint = true; |
119 | | - |
120 | | - var result = |
121 | | - await context.currentSession.getResolvedUnit(path) as ResolvedUnitResult; |
122 | | - return [ |
123 | | - AnalysisErrorInfo(result.errors, result.lineInfo), |
124 | | - ]; |
| 88 | + var errorInfos = await driver.lintFiles([file]); |
| 89 | + _validateExpectedLints(file, errorInfos); |
| 90 | + }); |
125 | 91 | } |
126 | 92 |
|
127 | 93 | /// Parse lint annotations in the given [file] and validate that they correspond |
|
0 commit comments