From 621865f22b841beebb10c785d04301b68bbd1dd2 Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Tue, 11 Oct 2016 21:23:24 -0700 Subject: [PATCH] Move MockSdk into tests. Also make _MockSdkLibrary implement noSuchMethod() to avoid breaking because of unused methods in the future. R=pquitslund@google.com, brianwilkerson@google.com BUG= Review URL: https://codereview.chromium.org//2417463002 . --- lib/src/analysis.dart | 10 ++++------ pubspec.yaml | 2 +- lib/src/sdk.dart => test/mock_sdk.dart | 22 +--------------------- test/rule_test.dart | 3 ++- 4 files changed, 8 insertions(+), 29 deletions(-) rename lib/src/sdk.dart => test/mock_sdk.dart (95%) diff --git a/lib/src/analysis.dart b/lib/src/analysis.dart index f04ba60db..255f8b77e 100644 --- a/lib/src/analysis.dart +++ b/lib/src/analysis.dart @@ -23,7 +23,6 @@ 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; @@ -70,9 +69,8 @@ class AnalysisDriver { int get numSourcesAnalyzed => _sourcesAnalyzed.length; List get resolvers { - DartSdk sdk = options.useMockSdk - ? new MockSdk() - : new FolderBasedDartSdk(PhysicalResourceProvider.INSTANCE, + DartSdk sdk = options.mockSdk ?? + new FolderBasedDartSdk(PhysicalResourceProvider.INSTANCE, PhysicalResourceProvider.INSTANCE.getFolder(sdkDir)); List resolvers = [new DartUriResolver(sdk)]; @@ -234,8 +232,8 @@ class DriverOptions { /// Whether to use Dart's Strong Mode analyzer. bool strongMode = true; - /// Whether to use a mock SDK (to speed up testing). - bool useMockSdk = false; + /// The mock SDK (to speed up testing) or `null` to use the actual SDK. + DartSdk mockSdk; /// Whether to show lints for the transitive closure of imported and exported /// libraries. diff --git a/pubspec.yaml b/pubspec.yaml index 6c35092bd..22486438f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: linter -version: 0.1.27 +version: 0.1.28 author: Dart Team description: Style linter for Dart. homepage: https://github.com/dart-lang/linter diff --git a/lib/src/sdk.dart b/test/mock_sdk.dart similarity index 95% rename from lib/src/sdk.dart rename to test/mock_sdk.dart index 2904637b2..398109ff5 100644 --- a/lib/src/sdk.dart +++ b/test/mock_sdk.dart @@ -346,27 +346,7 @@ class _MockSdkLibrary implements SdkLibrary { [this.parts = const <_MockSdkFile>[]]); @override - String get category => throw unimplemented; - - @override - bool get isDart2JsLibrary => throw unimplemented; - - @override - bool get isDocumented => throw unimplemented; - - @override - bool get isImplementation => throw unimplemented; - - @override - bool get isInternal => throw unimplemented; - - @override - bool get isShared => throw unimplemented; - - @override - bool get isVmLibrary => throw unimplemented; - - UnimplementedError get unimplemented => new UnimplementedError(); + noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); } /// An [AnalysisContextImpl] that only contains sources for a Dart SDK. diff --git a/test/rule_test.dart b/test/rule_test.dart index 402d69488..18fcb99f1 100644 --- a/test/rule_test.dart +++ b/test/rule_test.dart @@ -6,6 +6,7 @@ library linter.test.rule; import 'dart:io'; +import 'mock_sdk.dart'; import 'package:analyzer/src/generated/engine.dart'; import 'package:analyzer/src/generated/error.dart'; import 'package:analyzer/src/generated/source.dart'; @@ -409,7 +410,7 @@ testRule(String ruleName, File file, {bool debug: false}) { } LinterOptions options = new LinterOptions([rule]) - ..useMockSdk = true + ..mockSdk = new MockSdk() ..packageRootPath = '.'; DartLinter driver = new DartLinter(options);