@@ -25,6 +25,7 @@ class SnippetTester {
25
25
final Folder docFolder;
26
26
final String snippetDirPath;
27
27
final String snippetPath;
28
+ final AnalysisContextCollection collection;
28
29
29
30
final StringBuffer output = StringBuffer ();
30
31
@@ -41,7 +42,9 @@ class SnippetTester {
41
42
}
42
43
43
44
SnippetTester ._(
44
- this .provider, this .docFolder, this .snippetDirPath, this .snippetPath);
45
+ this .provider, this .docFolder, this .snippetDirPath, this .snippetPath)
46
+ : collection = AnalysisContextCollection (
47
+ resourceProvider: provider, includedPaths: [snippetPath]);
45
48
46
49
/// Return `true` if the given error is a diagnostic produced by a lint that
47
50
/// is allowed to occur in documentation.
@@ -91,7 +94,7 @@ class SnippetTester {
91
94
if (output.isNotEmpty) {
92
95
fail (output.toString ());
93
96
}
94
- }, timeout: Timeout .factor (6 ));
97
+ }, timeout: Timeout .factor (4 ));
95
98
}
96
99
} else if (child is Folder ) {
97
100
await verifyFolder (child);
@@ -103,7 +106,7 @@ class SnippetTester {
103
106
// TODO(brianwilkerson): When the files outside of 'src' contain only public
104
107
// API, write code to compute the list of imports so that new public API
105
108
// will automatically be allowed.
106
- String imports = '''
109
+ const String imports = '''
107
110
import 'dart:math' as math;
108
111
109
112
import 'package:analyzer/dart/analysis/analysis_context.dart';
@@ -127,13 +130,16 @@ $snippet
127
130
''' ,
128
131
modificationStamp: 1 );
129
132
try {
130
- AnalysisContextCollection collection = AnalysisContextCollection (
131
- includedPaths: < String > [snippetDirPath], resourceProvider: provider);
132
133
List <AnalysisContext > contexts = collection.contexts;
133
134
if (contexts.length != 1 ) {
134
135
fail ('The snippets directory contains multiple analysis contexts.' );
135
136
}
136
- var results = await contexts[0 ].currentSession.getErrors (snippetPath);
137
+ var context = contexts[0 ];
138
+ // Mark the snippet as changed since we reuse the same path
139
+ // for each snippet found.
140
+ context.changeFile (snippetPath);
141
+ await context.applyPendingFileChanges ();
142
+ var results = await context.currentSession.getErrors (snippetPath);
137
143
if (results is ErrorsResult ) {
138
144
Iterable <AnalysisError > errors = results.errors.where ((error) {
139
145
ErrorCode errorCode = error.errorCode;
0 commit comments