[cfe] Add symbolic language versions for testing

Change-Id: I0f8bb91d30fac442d781710b24908cd933d86388
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/365142
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
Johnni Winther 2024-05-01 13:11:10 +00:00 committed by Commit Queue
parent 36fb02deca
commit 3c9d05f255
96 changed files with 273 additions and 168 deletions

View file

@ -6,6 +6,8 @@ import 'package:_fe_analyzer_shared/src/testing/annotated_code_helper.dart';
import 'package:_fe_analyzer_shared/src/testing/id.dart';
import 'package:_fe_analyzer_shared/src/testing/id_testing.dart';
String _noProcessing(String text) => text;
Map<Uri, List<Annotation>> computeAnnotationsPerUri<T>(
Map<Uri, AnnotatedCode> annotatedCode,
Map<String, MemberAnnotations<IdValue>> expectedMaps,
@ -13,7 +15,8 @@ Map<Uri, List<Annotation>> computeAnnotationsPerUri<T>(
Map<String, Map<Uri, Map<Id, ActualData<T>>>> actualData,
DataInterpreter<T> dataInterpreter,
{Annotation? Function(Annotation? expected, Annotation? actual)? createDiff,
bool forceUpdate = false}) {
bool forceUpdate = false,
String Function(String) postProcessData = _noProcessing}) {
Set<Uri> uriSet = {};
Set<String> actualMarkers = actualData.keys.toSet();
Map<Uri, Map<Id, Map<String, IdValue>>> idValuePerUri = {};
@ -64,7 +67,10 @@ Map<Uri, List<Annotation>> computeAnnotationsPerUri<T>(
// Annotations are not computed from synthesized code.
result[uri] = _computeAnnotations(code, expectedMaps.keys, actualMarkers,
idValuePerId, actualDataPerId, dataInterpreter,
sortMarkers: false, createDiff: createDiff, forceUpdate: forceUpdate);
sortMarkers: false,
createDiff: createDiff,
forceUpdate: forceUpdate,
postProcessData: postProcessData);
}
}
return result;
@ -81,7 +87,8 @@ List<Annotation> _computeAnnotations<T>(
String defaultSuffix = '*/',
bool sortMarkers = true,
Annotation? Function(Annotation? expected, Annotation? actual)? createDiff,
bool forceUpdate = false}) {
bool forceUpdate = false,
required String Function(String) postProcessData}) {
Annotation createAnnotationFromData(
ActualData<T> actualData, Annotation? annotation) {
String getIndentationFromOffset(int offset) {
@ -142,8 +149,10 @@ List<Annotation> _computeAnnotations<T>(
annotation?.columnNo ?? -1,
offset,
prefix,
IdValue.idToString(actualData.id,
dataInterpreter.getText(actualData.value, indentation)),
IdValue.idToString(
actualData.id,
postProcessData(
dataInterpreter.getText(actualData.value, indentation))),
suffix);
}

View file

@ -263,6 +263,7 @@ TestData computeTestData(FileSystemEntity testFile,
{required Iterable<String> supportedMarkers,
required Uri createTestUri(Uri uri, String fileName),
required void onFailure(String message),
String Function(String) preprocessFile = _noProcessing,
bool preserveWhitespaceInAnnotations = false,
bool preserveInfixWhitespaceInAnnotations = false}) {
Uri? entryPoint;
@ -296,7 +297,8 @@ TestData computeTestData(FileSystemEntity testFile,
throw new UnimplementedError();
}
String annotatedCode = new File.fromUri(mainTestFile!.uri).readAsStringSync();
String annotatedCode =
preprocessFile(new File.fromUri(mainTestFile!.uri).readAsStringSync());
Map<Uri, AnnotatedCode> code = {
entryPoint!:
new AnnotatedCode.fromText(annotatedCode, commentStart, commentEnd)
@ -320,7 +322,7 @@ TestData computeTestData(FileSystemEntity testFile,
String libFileName = additionalFileData.key;
File libEntity = additionalFileData.value;
Uri libFileUri = createTestUri(libEntity.uri, libFileName);
String libCode = libEntity.readAsStringSync();
String libCode = preprocessFile(libEntity.readAsStringSync());
AnnotatedCode annotatedLibCode =
new AnnotatedCode.fromText(libCode, commentStart, commentEnd);
memorySourceFiles[libFileUri.path] = annotatedLibCode.sourceCode;
@ -820,6 +822,8 @@ const List<Option> idTestOptions = [
Options.forceUpdate,
];
String _noProcessing(String s) => s;
/// Check code for all tests in [dataDir] using [runTest].
Future<void> runTests<T>(Directory dataDir,
{List<String> args = const <String>[],
@ -832,7 +836,9 @@ Future<void> runTests<T>(Directory dataDir,
List<String>? skipList,
Map<String, List<String>>? skipMap,
bool preserveWhitespaceInAnnotations = false,
bool preserveInfixWhitespaceInAnnotations = false}) async {
bool preserveInfixWhitespaceInAnnotations = false,
String Function(String) preprocessFile = _noProcessing,
String Function(String) postProcessData = _noProcessing}) async {
ParsedOptions parsedOptions = ParsedOptions.parse(args, idTestOptions);
MarkerOptions markerOptions =
new MarkerOptions.fromDataDir(dataDir, shouldFindScript: shards == 1);
@ -903,7 +909,8 @@ Future<void> runTests<T>(Directory dataDir,
onFailure: onFailure,
preserveWhitespaceInAnnotations: preserveWhitespaceInAnnotations,
preserveInfixWhitespaceInAnnotations:
preserveInfixWhitespaceInAnnotations);
preserveInfixWhitespaceInAnnotations,
preprocessFile: preprocessFile);
print('Test: ${testData.testFileUri}');
Map<String, TestResult<T>> results = await runTest(markerOptions, testData,
@ -966,7 +973,8 @@ Future<void> runTests<T>(Directory dataDir,
testData.entryPoint,
actualData,
dataInterpreter!,
forceUpdate: forceUpdate);
forceUpdate: forceUpdate,
postProcessData: postProcessData);
annotations.forEach((Uri uri, List<Annotation> annotations) {
AnnotatedCode? code = testData.code[uri];
assert(code != null,

View file

@ -74,6 +74,7 @@ import "incremental_utils.dart" as util;
import 'test_utils.dart';
import 'testing_utils.dart' show checkEnvironment;
import 'utils/io_utils.dart' show computeRepoDir;
import 'utils/symbolic_language_versions.dart';
import 'utils/values.dart';
void main([List<String> arguments = const []]) => internalMain(createContext,
@ -772,14 +773,6 @@ Future<Map<String, List<int>>> createModules(
return moduleResult;
}
String doStringReplacements(String input) {
Version enableNonNullableVersion =
ExperimentalFlag.nonNullable.experimentEnabledVersion;
String output = input.replaceAll("%NNBD_VERSION_MARKER%",
"${enableNonNullableVersion.major}.${enableNonNullableVersion.minor}");
return output;
}
class ExpressionCompilation {
final bool errors;
final bool warnings;
@ -1250,7 +1243,7 @@ class NewWorldTest {
packagesUri = uri;
}
if (world.enableStringReplacement) {
data = doStringReplacements(data);
data = replaceMarkersWithVersions(data);
}
fs.entityForUri(uri).writeAsStringSync(data);
}

View file

@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
/*library:
languageVersion=2.8,
languageVersion=%CURRENT_VERSION_MARKER%,
packageUri=package:collection
*/

View file

@ -2,6 +2,6 @@
// 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.
/*library: languageVersion=2.8*/
/*library: languageVersion=%CURRENT_VERSION_MARKER%*/
method2() {}

View file

@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
/*library:
languageVersion=2.8,
languageVersion=%CURRENT_VERSION_MARKER%,
packageUri=package:collection
*/

View file

@ -2,7 +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.
/*library: languageVersion=2.8*/
/*library: languageVersion=%CURRENT_VERSION_MARKER%*/
import 'foo/bin/bin_file.dart';
import 'foo/test/test_file.dart';

View file

@ -1,4 +1,4 @@
/*library: languageVersion=2.8*/
/*library: languageVersion=%CURRENT_VERSION_MARKER%*/
String foo() {
return "42";

View file

@ -5,11 +5,11 @@
// Set version of this file (not technically in package) explicitly to test as
// much as possibly separately.
// @dart = 2.4
// @dart = %VERSION_MARKER0%
import 'package:foo/foo.dart';
/*library: languageVersion=2.4*/
/*library: languageVersion=%VERSION_MARKER0%*/
main() {
var result = foo();

View file

@ -4,7 +4,7 @@
{
"name": "pack",
"rootUri": "../pack/lib/",
"languageVersion": "2.7"
"languageVersion": "%VERSION_MARKER2%"
}
]
}

View file

@ -1,3 +1,3 @@
/*library: languageVersion=2.8*/
/*library: languageVersion=%CURRENT_VERSION_MARKER%*/
import 'pack/web/pack.dart';

View file

@ -1,4 +1,4 @@
/*library: languageVersion=2.8*/
/*library: languageVersion=%CURRENT_VERSION_MARKER%*/
library pack;
part /*error: errors=LanguageVersionMismatchInPart*/ 'package:pack/src/part.dart';

View file

@ -5,7 +5,7 @@
"name": "pack",
"rootUri": "../",
"packageUri": "lib/",
"languageVersion": "2.7"
"languageVersion": "%VERSION_MARKER2%"
}
]
}

View file

@ -1,5 +1,5 @@
/*library:
languageVersion=2.7,
languageVersion=%VERSION_MARKER2%,
packageUri=package:pack
*/

View file

@ -1,5 +1,5 @@
/*library:
languageVersion=2.7,
languageVersion=%VERSION_MARKER2%,
packageUri=package:pack
*/
library pack;

View file

@ -3,11 +3,10 @@
// BSD-style license that can be found in the LICENSE file.
/*error: errors=LanguageVersionTooHigh*/
// @dart = 3.5
// @dart = %TOO_HIGH_VERSION_MARKER%
// If no valid language version is specified, we default to the most reason one.
// In the tests this is hard-coded to 2.8.
// If no valid language version is specified, we default to the most recent one.
/*library: languageVersion=2.8*/
/*library: languageVersion=%CURRENT_VERSION_MARKER%*/
main() {}

View file

@ -3,13 +3,13 @@
// BSD-style license that can be found in the LICENSE file.
/*error: errors=LanguageVersionTooHigh*/
// @dart = 3.5
// @dart = %TOO_HIGH_VERSION_MARKER%
// @dart = 2.5
// @dart = %VERSION_MARKER1%
// If the first language version specified is not a valid language version,
// we default to the most reason one. In the tests this is hard-coded to 2.8.
// we default to the most recent one.
/*library: languageVersion=2.8*/
/*library: languageVersion=%CURRENT_VERSION_MARKER%*/
main() {}

View file

@ -3,9 +3,8 @@
// BSD-style license that can be found in the LICENSE file.
// If no language version is specified, and none if given in a
// .dart_tool/package_config.json file,
// we default to the most reason one. In the tests this is hard-coded to 2.8.
// .dart_tool/package_config.json file, we default to the most recent one.
/*library: languageVersion=2.8*/
/*library: languageVersion=%CURRENT_VERSION_MARKER%*/
main() {}

View file

@ -4,9 +4,9 @@
// With several valid versions the first one wins.
// @dart = 2.5
// @dart = 2.4
// @dart = %VERSION_MARKER1%
// @dart = %VERSION_MARKER0%
/*library: languageVersion=2.5*/
/*library: languageVersion=%VERSION_MARKER1%*/
main() {}

View file

@ -4,9 +4,9 @@
// With several versions where the first one is valid, the first one wins.
// @dart = 2.5
// @dart = 42.5
// @dart = %VERSION_MARKER1%
// @dart = %TOO_HIGH_VERSION_MARKER%
/*library: languageVersion=2.5*/
/*library: languageVersion=%VERSION_MARKER1%*/
main() {}

View file

@ -2,8 +2,8 @@
// 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.
// @dart = 2.4
// @dart = %VERSION_MARKER0%
/*library: languageVersion=2.4*/
/*library: languageVersion=%VERSION_MARKER0%*/
main() {}

View file

@ -4,7 +4,7 @@
{
"name": "foo",
"rootUri": "../lib/",
"languageVersion": "2.5"
"languageVersion": "%VERSION_MARKER1%"
}
]
}

View file

@ -2,7 +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.
/*library: languageVersion=2.5*/
/*library: languageVersion=%VERSION_MARKER1%*/
import 'foo2.dart';
import 'foo3.dart';

View file

@ -2,9 +2,9 @@
// 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.
// @dart = 2.4
// @dart = %VERSION_MARKER0%
/*library: languageVersion=2.4*/
/*library: languageVersion=%VERSION_MARKER0%*/
foo2() {
print("Hello from foo2!");

View file

@ -2,12 +2,12 @@
// 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.
// .dart_tool/package_config.json specifies 2.5, this library tries to go above
// that, which is fine.
// .dart_tool/package_config.json specifies %VERSION_MARKER1%, this library
// tries to go above that, which is fine.
// @dart = 2.6
// @dart = %VERSION_MARKER2%
/*library: languageVersion=2.6*/
/*library: languageVersion=%VERSION_MARKER2%*/
foo3() {
print("Hello from foo3!");

View file

@ -2,15 +2,15 @@
// 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.
// .dart_tool/package_config.json specifies 2.5, this library tries to go above
// that, which is fine, except it still has to be within the range of the sdk.
// The library stays on the .dart_tool/package_config.json specified one (2.5)
// and an error is issued.
// .dart_tool/package_config.json specifies %VERSION_MARKER1%, this library
// tries to go above that, which is fine, except it still has to be within the
// range of the sdk. The library stays on the .dart_tool/package_config.json
// specified one (%VERSION_MARKER1%) and an error is issued.
/*error: errors=LanguageVersionTooHigh*/
// @dart = 2.9
// @dart = %TOO_HIGH_VERSION_MARKER%
/*library: languageVersion=2.5*/
/*library: languageVersion=%VERSION_MARKER1%*/
foo4() {
print("Hello from foo4!");

View file

@ -2,7 +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.
/*library: languageVersion=2.5*/
/*library: languageVersion=%VERSION_MARKER1%*/
part 'foos_part.dart';

View file

@ -5,12 +5,12 @@
// Set version of this file (not technically in package) explicitly to test as
// much as possibly separately.
// @dart = 2.4
// @dart = %VERSION_MARKER0%
import 'package:foo/foo.dart';
import 'package:foo/foo_with_part.dart';
/*library: languageVersion=2.4*/
/*library: languageVersion=%VERSION_MARKER0%*/
main() {
foo();

View file

@ -3,7 +3,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.
/*library: languageVersion=2.8*/
/*library: languageVersion=%CURRENT_VERSION_MARKER%*/
import 'foo2.dart';

View file

@ -3,9 +3,9 @@
// 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.
// @dart = 2.4
// @dart = %VERSION_MARKER0%
/*library: languageVersion=2.4*/
/*library: languageVersion=%VERSION_MARKER0%*/
foo2() {
print("Hello from foo2!");

View file

@ -5,11 +5,11 @@
// Set version of this file (not technically in package) explicitly to test as
// much as possibly separately.
// @dart = 2.4
// @dart = %VERSION_MARKER0%
import 'package:foo/foo.dart';
/*library: languageVersion=2.4*/
/*library: languageVersion=%VERSION_MARKER0%*/
main() {
foo();

View file

@ -3,7 +3,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.
/*library: languageVersion=2.8*/
/*library: languageVersion=%CURRENT_VERSION_MARKER%*/
import 'foo2.dart';

View file

@ -3,9 +3,9 @@
// 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.
// @dart = 2.4
// @dart = %VERSION_MARKER0%
/*library: languageVersion=2.4*/
/*library: languageVersion=%VERSION_MARKER0%*/
foo2() {
print("Hello from foo2!");

View file

@ -5,11 +5,11 @@
// Set version of this file (not technically in package) explicitly to test as
// much as possibly separately.
// @dart = 2.4
// @dart = %VERSION_MARKER0%
import 'package:foo/foo.dart';
/*library: languageVersion=2.4*/
/*library: languageVersion=%VERSION_MARKER0%*/
main() {
foo();

View file

@ -5,7 +5,7 @@
"name": "foo",
"rootUri": "../lib/",
"languageVersion": "arglebargle",
"languageVersion": "2.5"
"languageVersion": "%VERSION_MARKER1%"
}
]
}

View file

@ -3,7 +3,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.
/*library: languageVersion=2.8*/
/*library: languageVersion=%CURRENT_VERSION_MARKER%*/
import 'foo2.dart';

View file

@ -3,9 +3,9 @@
// 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.
// @dart = 2.4
// @dart = %VERSION_MARKER0%
/*library: languageVersion=2.4*/
/*library: languageVersion=%VERSION_MARKER0%*/
foo2() {
print("Hello from foo2!");

View file

@ -5,11 +5,11 @@
// Set version of this file (not technically in package) explicitly to test as
// much as possibly separately.
// @dart = 2.4
// @dart = %VERSION_MARKER0%
import 'package:foo/foo.dart';
/*library: languageVersion=2.4*/
/*library: languageVersion=%VERSION_MARKER0%*/
main() {
foo();

View file

@ -5,7 +5,7 @@
{
"name": "foo",
"rootUri": "../lib/",
"languageVersion": "2.5",
"languageVersion": "%VERSION_MARKER1%",
"languageVersion": "arglebargle"
}
]

View file

@ -3,7 +3,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.
/*library: languageVersion=2.8*/
/*library: languageVersion=%CURRENT_VERSION_MARKER%*/
import 'foo2.dart';

View file

@ -3,9 +3,9 @@
// 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.
// @dart = 2.4
// @dart = %VERSION_MARKER0%
/*library: languageVersion=2.4*/
/*library: languageVersion=%VERSION_MARKER0%*/
foo2() {
print("Hello from foo2!");

View file

@ -5,11 +5,11 @@
// Set version of this file (not technically in package) explicitly to test as
// much as possibly separately.
// @dart = 2.4
// @dart = %VERSION_MARKER0%
import 'package:foo/foo.dart';
/*library: languageVersion=2.4*/
/*library: languageVersion=%VERSION_MARKER0%*/
main() {
foo();

View file

@ -3,7 +3,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.
/*library: languageVersion=2.8*/
/*library: languageVersion=%CURRENT_VERSION_MARKER%*/
import 'foo2.dart';

View file

@ -3,9 +3,9 @@
// 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.
// @dart = 2.4
// @dart = %VERSION_MARKER0%
/*library: languageVersion=2.4*/
/*library: languageVersion=%VERSION_MARKER0%*/
foo2() {
print("Hello from foo2!");

View file

@ -5,11 +5,11 @@
// Set version of this file (not technically in package) explicitly to test as
// much as possibly separately.
// @dart = 2.4
// @dart = %VERSION_MARKER0%
import 'package:foo/foo.dart';
/*library: languageVersion=2.4*/
/*library: languageVersion=%VERSION_MARKER0%*/
main() {
foo();

View file

@ -3,10 +3,9 @@
// BSD-style license that can be found in the LICENSE file.
// If no language version is specified, and none if given in a
// .dart_tool/package_config.json file,
// we default to the most reason one. In the tests this is hard-coded to 2.8.
// .dart_tool/package_config.json file, we default to the most recent one.
/*library: languageVersion=2.8*/
/*library: languageVersion=%CURRENT_VERSION_MARKER%*/
foo() {
print("Hello from foo!");

View file

@ -2,11 +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.
// @dart = 2.5
// @dart = %VERSION_MARKER1%
import 'package:foo/foo.dart';
/*library: languageVersion=2.5*/
/*library: languageVersion=%VERSION_MARKER1%*/
main() {
foo();

View file

@ -5,7 +5,7 @@
"name": "foo",
"rootUri": "../",
"packageUri": "lib/",
"languageVersion": "2.5"
"languageVersion": "%VERSION_MARKER1%"
}
]
}

View file

@ -2,7 +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.
/*library: languageVersion=2.5*/
/*library: languageVersion=%VERSION_MARKER1%*/
foo() {
print("Hello from foo!");

View file

@ -7,7 +7,7 @@ import 'package:foo/foo.dart';
// Version comes from the package foo having this file in it's root uri.
/*library:
languageVersion=2.5,
languageVersion=%VERSION_MARKER1%,
packageUri=package:foo
*/

View file

@ -4,7 +4,7 @@
{
"name": "foo",
"rootUri": "../lib/",
"languageVersion": "2.5"
"languageVersion": "%VERSION_MARKER1%"
}
]
}

View file

@ -2,7 +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.
/*library: languageVersion=2.5*/
/*library: languageVersion=%VERSION_MARKER1%*/
foo() {
print("Hello from foo!");

View file

@ -4,7 +4,7 @@
import 'package:foo/foo.dart';
/*library: languageVersion=2.8*/
/*library: languageVersion=%CURRENT_VERSION_MARKER%*/
main() {
foo();

View file

@ -4,7 +4,7 @@
{
"name": "foo",
"rootUri": "../lib/",
"languageVersion": "2.9"
"languageVersion": "%TOO_HIGH_VERSION_MARKER%"
}
]
}

View file

@ -3,7 +3,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.
/*library: languageVersion=2.8*/
/*library: languageVersion=%CURRENT_VERSION_MARKER%*/
import 'foo2.dart';
import 'foo3.dart';

View file

@ -4,9 +4,9 @@
// BSD-style license that can be found in the LICENSE file.
/*error: errors=LanguageVersionTooHigh*/
// @dart = 2.9
// @dart = %TOO_HIGH_VERSION_MARKER%
/*library: languageVersion=2.8*/
/*library: languageVersion=%CURRENT_VERSION_MARKER%*/
foo2() {
print("Hello from foo2!");

View file

@ -3,9 +3,9 @@
// 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.
// @dart = 2.7
// @dart = %VERSION_MARKER2%
/*library: languageVersion=2.7*/
/*library: languageVersion=%VERSION_MARKER2%*/
foo3() {
print("Hello from foo3!");

View file

@ -5,11 +5,11 @@
// Set version of this file (not technically in package) explicitly to test as
// much as possibly separately.
// @dart = 2.4
// @dart = %VERSION_MARKER0%
import 'package:foo/foo.dart';
/*library: languageVersion=2.4*/
/*library: languageVersion=%VERSION_MARKER0%*/
main() {
foo();

View file

@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
/*library:
languageVersion=2.8,
languageVersion=%CURRENT_VERSION_MARKER%,
packageUri=package:foo
*/

View file

@ -2,6 +2,6 @@
// 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.
/*library: languageVersion=2.8*/
/*library: languageVersion=%CURRENT_VERSION_MARKER%*/
method2() {}

View file

@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
/*library:
languageVersion=2.8,
languageVersion=%CURRENT_VERSION_MARKER%,
packageUri=package:foo
*/

View file

@ -2,7 +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.
/*library: languageVersion=2.8*/
/*library: languageVersion=%CURRENT_VERSION_MARKER%*/
// Test that bin and test files within the root folder of a package are
// associated with the package.

View file

@ -2,6 +2,6 @@
// 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.
/*library: languageVersion=2.8*/
/*library: languageVersion=%CURRENT_VERSION_MARKER%*/
method1() {}

View file

@ -2,6 +2,6 @@
// 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.
/*library: languageVersion=2.8*/
/*library: languageVersion=%CURRENT_VERSION_MARKER%*/
method2() {}

View file

@ -2,6 +2,6 @@
// 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.
/*library: languageVersion=2.8*/
/*library: languageVersion=%CURRENT_VERSION_MARKER%*/
method3() {}

View file

@ -2,7 +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.
/*library: languageVersion=2.8*/
/*library: languageVersion=%CURRENT_VERSION_MARKER%*/
// Test that bin and test files within the root folder of a package are
// associated with the package.

View file

@ -2,11 +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.
// @dart = 2.5
// @dart = %VERSION_MARKER1%
part 'part.dart';
/*library: languageVersion=2.5*/
/*library: languageVersion=%VERSION_MARKER1%*/
main() {
// foo();

View file

@ -2,7 +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.
// @dart = 2.5
// @dart = %VERSION_MARKER1%
part of 'main.dart';

View file

@ -2,12 +2,12 @@
// 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.
// @dart = 2.5
// @dart = 2.4
// @dart = %VERSION_MARKER1%
// @dart = %VERSION_MARKER0%
part 'part.dart';
/*library: languageVersion=2.5*/
/*library: languageVersion=%VERSION_MARKER1%*/
main() {
// foo();

View file

@ -2,7 +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.
// @dart = 2.5
// @dart = %VERSION_MARKER1%
part of 'main.dart';

View file

@ -2,11 +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.
// @dart = 2.5
// @dart = %VERSION_MARKER1%
part /*error: errors=LanguageVersionMismatchInPart*/ 'part.dart';
/*library: languageVersion=2.5*/
/*library: languageVersion=%VERSION_MARKER1%*/
main() {
foo();

View file

@ -2,7 +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.
// @dart = 2.4
// @dart = %VERSION_MARKER0%
part of 'main.dart';

View file

@ -4,7 +4,7 @@
{
"name": "foo",
"rootUri": "../lib/",
"languageVersion": "2.5"
"languageVersion": "%VERSION_MARKER1%"
}
]
}

View file

@ -2,14 +2,15 @@
// 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.
// The library and its part is both technically at language version 2.5,
// but one is explicitly set, the other is not. That's an error.
// The library and its part is both technically at language version
// %VERSION_MARKER1%, but one is explicitly set, the other is not. That's an
// error.
// @dart = 2.5
// @dart = %VERSION_MARKER1%
part /*error: errors=LanguageVersionMismatchInPart*/ 'part.dart';
/*library: languageVersion=2.5*/
/*library: languageVersion=%VERSION_MARKER1%*/
foo() {
bar();

View file

@ -5,11 +5,11 @@
// Set version of this file (not technically in package) explicitly to test as
// much as possibly separately.
// @dart = 2.4
// @dart = %VERSION_MARKER0%
import 'package:foo/foo.dart';
/*library: languageVersion=2.4*/
/*library: languageVersion=%VERSION_MARKER0%*/
main() {
main();

View file

@ -4,7 +4,7 @@
{
"name": "foo",
"rootUri": "../lib/",
"languageVersion": "2.5"
"languageVersion": "%VERSION_MARKER1%"
}
]
}

View file

@ -2,12 +2,13 @@
// 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.
// The library and its part is both technically at language version 2.5,
// but one is explicitly set, the other is not. That's an error.
// The library and its part is both technically at language version
// %VERSION_MARKER1%, but one is explicitly set, the other is not. That's an
// error.
part /*error: errors=LanguageVersionMismatchInPart*/ 'part.dart';
/*library: languageVersion=2.5*/
/*library: languageVersion=%VERSION_MARKER1%*/
foo() {
bar();

View file

@ -2,7 +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.
// @dart = 2.5
// @dart = %VERSION_MARKER1%
part of 'foo.dart';

View file

@ -5,11 +5,11 @@
// Set version of this file (not technically in package) explicitly to test as
// much as possibly separately.
// @dart = 2.4
// @dart = %VERSION_MARKER0%
import 'package:foo/foo.dart';
/*library: languageVersion=2.4*/
/*library: languageVersion=%VERSION_MARKER0%*/
main() {
main();

View file

@ -1,4 +1,4 @@
/*library: languageVersion=2.8*/
/*library: languageVersion=%CURRENT_VERSION_MARKER%*/
String foo() {
return "42";

View file

@ -5,11 +5,11 @@
// Set version of this file (not technically in package) explicitly to test as
// much as possibly separately.
// @dart = 2.4
// @dart = %VERSION_MARKER0%
import 'package:foo/foo.dart';
/*library: languageVersion=2.4*/
/*library: languageVersion=%VERSION_MARKER0%*/
main() {
var result = foo();

View file

@ -5,11 +5,11 @@
// Set version of this file (not technically in package) explicitly to test as
// much as possibly separately.
// @dart = 2.4
// @dart = %VERSION_MARKER0%
import /*error: errors=UntranslatableUri*/ 'package:foo/foo.dart';
/*library: languageVersion=2.4*/
/*library: languageVersion=%VERSION_MARKER0%*/
main() {
var result = /*error: errors=MethodNotFound*/ notNamedFoo();

View file

@ -1,4 +1,4 @@
/*library: languageVersion=2.8*/
/*library: languageVersion=%CURRENT_VERSION_MARKER%*/
String foo() {
return "42";

View file

@ -5,11 +5,11 @@
// Set version of this file (not technically in package) explicitly to test as
// much as possibly separately.
// @dart = 2.4
// @dart = %VERSION_MARKER0%
import 'package:foo/foo.dart';
/*library: languageVersion=2.4*/
/*library: languageVersion=%VERSION_MARKER0%*/
main() {
var result = foo();

View file

@ -5,11 +5,11 @@
// Set version of this file (not technically in package) explicitly to test as
// much as possibly separately.
// @dart = 2.4
// @dart = %VERSION_MARKER0%
import /*error: errors=UntranslatableUri*/ 'package:foo/foo.dart';
/*library: languageVersion=2.4*/
/*library: languageVersion=%VERSION_MARKER0%*/
main() {
var result = /*error: errors=MethodNotFound*/ notNamedFoo();

View file

@ -25,6 +25,8 @@ import 'package:front_end/src/testing/id_testing_helper.dart'
import 'package:front_end/src/testing/id_testing_utils.dart';
import 'package:kernel/ast.dart' show Component, Library, Version;
import '../utils/symbolic_language_versions.dart';
Future<void> main(List<String> args) async {
// Fix default/max major and minor version so we can test it.
// This config sets it to 2.8.
@ -40,7 +42,9 @@ Future<void> main(List<String> args) async {
skipList: [
// Two language versions specified, the last one is ok and is used here.
"package_default_version_is_wrong_2",
]);
],
preprocessFile: replaceMarkersWithVersions,
postProcessData: replaceVersionsWithMarkers);
}
class TestConfigWithLanguageVersion extends CfeTestConfig {
@ -50,7 +54,8 @@ class TestConfigWithLanguageVersion extends CfeTestConfig {
@override
CompilerOptions customizeCompilerOptions(
CompilerOptions options, TestData testData) {
options.currentSdkVersion = "2.8";
options.currentSdkVersion =
SymbolicLanguageVersion.currentVersion.version.toText();
File f = new File.fromUri(testData.testFileUri.resolve("test.options"));
if (f.existsSync()) {

View file

@ -4,6 +4,6 @@
/*cfe:nnbd.library: nnbd=true*/
// @dart=2.9999
// @dart=%NNBD_VERSION_MARKER%
external int method(int? i);

View file

@ -2,7 +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.
// @dart=2.9999
// @dart=%NNBD_VERSION_MARKER%
// ignore: import_internal_library
import 'dart:_internal';

View file

@ -4,6 +4,6 @@
/*cfe:nnbd.library: nnbd=false*/
// @dart=2.6
// @dart=%LEGACY_VERSION_MARKER%
external int method(int i);

View file

@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
/*cfe:nnbd.error: message=The language version override has to be the same in the library and its patch(es).*/
// @dart=2.9999
// @dart=%NNBD_VERSION_MARKER%
// ignore: import_internal_library
import 'dart:_internal';

View file

@ -4,6 +4,6 @@
/*cfe:nnbd.library: nnbd=false*/
// @dart=2.6
// @dart=%LEGACY_VERSION_MARKER%
external int method();

View file

@ -2,7 +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.
// @dart=2.6
// @dart=%LEGACY_VERSION_MARKER%
// ignore: import_internal_library
import 'dart:_internal';

View file

@ -4,6 +4,6 @@
/*cfe:nnbd.library: nnbd=true*/
// @dart=2.9999
// @dart=%NNBD_VERSION_MARKER%
external int method();

View file

@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
/*cfe:nnbd.error: message=The language version override has to be the same in the library and its patch(es).*/
// @dart=2.6
// @dart=%LEGACY_VERSION_MARKER%
// ignore: import_internal_library
import 'dart:_internal';

View file

@ -20,6 +20,7 @@ import 'package:front_end/src/fasta/scope.dart';
import 'package:front_end/src/testing/id_testing_helper.dart';
import 'package:front_end/src/testing/id_testing_utils.dart';
import 'package:kernel/ast.dart';
import '../utils/symbolic_language_versions.dart';
Future<void> main(List<String> args) async {
Directory dataDir = new Directory.fromUri(Platform.script.resolve('data'));
@ -46,7 +47,9 @@ Future<void> main(List<String> args) async {
'opt_out',
'opt_out_patch',
]
});
},
preprocessFile: replaceMarkersWithVersions,
postProcessData: replaceVersionsWithMarkers);
}
class TestConfigWithLanguageVersion extends CfeTestConfig {
@ -61,7 +64,8 @@ class TestConfigWithLanguageVersion extends CfeTestConfig {
@override
void customizeCompilerOptions(CompilerOptions options, TestData testData) {
options.currentSdkVersion = "2.9999";
options.currentSdkVersion =
SymbolicLanguageVersion.nnbdVersion.version.toText();
}
}

View file

@ -0,0 +1,87 @@
// Copyright (c) 2024, 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:kernel/ast.dart';
/// Symbolic language versions for use in testing.
enum SymbolicLanguageVersion {
/// A valid language version the opts out of null safety.
legacyVersion("%LEGACY_VERSION_MARKER%", const Version(2, 6)),
/// A valid language version the opts in to null safety.
nnbdVersion("%NNBD_VERSION_MARKER%", const Version(2, 12)),
/// An invalid language version that is lower than [lowestVersion].
// TODO(johnniwinther): Report error on this.
tooLowVersion("%TOO_LOW_VERSION_MARKER%", const Version(1, 0)),
/// The lowest supported language version.
lowestVersion("%LOWEST_VERSION_MARKER%", const Version(2, 0)),
/// A valid language version larger than [lowestVersion] and lower than
/// [version1].
version0("%VERSION_MARKER0%", const Version(2, 4)),
/// A valid language version larger than [version0] and lower than
/// [version2].
version1("%VERSION_MARKER1%", const Version(2, 5)),
/// A valid language version larger than [version1] and lower than
/// [currentVersion].
version2("%VERSION_MARKER2%", const Version(2, 6)),
/// The current language version. This is also the highest supported version.
currentVersion("%CURRENT_VERSION_MARKER%", const Version(2, 8)),
/// An invalid language version that is higher than [currentVersion].
tooHighVersion("%TOO_HIGH_VERSION_MARKER%", const Version(2, 9999));
final String marker;
final Version version;
const SymbolicLanguageVersion(this.marker, this.version);
}
late final bool _validMarkers = _checkMarkers();
bool _checkMarkers() {
return SymbolicLanguageVersion.tooLowVersion.version <
SymbolicLanguageVersion.lowestVersion.version &&
SymbolicLanguageVersion.lowestVersion.version <
SymbolicLanguageVersion.version0.version &&
SymbolicLanguageVersion.version0.version <
SymbolicLanguageVersion.version1.version &&
SymbolicLanguageVersion.version1.version <
SymbolicLanguageVersion.version2.version &&
SymbolicLanguageVersion.version2.version <
SymbolicLanguageVersion.currentVersion.version &&
SymbolicLanguageVersion.currentVersion.version <
SymbolicLanguageVersion.tooHighVersion.version;
}
/// Replaces all occurrences of symbolic language markers in [text] with their
/// corresponding version as text.
String replaceMarkersWithVersions(String text) {
assert(_validMarkers);
for (SymbolicLanguageVersion symbolicVersion
in SymbolicLanguageVersion.values) {
String marker = symbolicVersion.marker;
Version version = symbolicVersion.version;
text = text.replaceAll(marker, version.toText());
}
return text;
}
/// Replaces all occurrences language versions as text in [text] with the
/// corresponding symbolic language markers.
String replaceVersionsWithMarkers(String text) {
assert(_validMarkers);
for (SymbolicLanguageVersion symbolicVersion
in SymbolicLanguageVersion.values) {
String marker = symbolicVersion.marker;
Version version = symbolicVersion.version;
text = text.replaceAll(version.toText(), marker);
}
return text;
}