diff --git a/pkg/analyzer/test/verify_docs_test.dart b/pkg/analyzer/test/verify_docs_test.dart index caaf5020f3b..d9a9c8e6fdc 100644 --- a/pkg/analyzer/test/verify_docs_test.dart +++ b/pkg/analyzer/test/verify_docs_test.dart @@ -25,6 +25,7 @@ class SnippetTester { final Folder docFolder; final String snippetDirPath; final String snippetPath; + final AnalysisContextCollection collection; final StringBuffer output = StringBuffer(); @@ -41,7 +42,9 @@ class SnippetTester { } SnippetTester._( - this.provider, this.docFolder, this.snippetDirPath, this.snippetPath); + this.provider, this.docFolder, this.snippetDirPath, this.snippetPath) + : collection = AnalysisContextCollection( + resourceProvider: provider, includedPaths: [snippetPath]); /// Return `true` if the given error is a diagnostic produced by a lint that /// is allowed to occur in documentation. @@ -91,7 +94,7 @@ class SnippetTester { if (output.isNotEmpty) { fail(output.toString()); } - }, timeout: Timeout.factor(6)); + }, timeout: Timeout.factor(4)); } } else if (child is Folder) { await verifyFolder(child); @@ -103,7 +106,7 @@ class SnippetTester { // TODO(brianwilkerson): When the files outside of 'src' contain only public // API, write code to compute the list of imports so that new public API // will automatically be allowed. - String imports = ''' + const String imports = ''' import 'dart:math' as math; import 'package:analyzer/dart/analysis/analysis_context.dart'; @@ -127,13 +130,16 @@ $snippet ''', modificationStamp: 1); try { - AnalysisContextCollection collection = AnalysisContextCollection( - includedPaths: [snippetDirPath], resourceProvider: provider); List contexts = collection.contexts; if (contexts.length != 1) { fail('The snippets directory contains multiple analysis contexts.'); } - var results = await contexts[0].currentSession.getErrors(snippetPath); + var context = contexts[0]; + // Mark the snippet as changed since we reuse the same path + // for each snippet found. + context.changeFile(snippetPath); + await context.applyPendingFileChanges(); + var results = await context.currentSession.getErrors(snippetPath); if (results is ErrorsResult) { Iterable errors = results.errors.where((error) { ErrorCode errorCode = error.errorCode;