55import 'dart:convert' show json;
66
77import 'package:analyzer/dart/analysis/results.dart' ;
8+ import 'package:analyzer/diagnostic/diagnostic.dart' ;
89import 'package:analyzer/error/error.dart' ;
910import 'package:analyzer/error/listener.dart' ;
1011import 'package:analyzer/file_system/file_system.dart' ;
@@ -41,7 +42,7 @@ ExpectedDiagnostic error(
4142 Pattern ? messageContains,
4243}) => _ExpectedError (code, offset, length, messageContains: messageContains);
4344
44- typedef DiagnosticMatcher = bool Function (AnalysisError error );
45+ typedef DiagnosticMatcher = bool Function (Diagnostic diagnostic );
4546
4647/// A description of a diagnostic that is expected to be reported.
4748class ExpectedDiagnostic {
@@ -70,16 +71,17 @@ class ExpectedDiagnostic {
7071 }) : _messageContains = messageContains,
7172 _correctionContains = correctionContains;
7273
73- /// Whether the [error] matches this description of what it's expected to be.
74- bool matches (AnalysisError error) {
75- if (! _diagnosticMatcher (error)) return false ;
76- if (error.offset != _offset) return false ;
77- if (error.length != _length) return false ;
78- if (_messageContains != null && ! error.message.contains (_messageContains)) {
74+ /// Whether the [diagnostic] matches this description of what it's expected to be.
75+ bool matches (Diagnostic diagnostic) {
76+ if (! _diagnosticMatcher (diagnostic)) return false ;
77+ if (diagnostic.offset != _offset) return false ;
78+ if (diagnostic.length != _length) return false ;
79+ if (_messageContains != null &&
80+ ! diagnostic.message.contains (_messageContains)) {
7981 return false ;
8082 }
8183 if (_correctionContains != null ) {
82- var correctionMessage = error .correctionMessage;
84+ var correctionMessage = diagnostic .correctionMessage;
8385 if (correctionMessage == null ||
8486 ! correctionMessage.contains (_correctionContains)) {
8587 return false ;
@@ -202,7 +204,7 @@ class PubPackageResolutionTest extends _ContextResolutionTest {
202204 ) async {
203205 addTestFile (content);
204206 await resolveTestFile ();
205- await _assertDiagnosticsIn (_errors , expectedDiagnostics);
207+ await _assertDiagnosticsIn (_diagnostics , expectedDiagnostics);
206208 }
207209
208210 /// Asserts that the number of diagnostics that have been gathered at [path]
@@ -215,7 +217,7 @@ class PubPackageResolutionTest extends _ContextResolutionTest {
215217 List <ExpectedDiagnostic > expectedDiagnostics,
216218 ) async {
217219 await _resolveFile (path);
218- await _assertDiagnosticsIn (_errors , expectedDiagnostics);
220+ await _assertDiagnosticsIn (_diagnostics , expectedDiagnostics);
219221 }
220222
221223 /// Asserts that the diagnostics for each `path` match those in the paired
@@ -334,15 +336,15 @@ class PubPackageResolutionTest extends _ContextResolutionTest {
334336 writePackageConfig (path, configCopy);
335337 }
336338
337- /// Asserts that the diagnostics in [errors ] match [expectedDiagnostics] .
339+ /// Asserts that the diagnostics in [diagnostics ] match [expectedDiagnostics] .
338340 Future <void > _assertDiagnosticsIn (
339- List <AnalysisError > errors ,
341+ List <Diagnostic > diagnostics ,
340342 List <ExpectedDiagnostic > expectedDiagnostics,
341343 ) async {
342344 //
343345 // Match actual diagnostics to expected diagnostics.
344346 //
345- var unmatchedActual = errors .toList ();
347+ var unmatchedActual = diagnostics .toList ();
346348 var unmatchedExpected = expectedDiagnostics.toList ();
347349 var actualIndex = 0 ;
348350 while (actualIndex < unmatchedActual.length) {
@@ -414,10 +416,12 @@ class PubPackageResolutionTest extends _ContextResolutionTest {
414416 }
415417 }
416418 if (buffer.isNotEmpty) {
417- errors.sort ((first, second) => first.offset.compareTo (second.offset));
419+ diagnostics.sort (
420+ (first, second) => first.offset.compareTo (second.offset),
421+ );
418422 buffer.writeln ();
419423 buffer.writeln ('To accept the current state, expect:' );
420- for (var actual in errors ) {
424+ for (var actual in diagnostics ) {
421425 late String diagnosticKind;
422426 Object ? description;
423427 if (actual.errorCode is LintCode ) {
@@ -461,7 +465,7 @@ class PubPackageResolutionTest extends _ContextResolutionTest {
461465 }
462466 }
463467
464- Future <List <AnalysisError >> _resolvePubspecFile (String content) async {
468+ Future <List <Diagnostic >> _resolvePubspecFile (String content) async {
465469 var path = convertPath (testPackagePubspecPath);
466470 var pubspecRules = < LintRule , PubspecVisitor <Object ?>> {};
467471 for (var rule in Registry .ruleRegistry.where (
@@ -530,8 +534,8 @@ abstract class _ContextResolutionTest
530534
531535 List <String > get _collectionIncludedPaths;
532536
533- /// The analysis errors that were computed during analysis.
534- List <AnalysisError > get _errors =>
537+ /// The diagnostics that were computed during analysis.
538+ List <Diagnostic > get _diagnostics =>
535539 result.errors
536540 .whereNot ((e) => ignoredErrorCodes.any ((c) => e.errorCode == c))
537541 .toList ();
0 commit comments