Skip to content

Commit

Permalink
SDK mocking for improved test throughput.
Browse files Browse the repository at this point in the history
Improves `all_test` execution from ~30 seconds to ~12. :)

R=scheglov@google.com

Review URL: https://codereview.chromium.org//1415723007 .
  • Loading branch information
pq committed Nov 3, 2015
1 parent 2689ad3 commit 5671069
Show file tree
Hide file tree
Showing 4 changed files with 441 additions and 11 deletions.
19 changes: 14 additions & 5 deletions lib/src/analysis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import 'package:linter/src/io.dart';
import 'package:linter/src/linter.dart';
import 'package:linter/src/project.dart';
import 'package:linter/src/rules.dart';
import 'package:linter/src/sdk.dart';
import 'package:package_config/packages.dart' show Packages;
import 'package:package_config/packages_file.dart' as pkgfile show parse;
import 'package:package_config/src/packages_impl.dart' show MapPackages;
Expand Down Expand Up @@ -62,8 +63,12 @@ class AnalysisDriver {
int get numSourcesAnalyzed => _sourcesAnalyzed.length;

List<UriResolver> get resolvers {
DartSdk sdk = new DirectoryBasedDartSdk(new JavaFile(sdkDir));
DartSdk sdk = options.useMockSdk
? new MockSdk()
: new DirectoryBasedDartSdk(new JavaFile(sdkDir));

List<UriResolver> resolvers = [new DartUriResolver(sdk)];

if (options.packageRootPath != null) {
JavaFile packageDirectory = new JavaFile(options.packageRootPath);
resolvers.add(new PackageUriResolver([packageDirectory]));
Expand All @@ -78,6 +83,7 @@ class AnalysisDriver {
PhysicalResourceProvider.INSTANCE, packageMap));
}
}

// File URI resolver must come last so that files inside "/lib" are
// are analyzed via "package:" URI's.
resolvers.add(new FileUriResolver());
Expand Down Expand Up @@ -211,16 +217,19 @@ class DriverOptions {
/// The path to the package root.
String packageRootPath;

/// If non-null, the function to use to run pub list. This is used to mock
/// out executions of pub list when testing the linter.
RunPubList runPubList = null;

/// Whether to show SDK warnings.
bool showSdkWarnings = false;

/// Whether to use a mock SDK (to speed up testing).
bool useMockSdk = false;

/// Whether to show lints for the transitive closure of imported and exported
/// libraries.
bool visitTransitiveClosure = false;

/// If non-null, the function to use to run pub list. This is used to mock
/// out executions of pub list when testing the linter.
RunPubList runPubList = null;
}

/// Prints logging information comments to the [outSink] and error messages to
Expand Down
3 changes: 0 additions & 3 deletions lib/src/linter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ class DartLinter implements AnalysisErrorListener {
/// Creates a new linter.
DartLinter(this.options, {this.reporter: const PrintingReporter()});

factory DartLinter.forRules(Iterable<LintRule> ruleSet) =>
new DartLinter(new LinterOptions(ruleSet));

Iterable<AnalysisErrorInfo> lintFiles(List<File> files) {
List<AnalysisErrorInfo> errors = [];
var analysisDriver = new AnalysisDriver(options);
Expand Down

0 comments on commit 5671069

Please sign in to comment.