b71948faee
R=brianwilkerson@google.com, paulberry@google.com Change-Id: I70946b8e6f790608ad52c8f27cd6f506673f7b0d Reviewed-on: https://dart-review.googlesource.com/c/82710 Reviewed-by: Paul Berry <paulberry@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
118 lines
4.5 KiB
Dart
118 lines
4.5 KiB
Dart
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import 'package:analyzer/src/generated/engine.dart';
|
|
import 'package:analyzer/src/generated/sdk.dart';
|
|
import 'package:analyzer/src/test_utilities/mock_sdk.dart';
|
|
import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
|
|
import 'package:test/test.dart';
|
|
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
|
|
|
import 'test_support.dart';
|
|
|
|
main() {
|
|
defineReflectiveSuite(() {
|
|
defineReflectiveTests(DartSdkManagerTest);
|
|
defineReflectiveTests(SdkDescriptionTest);
|
|
});
|
|
}
|
|
|
|
@reflectiveTest
|
|
class DartSdkManagerTest extends EngineTestCase with ResourceProviderMixin {
|
|
void test_anySdk() {
|
|
DartSdkManager manager = new DartSdkManager('/a/b/c', false);
|
|
expect(manager.anySdk, isNull);
|
|
|
|
AnalysisOptions options = new AnalysisOptionsImpl();
|
|
SdkDescription description = new SdkDescription(<String>['/c/d'], options);
|
|
DartSdk sdk = new MockSdk(resourceProvider: resourceProvider);
|
|
manager.getSdk(description, () => sdk);
|
|
expect(manager.anySdk, same(sdk));
|
|
}
|
|
|
|
void test_getSdk_differentDescriptors() {
|
|
DartSdkManager manager = new DartSdkManager('/a/b/c', false);
|
|
AnalysisOptions options = new AnalysisOptionsImpl();
|
|
SdkDescription description1 = new SdkDescription(<String>['/c/d'], options);
|
|
DartSdk sdk1 = new MockSdk(resourceProvider: resourceProvider);
|
|
DartSdk result1 = manager.getSdk(description1, () => sdk1);
|
|
expect(result1, same(sdk1));
|
|
SdkDescription description2 = new SdkDescription(<String>['/e/f'], options);
|
|
DartSdk sdk2 = new MockSdk(resourceProvider: resourceProvider);
|
|
DartSdk result2 = manager.getSdk(description2, () => sdk2);
|
|
expect(result2, same(sdk2));
|
|
|
|
manager.getSdk(description1, _failIfAbsent);
|
|
manager.getSdk(description2, _failIfAbsent);
|
|
}
|
|
|
|
void test_getSdk_sameDescriptor() {
|
|
DartSdkManager manager = new DartSdkManager('/a/b/c', false);
|
|
AnalysisOptions options = new AnalysisOptionsImpl();
|
|
SdkDescription description = new SdkDescription(<String>['/c/d'], options);
|
|
DartSdk sdk = new MockSdk(resourceProvider: resourceProvider);
|
|
DartSdk result = manager.getSdk(description, () => sdk);
|
|
expect(result, same(sdk));
|
|
manager.getSdk(description, _failIfAbsent);
|
|
}
|
|
|
|
DartSdk _failIfAbsent() {
|
|
fail('Use of ifAbsent function');
|
|
}
|
|
}
|
|
|
|
@reflectiveTest
|
|
class SdkDescriptionTest extends EngineTestCase {
|
|
void test_equals_differentPaths_nested() {
|
|
AnalysisOptions options = new AnalysisOptionsImpl();
|
|
SdkDescription left = new SdkDescription(<String>['/a/b/c'], options);
|
|
SdkDescription right = new SdkDescription(<String>['/a/b'], options);
|
|
expect(left == right, isFalse);
|
|
}
|
|
|
|
void test_equals_differentPaths_unrelated() {
|
|
AnalysisOptions options = new AnalysisOptionsImpl();
|
|
SdkDescription left = new SdkDescription(<String>['/a/b/c'], options);
|
|
SdkDescription right = new SdkDescription(<String>['/d/e'], options);
|
|
expect(left == right, isFalse);
|
|
}
|
|
|
|
void test_equals_noPaths() {
|
|
AnalysisOptions options = new AnalysisOptionsImpl();
|
|
SdkDescription left = new SdkDescription(<String>[], options);
|
|
SdkDescription right = new SdkDescription(<String>[], options);
|
|
expect(left == right, isTrue);
|
|
}
|
|
|
|
void test_equals_samePaths_differentOptions() {
|
|
String path = '/a/b/c';
|
|
AnalysisOptionsImpl leftOptions = new AnalysisOptionsImpl()
|
|
..useFastaParser = false;
|
|
AnalysisOptionsImpl rightOptions = new AnalysisOptionsImpl()
|
|
..useFastaParser = true;
|
|
SdkDescription left = new SdkDescription(<String>[path], leftOptions);
|
|
SdkDescription right = new SdkDescription(<String>[path], rightOptions);
|
|
expect(left == right, isFalse);
|
|
}
|
|
|
|
void test_equals_samePaths_sameOptions_multiple() {
|
|
String leftPath = '/a/b/c';
|
|
String rightPath = '/d/e';
|
|
AnalysisOptions options = new AnalysisOptionsImpl();
|
|
SdkDescription left =
|
|
new SdkDescription(<String>[leftPath, rightPath], options);
|
|
SdkDescription right =
|
|
new SdkDescription(<String>[leftPath, rightPath], options);
|
|
expect(left == right, isTrue);
|
|
}
|
|
|
|
void test_equals_samePaths_sameOptions_single() {
|
|
String path = '/a/b/c';
|
|
AnalysisOptions options = new AnalysisOptionsImpl();
|
|
SdkDescription left = new SdkDescription(<String>[path], options);
|
|
SdkDescription right = new SdkDescription(<String>[path], options);
|
|
expect(left == right, isTrue);
|
|
}
|
|
}
|