Skip to content

Commit a36e01d

Browse files
parloughCommit Queue
authored and
Commit Queue
committed
[analyzer] Reuse analysis context collection in verify_docs_test
Perhaps there's a good reason not do this, but it seems to work fine for now, and doesn't hide errors. On my computer it brought the test down from 35 seconds to 600 ms. Closes #54183 Bug: #54183 Change-Id: I15351ce71897534a82da1f649d33b0b7b6180f4c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/339440 Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]> Auto-Submit: Parker Lougheed <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent 51d46fd commit a36e01d

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

pkg/analyzer/test/verify_docs_test.dart

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class SnippetTester {
2525
final Folder docFolder;
2626
final String snippetDirPath;
2727
final String snippetPath;
28+
final AnalysisContextCollection collection;
2829

2930
final StringBuffer output = StringBuffer();
3031

@@ -41,7 +42,9 @@ class SnippetTester {
4142
}
4243

4344
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]);
4548

4649
/// Return `true` if the given error is a diagnostic produced by a lint that
4750
/// is allowed to occur in documentation.
@@ -91,7 +94,7 @@ class SnippetTester {
9194
if (output.isNotEmpty) {
9295
fail(output.toString());
9396
}
94-
}, timeout: Timeout.factor(6));
97+
}, timeout: Timeout.factor(4));
9598
}
9699
} else if (child is Folder) {
97100
await verifyFolder(child);
@@ -103,7 +106,7 @@ class SnippetTester {
103106
// TODO(brianwilkerson): When the files outside of 'src' contain only public
104107
// API, write code to compute the list of imports so that new public API
105108
// will automatically be allowed.
106-
String imports = '''
109+
const String imports = '''
107110
import 'dart:math' as math;
108111
109112
import 'package:analyzer/dart/analysis/analysis_context.dart';
@@ -127,13 +130,16 @@ $snippet
127130
''',
128131
modificationStamp: 1);
129132
try {
130-
AnalysisContextCollection collection = AnalysisContextCollection(
131-
includedPaths: <String>[snippetDirPath], resourceProvider: provider);
132133
List<AnalysisContext> contexts = collection.contexts;
133134
if (contexts.length != 1) {
134135
fail('The snippets directory contains multiple analysis contexts.');
135136
}
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);
137143
if (results is ErrorsResult) {
138144
Iterable<AnalysisError> errors = results.errors.where((error) {
139145
ErrorCode errorCode = error.errorCode;

0 commit comments

Comments
 (0)