Skip to content

Commit

Permalink
Move MockSdk into tests.
Browse files Browse the repository at this point in the history
Also make _MockSdkLibrary implement noSuchMethod() to avoid breaking
because of unused methods in the future.

[email protected], [email protected]
BUG=

Review URL: https://codereview.chromium.org//2417463002 .
  • Loading branch information
scheglov committed Oct 12, 2016
1 parent aca9843 commit 621865f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 29 deletions.
10 changes: 4 additions & 6 deletions lib/src/analysis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -70,9 +69,8 @@ class AnalysisDriver {
int get numSourcesAnalyzed => _sourcesAnalyzed.length;

List<UriResolver> 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<UriResolver> resolvers = [new DartUriResolver(sdk)];
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: linter
version: 0.1.27
version: 0.1.28
author: Dart Team <[email protected]>
description: Style linter for Dart.
homepage: https://github.com/dart-lang/linter
Expand Down
22 changes: 1 addition & 21 deletions lib/src/sdk.dart → test/mock_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion test/rule_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 621865f

Please sign in to comment.