Skip to content
This repository was archived by the owner on Nov 20, 2024. It is now read-only.

Commit 5671069

Browse files
committed
SDK mocking for improved test throughput.
Improves `all_test` execution from ~30 seconds to ~12. :) [email protected] Review URL: https://codereview.chromium.org//1415723007 .
1 parent 2689ad3 commit 5671069

File tree

4 files changed

+441
-11
lines changed

4 files changed

+441
-11
lines changed

lib/src/analysis.dart

+14-5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import 'package:linter/src/io.dart';
2525
import 'package:linter/src/linter.dart';
2626
import 'package:linter/src/project.dart';
2727
import 'package:linter/src/rules.dart';
28+
import 'package:linter/src/sdk.dart';
2829
import 'package:package_config/packages.dart' show Packages;
2930
import 'package:package_config/packages_file.dart' as pkgfile show parse;
3031
import 'package:package_config/src/packages_impl.dart' show MapPackages;
@@ -62,8 +63,12 @@ class AnalysisDriver {
6263
int get numSourcesAnalyzed => _sourcesAnalyzed.length;
6364

6465
List<UriResolver> get resolvers {
65-
DartSdk sdk = new DirectoryBasedDartSdk(new JavaFile(sdkDir));
66+
DartSdk sdk = options.useMockSdk
67+
? new MockSdk()
68+
: new DirectoryBasedDartSdk(new JavaFile(sdkDir));
69+
6670
List<UriResolver> resolvers = [new DartUriResolver(sdk)];
71+
6772
if (options.packageRootPath != null) {
6873
JavaFile packageDirectory = new JavaFile(options.packageRootPath);
6974
resolvers.add(new PackageUriResolver([packageDirectory]));
@@ -78,6 +83,7 @@ class AnalysisDriver {
7883
PhysicalResourceProvider.INSTANCE, packageMap));
7984
}
8085
}
86+
8187
// File URI resolver must come last so that files inside "/lib" are
8288
// are analyzed via "package:" URI's.
8389
resolvers.add(new FileUriResolver());
@@ -211,16 +217,19 @@ class DriverOptions {
211217
/// The path to the package root.
212218
String packageRootPath;
213219

220+
/// If non-null, the function to use to run pub list. This is used to mock
221+
/// out executions of pub list when testing the linter.
222+
RunPubList runPubList = null;
223+
214224
/// Whether to show SDK warnings.
215225
bool showSdkWarnings = false;
216226

227+
/// Whether to use a mock SDK (to speed up testing).
228+
bool useMockSdk = false;
229+
217230
/// Whether to show lints for the transitive closure of imported and exported
218231
/// libraries.
219232
bool visitTransitiveClosure = false;
220-
221-
/// If non-null, the function to use to run pub list. This is used to mock
222-
/// out executions of pub list when testing the linter.
223-
RunPubList runPubList = null;
224233
}
225234

226235
/// Prints logging information comments to the [outSink] and error messages to

lib/src/linter.dart

-3
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ class DartLinter implements AnalysisErrorListener {
6161
/// Creates a new linter.
6262
DartLinter(this.options, {this.reporter: const PrintingReporter()});
6363

64-
factory DartLinter.forRules(Iterable<LintRule> ruleSet) =>
65-
new DartLinter(new LinterOptions(ruleSet));
66-
6764
Iterable<AnalysisErrorInfo> lintFiles(List<File> files) {
6865
List<AnalysisErrorInfo> errors = [];
6966
var analysisDriver = new AnalysisDriver(options);

0 commit comments

Comments
 (0)