Skip to content

Commit 3b37934

Browse files
stereotype441Commit Queue
authored andcommitted
[analyzer] Make ContextResolutionTest hermetic.
This change causes all tests derived from `ContextResolutionTest` to register lint rules during `setUp` and de-register them during `tearDown`, making these tests properly hermetic. Previously, the first time a `ContextResolutionTest`-derived test was run, its `setUp` would register lint rules, and then further `ContextResolutionTest`-derived tests would not register them, meaning that if any test was run in the interim that attempted to properly clean up its lint registrations, it could provoke a later test failure. The new approach makes the tests more predictable and comprehensible. There is a small performance penalty (running `pkg/analyzer/test/test_all.dart` takes ~2.5% longer on my machine). I the predictability and comprehensibility that we gain by making the tests hermetic is worth this small performance cost. Change-Id: I6a6a6964541ce43a5c5afd6d047bf250050f95c5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/464060 Auto-Submit: Paul Berry <paulberry@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
1 parent 192f389 commit 3b37934

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

pkg/analyzer/test/src/dart/resolution/context_collection_resolution.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import 'package:analyzer/src/dart/analysis/driver_based_analysis_context.dart';
1414
import 'package:analyzer/src/dart/analysis/results.dart';
1515
import 'package:analyzer/src/dart/analysis/unlinked_unit_store.dart';
1616
import 'package:analyzer/src/dart/element/element.dart';
17+
import 'package:analyzer/src/lint/registry.dart';
1718
import 'package:analyzer/src/test_utilities/mock_sdk.dart';
1819
import 'package:analyzer/src/util/file_paths.dart' as file_paths;
1920
import 'package:analyzer/src/workspace/basic.dart';
@@ -73,8 +74,6 @@ class BlazeWorkspaceResolutionTest extends ContextResolutionTest {
7374
/// [AnalysisContextCollection] based implementation of [ResolutionTest].
7475
abstract class ContextResolutionTest
7576
with ResourceProviderMixin, ResolutionTest {
76-
static bool _lintRulesAreRegistered = false;
77-
7877
/// The byte store that is reused between tests. This allows reusing all
7978
/// unlinked and linked summaries for SDK, so that tests run much faster.
8079
/// However nothing is preserved between Dart VM runs, so changes to the
@@ -246,14 +245,14 @@ abstract class ContextResolutionTest
246245

247246
@mustCallSuper
248247
void setUp() {
249-
if (!_lintRulesAreRegistered) {
250-
registerLintRules();
251-
_lintRulesAreRegistered = true;
252-
}
248+
registerLintRules();
253249
}
254250

255251
@mustCallSuper
256252
Future<void> tearDown() async {
253+
for (var rule in Registry.ruleRegistry.rules) {
254+
Registry.ruleRegistry.unregisterLintRule(rule);
255+
}
257256
await disposeAnalysisContextCollection();
258257
}
259258

0 commit comments

Comments
 (0)