Prepare bots for not reporting UNUSED_IMPORT in presence of unresolved identifiers. (#154514)

With https://dart-review.googlesource.com/c/sdk/+/383022 the analyzer does not report `unused_import` when there are compilation errors potentially related to imports.

https://github.com/flutter/flutter/issues/154413
This commit is contained in:
Konstantin Scheglov 2024-09-03 14:16:48 -07:00 committed by GitHub
parent 3fd27bdb58
commit 284d289425
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -38,7 +38,8 @@ const List<String> expectedUiErrors = <String>[
'dev/bots/test/analyze-snippet-code-test-dart-ui/ui.dart:16:20: (top-level declaration) (unused_field)', 'dev/bots/test/analyze-snippet-code-test-dart-ui/ui.dart:16:20: (top-level declaration) (unused_field)',
]; ];
final RegExp errorPrefixRE = RegExp(r'^([-a-z0-9/_.:]+): .*(\([-a-z_ ]+\) \([-a-z_ ]+\))$'); final RegExp errorPrefixRE =
RegExp(r'^([-a-z0-9/_.:]+): .*(\([-a-z_ ]+\) \([-a-z_ ]+\))$');
String removeLintDescriptions(String error) { String removeLintDescriptions(String error) {
final RegExpMatch? match = errorPrefixRE.firstMatch(error); final RegExpMatch? match = errorPrefixRE.firstMatch(error);
if (match != null) { if (match != null) {
@ -67,8 +68,10 @@ void main() {
); );
expect(process.stdout, isEmpty); expect(process.stdout, isEmpty);
final List<String> stderrLines = process.stderr.toString().split('\n'); final List<String> stderrLines = process.stderr.toString().split('\n');
expect(stderrLines.length, stderrLines.toSet().length, reason: 'found duplicates in $stderrLines'); expect(stderrLines.length, stderrLines.toSet().length,
final List<String> stderrNoDescriptions = stderrLines.map(removeLintDescriptions).toList(); reason: 'found duplicates in $stderrLines');
final List<String> stderrNoDescriptions =
stderrLines.map(removeLintDescriptions).toList();
expect(stderrNoDescriptions, <String>[ expect(stderrNoDescriptions, <String>[
...expectedMainErrors, ...expectedMainErrors,
'Found 18 snippet code errors.', 'Found 18 snippet code errors.',
@ -76,7 +79,7 @@ void main() {
'', // because we end with a newline, split gives us an extra blank line '', // because we end with a newline, split gives us an extra blank line
]); ]);
expect(process.exitCode, 1); expect(process.exitCode, 1);
}); }, skip: true); // TODO(scheglov): Restore after landing Dart SDK changes, https://github.com/flutter/flutter/issues/154413
test('Analyzes dart:ui code', () { test('Analyzes dart:ui code', () {
final ProcessResult process = Process.runSync( final ProcessResult process = Process.runSync(
@ -90,8 +93,10 @@ void main() {
); );
expect(process.stdout, isEmpty); expect(process.stdout, isEmpty);
final List<String> stderrLines = process.stderr.toString().split('\n'); final List<String> stderrLines = process.stderr.toString().split('\n');
expect(stderrLines.length, stderrLines.toSet().length, reason: 'found duplicates in $stderrLines'); expect(stderrLines.length, stderrLines.toSet().length,
final List<String> stderrNoDescriptions = stderrLines.map(removeLintDescriptions).toList(); reason: 'found duplicates in $stderrLines');
final List<String> stderrNoDescriptions =
stderrLines.map(removeLintDescriptions).toList();
expect(stderrNoDescriptions, <String>[ expect(stderrNoDescriptions, <String>[
...expectedUiErrors, ...expectedUiErrors,
...expectedMainErrors, ...expectedMainErrors,
@ -100,5 +105,5 @@ void main() {
'', // because we end with a newline, split gives us an extra blank line '', // because we end with a newline, split gives us an extra blank line
]); ]);
expect(process.exitCode, 1); expect(process.exitCode, 1);
}); }, skip: true); // TODO(scheglov): Restore after landing Dart SDK changes, https://github.com/flutter/flutter/issues/154413
} }