mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 01:30:32 +00:00
Migrate SdkConstraintVerifierTest to PubPackageResolutionTest.
R=brianwilkerson@google.com Change-Id: I0d6fa9ccdfbb4f9156226af2884a5f9b14dea495 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/158064 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
d5db03707e
commit
a8f1be78a5
|
@ -257,12 +257,10 @@ class PubPackageResolutionTest extends ContextResolutionTest {
|
|||
writeTestPackageConfig({});
|
||||
}
|
||||
|
||||
void writeTestPackageAnalysisOptionsFile(
|
||||
AnalysisOptionsFileConfig builder,
|
||||
) {
|
||||
void writeTestPackageAnalysisOptionsFile(AnalysisOptionsFileConfig config) {
|
||||
newFile(
|
||||
'$testPackageRootPath/analysis_options.yaml',
|
||||
content: builder.toContent(),
|
||||
content: config.toContent(),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -300,6 +298,30 @@ class PubPackageResolutionTest extends ContextResolutionTest {
|
|||
void writeTestPackageConfigWithMeta() {
|
||||
writeTestPackageConfigWith({}, meta: true);
|
||||
}
|
||||
|
||||
void writeTestPackagePubspecYamlFile(PubspecYamlFileConfig config) {
|
||||
newFile(
|
||||
'$testPackageRootPath/pubspec.yaml',
|
||||
content: config.toContent(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class PubspecYamlFileConfig {
|
||||
final String sdkVersion;
|
||||
|
||||
PubspecYamlFileConfig({this.sdkVersion});
|
||||
|
||||
String toContent() {
|
||||
var buffer = StringBuffer();
|
||||
|
||||
if (sdkVersion != null) {
|
||||
buffer.writeln('environment:');
|
||||
buffer.writeln(" sdk: '$sdkVersion'");
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
||||
|
||||
mixin WithNullSafetyMixin on PubPackageResolutionTest {
|
||||
|
|
|
@ -2,21 +2,22 @@
|
|||
// 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:pub_semver/pub_semver.dart';
|
||||
|
||||
import '../../generated/test_support.dart';
|
||||
import '../dart/resolution/driver_resolution.dart';
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
|
||||
/// A base class designed to be used by tests of the hints produced by the
|
||||
/// SdkConstraintVerifier.
|
||||
class SdkConstraintVerifierTest extends DriverResolutionTest {
|
||||
/// Verify that the [errorCodes] are produced if the [source] is analyzed in
|
||||
/// a context that specifies the minimum SDK version to be [version].
|
||||
class SdkConstraintVerifierTest extends PubPackageResolutionTest {
|
||||
/// Verify that the [expectedErrors] are produced if the [source] is analyzed
|
||||
/// in a context that specifies the minimum SDK version to be [version].
|
||||
Future<void> verifyVersion(String version, String source,
|
||||
{List<ExpectedError> expectedErrors}) async {
|
||||
driver.configure(
|
||||
analysisOptions: analysisOptions
|
||||
..sdkVersionConstraint = VersionConstraint.parse(version));
|
||||
writeTestPackagePubspecYamlFile(
|
||||
PubspecYamlFileConfig(
|
||||
sdkVersion: '>=$version',
|
||||
),
|
||||
);
|
||||
|
||||
await assertErrorsInCode(source, expectedErrors ?? []);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,10 +2,7 @@
|
|||
// 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/dart/analysis/features.dart';
|
||||
import 'package:analyzer/src/dart/analysis/experiments.dart';
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/generated/engine.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import 'sdk_constraint_verifier_support.dart';
|
||||
|
@ -19,12 +16,6 @@ main() {
|
|||
@reflectiveTest
|
||||
class SdkVersionAsExpressionInConstContextTest
|
||||
extends SdkConstraintVerifierTest {
|
||||
@override
|
||||
AnalysisOptionsImpl get analysisOptions => AnalysisOptionsImpl()
|
||||
..contextFeatures = FeatureSet.fromEnableFlags(
|
||||
[EnableString.constant_update_2018],
|
||||
);
|
||||
|
||||
test_equals() async {
|
||||
await verifyVersion('2.5.0', '''
|
||||
const dynamic a = 2;
|
||||
|
|
|
@ -32,7 +32,7 @@ Future<int> zero() async => 0;
|
|||
}
|
||||
|
||||
test_equals_explicitImportOfExportingLibrary() async {
|
||||
newFile('/test/lib/exporter.dart', content: '''
|
||||
newFile('$testPackageLibPath/exporter.dart', content: '''
|
||||
export 'dart:async';
|
||||
''');
|
||||
await verifyVersion('2.1.0', '''
|
||||
|
@ -78,7 +78,7 @@ Future<int> zero() async => 0;
|
|||
}
|
||||
|
||||
test_lessThan_explicitImportOfExportingLibrary() async {
|
||||
newFile('/test/lib/exporter.dart', content: '''
|
||||
newFile('$testPackageLibPath/exporter.dart', content: '''
|
||||
export 'dart:async';
|
||||
''');
|
||||
await verifyVersion('2.0.0', '''
|
||||
|
|
|
@ -2,10 +2,7 @@
|
|||
// 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/dart/analysis/features.dart';
|
||||
import 'package:analyzer/src/dart/analysis/experiments.dart';
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/generated/engine.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import 'sdk_constraint_verifier_support.dart';
|
||||
|
@ -19,12 +16,6 @@ main() {
|
|||
@reflectiveTest
|
||||
class SdkVersionBoolOperatorInConstContextTest
|
||||
extends SdkConstraintVerifierTest {
|
||||
@override
|
||||
AnalysisOptionsImpl get analysisOptions => AnalysisOptionsImpl()
|
||||
..contextFeatures = FeatureSet.fromEnableFlags(
|
||||
[EnableString.constant_update_2018],
|
||||
);
|
||||
|
||||
test_and_const_equals() async {
|
||||
await verifyVersion('2.5.0', '''
|
||||
const c = true & false;
|
||||
|
|
|
@ -2,10 +2,7 @@
|
|||
// 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/dart/analysis/features.dart';
|
||||
import 'package:analyzer/src/dart/analysis/experiments.dart';
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/generated/engine.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import 'sdk_constraint_verifier_support.dart';
|
||||
|
@ -18,12 +15,6 @@ main() {
|
|||
|
||||
@reflectiveTest
|
||||
class SdkVersionEqEqOperatorTest extends SdkConstraintVerifierTest {
|
||||
@override
|
||||
AnalysisOptionsImpl get analysisOptions => AnalysisOptionsImpl()
|
||||
..contextFeatures = FeatureSet.fromEnableFlags(
|
||||
[EnableString.constant_update_2018],
|
||||
);
|
||||
|
||||
test_left_equals() async {
|
||||
await verifyVersion('2.5.0', '''
|
||||
class A {
|
||||
|
|
|
@ -2,10 +2,7 @@
|
|||
// 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/dart/analysis/features.dart';
|
||||
import 'package:analyzer/src/dart/analysis/experiments.dart';
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/generated/engine.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import 'sdk_constraint_verifier_support.dart';
|
||||
|
@ -18,12 +15,6 @@ main() {
|
|||
|
||||
@reflectiveTest
|
||||
class SdkVersionExtensionMethodsTest extends SdkConstraintVerifierTest {
|
||||
@override
|
||||
AnalysisOptionsImpl get analysisOptions => AnalysisOptionsImpl()
|
||||
..contextFeatures = FeatureSet.fromEnableFlags(
|
||||
[EnableString.extension_methods],
|
||||
);
|
||||
|
||||
test_extension_equals() async {
|
||||
await verifyVersion('2.6.0', '''
|
||||
extension E on int {}
|
||||
|
|
|
@ -2,12 +2,11 @@
|
|||
// 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/dart/analysis/features.dart';
|
||||
import 'package:analyzer/src/dart/analysis/experiments.dart';
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/generated/engine.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import 'sdk_constraint_verifier_support.dart';
|
||||
|
||||
main() {
|
||||
|
@ -19,10 +18,14 @@ main() {
|
|||
@reflectiveTest
|
||||
class SdkVersionGtGtGtOperatorTest extends SdkConstraintVerifierTest {
|
||||
@override
|
||||
AnalysisOptionsImpl get analysisOptions => AnalysisOptionsImpl()
|
||||
..contextFeatures = FeatureSet.fromEnableFlags(
|
||||
[EnableString.triple_shift],
|
||||
void setUp() {
|
||||
super.setUp();
|
||||
writeTestPackageAnalysisOptionsFile(
|
||||
AnalysisOptionsFileConfig(
|
||||
experiments: [EnableString.triple_shift],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
test_const_equals() async {
|
||||
// TODO(brianwilkerson) Add '>>>' to MockSdk and remove the code
|
||||
|
|
|
@ -2,10 +2,7 @@
|
|||
// 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/dart/analysis/features.dart';
|
||||
import 'package:analyzer/src/dart/analysis/experiments.dart';
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/generated/engine.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import 'sdk_constraint_verifier_support.dart';
|
||||
|
@ -19,12 +16,6 @@ main() {
|
|||
@reflectiveTest
|
||||
class SdkVersionIsExpressionInConstContextTest
|
||||
extends SdkConstraintVerifierTest {
|
||||
@override
|
||||
AnalysisOptionsImpl get analysisOptions => AnalysisOptionsImpl()
|
||||
..contextFeatures = FeatureSet.fromEnableFlags(
|
||||
[EnableString.constant_update_2018],
|
||||
);
|
||||
|
||||
test_equals() async {
|
||||
await verifyVersion('2.5.0', '''
|
||||
const dynamic a = 2;
|
||||
|
|
|
@ -2,12 +2,10 @@
|
|||
// 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/dart/analysis/features.dart';
|
||||
import 'package:analyzer/src/dart/error/hint_codes.dart';
|
||||
import 'package:analyzer/src/generated/engine.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/with_null_safety_mixin.dart';
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import 'sdk_constraint_verifier_support.dart';
|
||||
|
||||
main() {
|
||||
|
@ -19,10 +17,6 @@ main() {
|
|||
|
||||
@reflectiveTest
|
||||
class SdkVersionNeverTest extends SdkConstraintVerifierTest {
|
||||
@override
|
||||
AnalysisOptionsImpl get analysisOptions => AnalysisOptionsImpl()
|
||||
..contextFeatures = FeatureSet.forTesting(sdkVersion: '2.7.0');
|
||||
|
||||
test_languageVersionBeforeNullSafety() async {
|
||||
await verifyVersion('2.7.0', r'''
|
||||
Never foo;
|
||||
|
|
|
@ -2,10 +2,7 @@
|
|||
// 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/dart/analysis/features.dart';
|
||||
import 'package:analyzer/src/dart/analysis/experiments.dart';
|
||||
import 'package:analyzer/src/dart/error/hint_codes.dart';
|
||||
import 'package:analyzer/src/generated/engine.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import 'sdk_constraint_verifier_support.dart';
|
||||
|
@ -18,12 +15,6 @@ main() {
|
|||
|
||||
@reflectiveTest
|
||||
class SdkVersionUiAsCodeInConstContextTest extends SdkConstraintVerifierTest {
|
||||
@override
|
||||
AnalysisOptionsImpl get analysisOptions => AnalysisOptionsImpl()
|
||||
..contextFeatures = FeatureSet.fromEnableFlags(
|
||||
[EnableString.constant_update_2018],
|
||||
);
|
||||
|
||||
test_equals() async {
|
||||
await verifyVersion('2.5.0', '''
|
||||
const zero = [...const [0]];
|
||||
|
|
Loading…
Reference in a new issue