mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 00:58:29 +00:00
Use Feature to specify experiments.
Change-Id: Ide1a58c93cfc4920dff3ab2f52113434de93fff0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/288162 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
c58d445fa8
commit
fce81082c0
|
@ -3,6 +3,7 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/dart/analysis/analysis_context.dart';
|
||||
import 'package:analyzer/dart/analysis/features.dart';
|
||||
import 'package:analyzer/dart/analysis/results.dart';
|
||||
import 'package:analyzer/dart/analysis/session.dart';
|
||||
import 'package:analyzer/file_system/file_system.dart';
|
||||
|
@ -44,12 +45,12 @@ class AbstractContextTest with ResourceProviderMixin {
|
|||
|
||||
/// Return a list of the experiments that are to be enabled for tests in this
|
||||
/// class, an empty list if there are no experiments that should be enabled.
|
||||
List<String> get experiments => [
|
||||
EnableString.class_modifiers,
|
||||
EnableString.macros,
|
||||
EnableString.patterns,
|
||||
EnableString.records,
|
||||
EnableString.sealed_class,
|
||||
List<Feature> get experiments => [
|
||||
Feature.class_modifiers,
|
||||
Feature.macros,
|
||||
Feature.patterns,
|
||||
Feature.records,
|
||||
Feature.sealed_class,
|
||||
];
|
||||
|
||||
String get latestLanguageVersion =>
|
||||
|
@ -105,7 +106,7 @@ class AbstractContextTest with ResourceProviderMixin {
|
|||
|
||||
/// Create an analysis options file based on the given arguments.
|
||||
void createAnalysisOptionsFile({
|
||||
List<String>? experiments,
|
||||
List<Feature>? experiments,
|
||||
List<String>? cannotIgnore,
|
||||
bool? implicitCasts,
|
||||
List<String>? lints,
|
||||
|
@ -119,7 +120,12 @@ class AbstractContextTest with ResourceProviderMixin {
|
|||
if (experiments != null) {
|
||||
buffer.writeln(' enable-experiment:');
|
||||
for (var experiment in experiments) {
|
||||
buffer.writeln(' - $experiment');
|
||||
final experimentalFlag = experiment.experimentalFlag;
|
||||
if (experimentalFlag != null) {
|
||||
buffer.writeln(' - ${experiment.experimentalFlag}');
|
||||
} else {
|
||||
throw ArgumentError('Not experimental: $experiment');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ import 'dart:async';
|
|||
import 'package:analysis_server/protocol/protocol.dart';
|
||||
import 'package:analysis_server/protocol/protocol_constants.dart';
|
||||
import 'package:analysis_server/protocol/protocol_generated.dart';
|
||||
import 'package:analyzer/dart/analysis/features.dart';
|
||||
import 'package:analyzer/source/source_range.dart';
|
||||
import 'package:analyzer/src/test_utilities/test_code_format.dart';
|
||||
import 'package:analyzer_plugin/protocol/protocol_common.dart';
|
||||
|
@ -26,12 +25,6 @@ void main() {
|
|||
|
||||
@reflectiveTest
|
||||
class AnalysisNotificationHighlightsTest extends HighlightsTestSupport {
|
||||
@override
|
||||
List<String> get experiments => [
|
||||
Feature.inline_class.enableString,
|
||||
...super.experiments,
|
||||
];
|
||||
|
||||
void assertHighlightText(TestCode testCode, int index, String expected) {
|
||||
var actual = _getHighlightText(testCode, index);
|
||||
if (actual != expected) {
|
||||
|
|
|
@ -27,7 +27,7 @@ import 'src/utilities/mock_packages.dart';
|
|||
|
||||
/// TODO(scheglov) this is duplicate
|
||||
class AnalysisOptionsFileConfig {
|
||||
final List<String> experiments;
|
||||
final List<Feature> experiments;
|
||||
final bool implicitCasts;
|
||||
final bool implicitDynamic;
|
||||
final List<String> lints;
|
||||
|
@ -52,7 +52,12 @@ class AnalysisOptionsFileConfig {
|
|||
if (experiments.isNotEmpty) {
|
||||
buffer.writeln(' enable-experiment:');
|
||||
for (var experiment in experiments) {
|
||||
buffer.writeln(' - $experiment');
|
||||
final experimentalFlag = experiment.experimentalFlag;
|
||||
if (experimentalFlag != null) {
|
||||
buffer.writeln(' - ${experiment.experimentalFlag}');
|
||||
} else {
|
||||
throw ArgumentError('Not experimental: $experiment');
|
||||
}
|
||||
}
|
||||
}
|
||||
buffer.writeln(' language:');
|
||||
|
@ -214,15 +219,13 @@ class ContextResolutionTest with ResourceProviderMixin {
|
|||
}
|
||||
|
||||
class PubPackageAnalysisServerTest extends ContextResolutionTest {
|
||||
// If experiments are needed,
|
||||
// add `import 'package:analyzer/dart/analysis/features.dart';`
|
||||
// and list the necessary experiments here.
|
||||
List<String> get experiments => [
|
||||
Feature.class_modifiers.enableString,
|
||||
Feature.macros.enableString,
|
||||
Feature.patterns.enableString,
|
||||
Feature.records.enableString,
|
||||
Feature.sealed_class.enableString,
|
||||
List<Feature> get experiments => [
|
||||
Feature.class_modifiers,
|
||||
Feature.inline_class,
|
||||
Feature.macros,
|
||||
Feature.patterns,
|
||||
Feature.records,
|
||||
Feature.sealed_class,
|
||||
];
|
||||
|
||||
/// The path that is not in [workspaceRootPath], contains external packages.
|
||||
|
|
|
@ -11,7 +11,6 @@ import 'package:analysis_server/src/provisional/completion/dart/completion_dart.
|
|||
import 'package:analysis_server/src/services/completion/dart/completion_manager.dart';
|
||||
import 'package:analysis_server/src/services/completion/dart/imported_reference_contributor.dart';
|
||||
import 'package:analysis_server/src/services/completion/dart/suggestion_builder.dart';
|
||||
import 'package:analyzer/src/dart/analysis/experiments.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
|
@ -2394,7 +2393,6 @@ class B extends A {
|
|||
}
|
||||
|
||||
Future<void> test_function_parameters_nnbd_required() async {
|
||||
createAnalysisOptionsFile(experiments: [EnableString.non_nullable]);
|
||||
resolveSource('$testPackageLibPath/a.dart', '''
|
||||
void m(int? nullable, int nonNullable) {}
|
||||
''');
|
||||
|
@ -2417,7 +2415,6 @@ void f() {^}
|
|||
}
|
||||
|
||||
Future<void> test_function_parameters_nnbd_required_into_legacy() async {
|
||||
createAnalysisOptionsFile(experiments: [EnableString.non_nullable]);
|
||||
resolveSource('$testPackageLibPath/a.dart', '''
|
||||
void m(int? nullable, int nonNullable) {}
|
||||
''');
|
||||
|
@ -2441,7 +2438,6 @@ void f() {^}
|
|||
}
|
||||
|
||||
Future<void> test_function_parameters_nnbd_required_legacy() async {
|
||||
createAnalysisOptionsFile(experiments: [EnableString.non_nullable]);
|
||||
resolveSource('$testPackageLibPath/a.dart', '''
|
||||
// @dart = 2.8
|
||||
void m(int param) {}
|
||||
|
|
|
@ -7,6 +7,7 @@ import 'package:analysis_server/src/services/correction/bulk_fix_processor.dart'
|
|||
import 'package:analysis_server/src/services/correction/change_workspace.dart';
|
||||
import 'package:analysis_server/src/services/correction/fix.dart';
|
||||
import 'package:analysis_server/src/services/correction/fix_internal.dart';
|
||||
import 'package:analyzer/dart/analysis/features.dart';
|
||||
import 'package:analyzer/error/error.dart';
|
||||
import 'package:analyzer/src/dart/analysis/byte_store.dart';
|
||||
import 'package:analyzer/src/dart/error/lint_codes.dart';
|
||||
|
@ -87,7 +88,7 @@ abstract class BulkFixProcessorTest extends AbstractSingleUnitTest {
|
|||
late BulkFixProcessor processor;
|
||||
|
||||
@override
|
||||
List<String> get experiments => const [];
|
||||
List<Feature> get experiments => const [];
|
||||
|
||||
/// Return the lint code being tested.
|
||||
String? get lintCode => null;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
import 'package:analysis_server/src/services/correction/fix.dart';
|
||||
import 'package:analysis_server/src/services/linter/lint_names.dart';
|
||||
import 'package:analyzer/dart/analysis/features.dart';
|
||||
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
|
@ -19,7 +20,7 @@ void main() {
|
|||
@reflectiveTest
|
||||
class RemoveBreakBulkTest extends BulkFixProcessorTest {
|
||||
@override
|
||||
List<String> get experiments => ['patterns', 'records'];
|
||||
List<Feature> get experiments => [Feature.patterns, Feature.records];
|
||||
|
||||
@override
|
||||
String get lintCode => LintNames.unnecessary_breaks;
|
||||
|
@ -53,7 +54,7 @@ f() {
|
|||
@reflectiveTest
|
||||
class RemoveBreakTest extends FixProcessorLintTest {
|
||||
@override
|
||||
List<String> get experiments => ['patterns', 'records'];
|
||||
List<Feature> get experiments => [Feature.patterns, Feature.records];
|
||||
|
||||
@override
|
||||
FixKind get kind => DartFixKind.REMOVE_BREAK;
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analysis_server/src/services/correction/fix.dart';
|
||||
import 'package:analyzer/src/dart/analysis/experiments.dart';
|
||||
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
|
@ -64,8 +63,6 @@ const c = a == null;
|
|||
}
|
||||
|
||||
Future<void> test_gtGtGtOperator() async {
|
||||
writeTestPackageConfig(languageVersion: latestLanguageVersion);
|
||||
createAnalysisOptionsFile(experiments: [EnableString.triple_shift]);
|
||||
await testUpdate(content: '''
|
||||
class C {
|
||||
C operator >>>(C other) => this;
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
import 'package:analysis_server/src/utilities/selection.dart';
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/source/source_range.dart';
|
||||
import 'package:analyzer/src/dart/analysis/experiments.dart';
|
||||
import 'package:analyzer/src/test_utilities/test_code_format.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
@ -21,12 +20,6 @@ void main() {
|
|||
|
||||
@reflectiveTest
|
||||
class SelectionTest extends AbstractSingleUnitTest {
|
||||
@override
|
||||
List<String> get experiments => [
|
||||
...super.experiments,
|
||||
EnableString.patterns,
|
||||
];
|
||||
|
||||
Future<void> assertMembers(
|
||||
{String prefix = '', required String postfix}) async {
|
||||
var nodes = await nodesInRange('''
|
||||
|
|
Loading…
Reference in a new issue