mirror of
https://github.com/dart-lang/sdk
synced 2024-07-20 05:57:16 +00:00
[ddc] Add --canary flag to expression compiler worker
Closes: https://github.com/dart-lang/sdk/issues/52776 Change-Id: I639fe7fbadf3e938cc686aa8dbd2320a4cc7af7d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311151 Reviewed-by: Mark Zhou <markzipan@google.com> Commit-Queue: Anna Gringauze <annagrin@google.com> Reviewed-by: Nicholas Shahan <nshahan@google.com>
This commit is contained in:
parent
4a6f9328a2
commit
d2f5b3bfab
|
@ -83,6 +83,7 @@ class ExpressionCompilerWorker {
|
|||
final ProcessedOptions _processedOptions;
|
||||
final CompilerOptions _compilerOptions;
|
||||
final ModuleFormat _moduleFormat;
|
||||
final bool _canaryFeatures;
|
||||
final Component _sdkComponent;
|
||||
|
||||
void Function()? onDone;
|
||||
|
@ -91,6 +92,7 @@ class ExpressionCompilerWorker {
|
|||
this._processedOptions,
|
||||
this._compilerOptions,
|
||||
this._moduleFormat,
|
||||
this._canaryFeatures,
|
||||
this._sdkComponent,
|
||||
this.requestStream,
|
||||
this.sendResponse,
|
||||
|
@ -194,6 +196,7 @@ class ExpressionCompilerWorker {
|
|||
trackWidgetCreation: parsedArgs['track-widget-creation'] as bool,
|
||||
soundNullSafety: parsedArgs['sound-null-safety'] as bool,
|
||||
moduleFormat: moduleFormat,
|
||||
canaryFeatures: parsedArgs['canary'] as bool,
|
||||
verbose: parsedArgs['verbose'] as bool,
|
||||
requestStream: requestStream,
|
||||
sendResponse: sendResponse,
|
||||
|
@ -219,6 +222,7 @@ class ExpressionCompilerWorker {
|
|||
bool trackWidgetCreation = false,
|
||||
bool soundNullSafety = false,
|
||||
ModuleFormat moduleFormat = ModuleFormat.amd,
|
||||
bool canaryFeatures = false,
|
||||
bool verbose = false,
|
||||
Stream<Map<String, dynamic>>? requestStream, // Defaults to read from stdin
|
||||
void Function(Map<String, dynamic>)?
|
||||
|
@ -258,8 +262,15 @@ class ExpressionCompilerWorker {
|
|||
if (sdkComponent == null) {
|
||||
throw Exception('Could not load SDK component: $sdkSummary');
|
||||
}
|
||||
return ExpressionCompilerWorker._(processedOptions, compilerOptions,
|
||||
moduleFormat, sdkComponent, requestStream, sendResponse, onDone)
|
||||
return ExpressionCompilerWorker._(
|
||||
processedOptions,
|
||||
compilerOptions,
|
||||
moduleFormat,
|
||||
canaryFeatures,
|
||||
sdkComponent,
|
||||
requestStream,
|
||||
sendResponse,
|
||||
onDone)
|
||||
.._updateCache(sdkComponent, dartSdkModule, true);
|
||||
}
|
||||
|
||||
|
@ -436,11 +447,13 @@ class ExpressionCompilerWorker {
|
|||
finalComponent,
|
||||
hierarchy,
|
||||
SharedCompilerOptions(
|
||||
sourceMap: true,
|
||||
summarizeApi: false,
|
||||
moduleName: moduleName,
|
||||
soundNullSafety: _compilerOptions.nnbdMode == NnbdMode.Strong,
|
||||
enableAsserts: _enableAsserts),
|
||||
sourceMap: true,
|
||||
summarizeApi: false,
|
||||
moduleName: moduleName,
|
||||
soundNullSafety: _compilerOptions.nnbdMode == NnbdMode.Strong,
|
||||
enableAsserts: _enableAsserts,
|
||||
canaryFeatures: _canaryFeatures,
|
||||
),
|
||||
_moduleCache.componentForLibrary,
|
||||
_moduleCache.moduleNameForComponent,
|
||||
coreTypes: coreTypes,
|
||||
|
@ -776,6 +789,7 @@ final argParser = ArgParser()
|
|||
..addOption('module-format', defaultsTo: 'amd')
|
||||
..addFlag('track-widget-creation', defaultsTo: false)
|
||||
..addFlag('sound-null-safety', negatable: true, defaultsTo: true)
|
||||
..addFlag('canary', negatable: true, defaultsTo: false)
|
||||
..addFlag('verbose', defaultsTo: false);
|
||||
|
||||
Uri? _argToUri(String? uriArg) =>
|
||||
|
|
|
@ -149,11 +149,13 @@ class TestCompiler {
|
|||
|
||||
var classHierarchy = compilerResult.classHierarchy!;
|
||||
var compilerOptions = SharedCompilerOptions(
|
||||
replCompile: true,
|
||||
moduleName: moduleName,
|
||||
experiments: experiments,
|
||||
soundNullSafety: setup.soundNullSafety,
|
||||
emitDebugMetadata: true);
|
||||
replCompile: true,
|
||||
moduleName: moduleName,
|
||||
experiments: experiments,
|
||||
soundNullSafety: setup.soundNullSafety,
|
||||
emitDebugMetadata: true,
|
||||
canaryFeatures: false,
|
||||
);
|
||||
var coreTypes = compilerResult.coreTypes;
|
||||
|
||||
final importToSummary = Map<Library, Component>.identity();
|
||||
|
|
|
@ -114,10 +114,12 @@ class TestCompiler {
|
|||
var moduleName = 'foo.dart';
|
||||
var classHierarchy = compilerResult.classHierarchy;
|
||||
var compilerOptions = SharedCompilerOptions(
|
||||
replCompile: true,
|
||||
moduleName: moduleName,
|
||||
soundNullSafety: setup.soundNullSafety,
|
||||
moduleFormats: [setup.moduleFormat]);
|
||||
replCompile: true,
|
||||
moduleName: moduleName,
|
||||
soundNullSafety: setup.soundNullSafety,
|
||||
moduleFormats: [setup.moduleFormat],
|
||||
canaryFeatures: false,
|
||||
);
|
||||
var coreTypes = compilerResult.coreTypes;
|
||||
|
||||
final importToSummary = Map<Library, Component>.identity();
|
||||
|
@ -277,11 +279,28 @@ void main() {
|
|||
for (var moduleFormat in [ModuleFormat.amd, ModuleFormat.ddc]) {
|
||||
group('Module format: $moduleFormat |', () {
|
||||
group('Unsound null safety |', () {
|
||||
var options = SetupCompilerOptions(
|
||||
soundNullSafety: false, moduleFormat: moduleFormat);
|
||||
runUnsoundTests(moduleFormat);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
group('Expression compilations on the same expression compiler |', () {
|
||||
var source = '''
|
||||
for (var moduleFormat in [ModuleFormat.amd, ModuleFormat.ddc]) {
|
||||
group('Module format: $moduleFormat |', () {
|
||||
group('Sound null safety |', () {
|
||||
runSoundTests(moduleFormat);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void runUnsoundTests(ModuleFormat moduleFormat) {
|
||||
var options = SetupCompilerOptions(
|
||||
soundNullSafety: false,
|
||||
moduleFormat: moduleFormat,
|
||||
);
|
||||
|
||||
group('Expression compilations on the same expression compiler |', () {
|
||||
var source = '''
|
||||
${options.dartLangComment}
|
||||
main() {
|
||||
}
|
||||
|
@ -291,93 +310,93 @@ void main() {
|
|||
}
|
||||
''';
|
||||
|
||||
late TestDriver driver;
|
||||
late TestDriver driver;
|
||||
|
||||
setUp(() {
|
||||
driver = TestDriver(options, source);
|
||||
});
|
||||
setUp(() {
|
||||
driver = TestDriver(options, source);
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
driver.delete();
|
||||
});
|
||||
tearDown(() {
|
||||
driver.delete();
|
||||
});
|
||||
|
||||
test('successful expression compilations', () async {
|
||||
var compiler = await driver.createCompiler();
|
||||
await driver.check(
|
||||
compiler: compiler,
|
||||
scope: <String, String>{},
|
||||
expression: 'true',
|
||||
expectedResult: '''
|
||||
test('successful expression compilations', () async {
|
||||
var compiler = await driver.createCompiler();
|
||||
await driver.check(
|
||||
compiler: compiler,
|
||||
scope: <String, String>{},
|
||||
expression: 'true',
|
||||
expectedResult: '''
|
||||
(function() {
|
||||
return true;
|
||||
}(
|
||||
|
||||
))
|
||||
''');
|
||||
await driver.check(
|
||||
compiler: compiler,
|
||||
scope: <String, String>{},
|
||||
expression: 'false',
|
||||
expectedResult: '''
|
||||
await driver.check(
|
||||
compiler: compiler,
|
||||
scope: <String, String>{},
|
||||
expression: 'false',
|
||||
expectedResult: '''
|
||||
(function() {
|
||||
return false;
|
||||
}(
|
||||
|
||||
))
|
||||
''');
|
||||
});
|
||||
});
|
||||
|
||||
test('some successful expression compilations', () async {
|
||||
var compiler = await driver.createCompiler();
|
||||
await driver.check(
|
||||
compiler: compiler,
|
||||
scope: <String, String>{},
|
||||
expression: 'true',
|
||||
expectedResult: '''
|
||||
test('some successful expression compilations', () async {
|
||||
var compiler = await driver.createCompiler();
|
||||
await driver.check(
|
||||
compiler: compiler,
|
||||
scope: <String, String>{},
|
||||
expression: 'true',
|
||||
expectedResult: '''
|
||||
(function() {
|
||||
return true;
|
||||
}(
|
||||
|
||||
))
|
||||
''');
|
||||
await driver.check(
|
||||
compiler: compiler,
|
||||
scope: <String, String>{},
|
||||
expression: 'blah',
|
||||
expectedError: "Undefined name 'blah'",
|
||||
);
|
||||
await driver.check(
|
||||
compiler: compiler,
|
||||
scope: <String, String>{},
|
||||
expression: 'false',
|
||||
expectedResult: '''
|
||||
await driver.check(
|
||||
compiler: compiler,
|
||||
scope: <String, String>{},
|
||||
expression: 'blah',
|
||||
expectedError: "Undefined name 'blah'",
|
||||
);
|
||||
await driver.check(
|
||||
compiler: compiler,
|
||||
scope: <String, String>{},
|
||||
expression: 'false',
|
||||
expectedResult: '''
|
||||
(function() {
|
||||
return false;
|
||||
}(
|
||||
|
||||
))
|
||||
''');
|
||||
});
|
||||
});
|
||||
|
||||
test('failing expression compilations', () async {
|
||||
var compiler = await driver.createCompiler();
|
||||
await driver.check(
|
||||
compiler: compiler,
|
||||
scope: <String, String>{},
|
||||
expression: 'blah1',
|
||||
expectedError: "Undefined name 'blah1'",
|
||||
);
|
||||
await driver.check(
|
||||
compiler: compiler,
|
||||
scope: <String, String>{},
|
||||
expression: 'blah2',
|
||||
expectedError: "Undefined name 'blah2'",
|
||||
);
|
||||
});
|
||||
});
|
||||
test('failing expression compilations', () async {
|
||||
var compiler = await driver.createCompiler();
|
||||
await driver.check(
|
||||
compiler: compiler,
|
||||
scope: <String, String>{},
|
||||
expression: 'blah1',
|
||||
expectedError: "Undefined name 'blah1'",
|
||||
);
|
||||
await driver.check(
|
||||
compiler: compiler,
|
||||
scope: <String, String>{},
|
||||
expression: 'blah2',
|
||||
expectedError: "Undefined name 'blah2'",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('Expression compiler import tests', () {
|
||||
var source = '''
|
||||
group('Expression compiler import tests', () {
|
||||
var source = '''
|
||||
${options.dartLangComment}
|
||||
import 'dart:io' show Directory;
|
||||
import 'dart:io' as p;
|
||||
|
@ -394,21 +413,21 @@ void main() {
|
|||
}
|
||||
''';
|
||||
|
||||
late TestDriver driver;
|
||||
late TestDriver driver;
|
||||
|
||||
setUp(() {
|
||||
driver = TestDriver(options, source);
|
||||
});
|
||||
setUp(() {
|
||||
driver = TestDriver(options, source);
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
driver.delete();
|
||||
});
|
||||
tearDown(() {
|
||||
driver.delete();
|
||||
});
|
||||
|
||||
test('expression referencing unnamed import', () async {
|
||||
await driver.check(
|
||||
scope: <String, String>{},
|
||||
expression: 'Directory.systemTemp',
|
||||
expectedResult: '''
|
||||
test('expression referencing unnamed import', () async {
|
||||
await driver.check(
|
||||
scope: <String, String>{},
|
||||
expression: 'Directory.systemTemp',
|
||||
expectedResult: '''
|
||||
(function() {
|
||||
const dart_sdk = ${options.loadModule}('dart_sdk');
|
||||
const io = dart_sdk.io;
|
||||
|
@ -417,13 +436,13 @@ void main() {
|
|||
|
||||
))
|
||||
''');
|
||||
});
|
||||
});
|
||||
|
||||
test('expression referencing named import', () async {
|
||||
await driver.check(
|
||||
scope: <String, String>{},
|
||||
expression: 'p.Directory.systemTemp',
|
||||
expectedResult: '''
|
||||
test('expression referencing named import', () async {
|
||||
await driver.check(
|
||||
scope: <String, String>{},
|
||||
expression: 'p.Directory.systemTemp',
|
||||
expectedResult: '''
|
||||
(function() {
|
||||
const dart_sdk = ${options.loadModule}('dart_sdk');
|
||||
const io = dart_sdk.io;
|
||||
|
@ -432,15 +451,14 @@ void main() {
|
|||
|
||||
))
|
||||
''');
|
||||
});
|
||||
});
|
||||
|
||||
test(
|
||||
'expression referencing another library with the same named import',
|
||||
() async {
|
||||
await driver.check(
|
||||
scope: <String, String>{},
|
||||
expression: 'p.utf8.decoder',
|
||||
expectedResult: '''
|
||||
test('expression referencing another library with the same named import',
|
||||
() async {
|
||||
await driver.check(
|
||||
scope: <String, String>{},
|
||||
expression: 'p.utf8.decoder',
|
||||
expectedResult: '''
|
||||
(function() {
|
||||
const dart_sdk = ${options.loadModule}('dart_sdk');
|
||||
const convert = dart_sdk.convert;
|
||||
|
@ -449,13 +467,12 @@ void main() {
|
|||
|
||||
))
|
||||
''');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
group(
|
||||
'Expression compiler tests for interactions with module containers:',
|
||||
() {
|
||||
var source = '''
|
||||
group('Expression compiler tests for interactions with module containers:',
|
||||
() {
|
||||
var source = '''
|
||||
${options.dartLangComment}
|
||||
class A {
|
||||
const A();
|
||||
|
@ -473,22 +490,21 @@ void main() {
|
|||
void main() => foo();
|
||||
''';
|
||||
|
||||
late TestDriver driver;
|
||||
setUp(() {
|
||||
driver = TestDriver(options, source);
|
||||
});
|
||||
late TestDriver driver;
|
||||
setUp(() {
|
||||
driver = TestDriver(options, source);
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
driver.delete();
|
||||
});
|
||||
tearDown(() {
|
||||
driver.delete();
|
||||
});
|
||||
|
||||
test(
|
||||
'evaluation that non-destructively appends to the type container',
|
||||
() async {
|
||||
await driver.check(
|
||||
scope: <String, String>{'a': 'null', 'check': 'null'},
|
||||
expression: 'a is String',
|
||||
expectedResult: '''
|
||||
test('evaluation that non-destructively appends to the type container',
|
||||
() async {
|
||||
await driver.check(
|
||||
scope: <String, String>{'a': 'null', 'check': 'null'},
|
||||
expression: 'a is String',
|
||||
expectedResult: '''
|
||||
(function(a, check) {
|
||||
const dart_sdk = ${options.loadModule}('dart_sdk');
|
||||
const core = dart_sdk.core;
|
||||
|
@ -502,13 +518,13 @@ void main() {
|
|||
null
|
||||
))
|
||||
''');
|
||||
});
|
||||
});
|
||||
|
||||
test('evaluation that reuses the type container', () async {
|
||||
await driver.check(
|
||||
scope: <String, String>{'a': 'null', 'check': 'null'},
|
||||
expression: 'a is int',
|
||||
expectedResult: '''
|
||||
test('evaluation that reuses the type container', () async {
|
||||
await driver.check(
|
||||
scope: <String, String>{'a': 'null', 'check': 'null'},
|
||||
expression: 'a is int',
|
||||
expectedResult: '''
|
||||
(function(a, check) {
|
||||
const dart_sdk = ${options.loadModule}('dart_sdk');
|
||||
const core = dart_sdk.core;
|
||||
|
@ -522,15 +538,14 @@ void main() {
|
|||
null
|
||||
))
|
||||
''');
|
||||
});
|
||||
});
|
||||
|
||||
test(
|
||||
'evaluation that non-destructively appends to the constant container',
|
||||
() async {
|
||||
await driver.check(
|
||||
scope: <String, String>{'a': 'null', 'check': 'null'},
|
||||
expression: 'const B()',
|
||||
expectedResult: '''
|
||||
test('evaluation that non-destructively appends to the constant container',
|
||||
() async {
|
||||
await driver.check(
|
||||
scope: <String, String>{'a': 'null', 'check': 'null'},
|
||||
expression: 'const B()',
|
||||
expectedResult: '''
|
||||
(function(a, check) {
|
||||
const dart_sdk = ${options.loadModule}('dart_sdk');
|
||||
const dart = dart_sdk.dart;
|
||||
|
@ -550,15 +565,15 @@ void main() {
|
|||
null
|
||||
))
|
||||
''');
|
||||
});
|
||||
});
|
||||
|
||||
test(
|
||||
'evaluation that reuses the constant container and canonicalizes properly',
|
||||
() async {
|
||||
await driver.check(
|
||||
scope: <String, String>{'a': 'null', 'check': 'null'},
|
||||
expression: 'a == const A()',
|
||||
expectedResult: '''
|
||||
test(
|
||||
'evaluation that reuses the constant container and canonicalizes properly',
|
||||
() async {
|
||||
await driver.check(
|
||||
scope: <String, String>{'a': 'null', 'check': 'null'},
|
||||
expression: 'a == const A()',
|
||||
expectedResult: '''
|
||||
(function(a, check) {
|
||||
const dart_sdk = ${options.loadModule}('dart_sdk');
|
||||
const dart = dart_sdk.dart;
|
||||
|
@ -578,11 +593,11 @@ void main() {
|
|||
null
|
||||
))
|
||||
''');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
group('Expression compiler tests using extension symbols', () {
|
||||
var source = '''
|
||||
group('Expression compiler tests using extension symbols', () {
|
||||
var source = '''
|
||||
${options.dartLangComment}
|
||||
void bar() {
|
||||
/* evaluation placeholder */
|
||||
|
@ -591,21 +606,21 @@ void main() {
|
|||
void main() => bar();
|
||||
''';
|
||||
|
||||
late TestDriver driver;
|
||||
setUp(() {
|
||||
driver = TestDriver(options, source);
|
||||
});
|
||||
late TestDriver driver;
|
||||
setUp(() {
|
||||
driver = TestDriver(options, source);
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
driver.delete();
|
||||
});
|
||||
tearDown(() {
|
||||
driver.delete();
|
||||
});
|
||||
|
||||
test('map access', () async {
|
||||
await driver.check(
|
||||
scope: <String, String>{'inScope': '1', 'innerInScope': '0'},
|
||||
expression:
|
||||
'(Map<String, String> params) { return params["index"]; }({})',
|
||||
expectedResult: '''
|
||||
test('map access', () async {
|
||||
await driver.check(
|
||||
scope: <String, String>{'inScope': '1', 'innerInScope': '0'},
|
||||
expression:
|
||||
'(Map<String, String> params) { return params["index"]; }({})',
|
||||
expectedResult: '''
|
||||
(function() {
|
||||
const dart_sdk = ${options.loadModule}('dart_sdk');
|
||||
const core = dart_sdk.core;
|
||||
|
@ -625,19 +640,18 @@ void main() {
|
|||
|
||||
))
|
||||
''');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
for (var moduleFormat in [ModuleFormat.amd, ModuleFormat.ddc]) {
|
||||
group('Module format: $moduleFormat |', () {
|
||||
group('Sound null safety |', () {
|
||||
var options = SetupCompilerOptions(soundNullSafety: true);
|
||||
void runSoundTests(ModuleFormat moduleFormat) {
|
||||
var options = SetupCompilerOptions(
|
||||
soundNullSafety: true,
|
||||
moduleFormat: moduleFormat,
|
||||
);
|
||||
|
||||
group('Expression compilations on the same expression compiler |', () {
|
||||
var source = '''
|
||||
group('Expression compilations on the same expression compiler |', () {
|
||||
var source = '''
|
||||
${options.dartLangComment}
|
||||
main() {
|
||||
}
|
||||
|
@ -647,93 +661,93 @@ void main() {
|
|||
}
|
||||
''';
|
||||
|
||||
late TestDriver driver;
|
||||
late TestDriver driver;
|
||||
|
||||
setUp(() {
|
||||
driver = TestDriver(options, source);
|
||||
});
|
||||
setUp(() {
|
||||
driver = TestDriver(options, source);
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
driver.delete();
|
||||
});
|
||||
tearDown(() {
|
||||
driver.delete();
|
||||
});
|
||||
|
||||
test('successful expression compilations', () async {
|
||||
var compiler = await driver.createCompiler();
|
||||
await driver.check(
|
||||
compiler: compiler,
|
||||
scope: <String, String>{},
|
||||
expression: 'true',
|
||||
expectedResult: '''
|
||||
test('successful expression compilations', () async {
|
||||
var compiler = await driver.createCompiler();
|
||||
await driver.check(
|
||||
compiler: compiler,
|
||||
scope: <String, String>{},
|
||||
expression: 'true',
|
||||
expectedResult: '''
|
||||
(function() {
|
||||
return true;
|
||||
}(
|
||||
|
||||
))
|
||||
''');
|
||||
await driver.check(
|
||||
compiler: compiler,
|
||||
scope: <String, String>{},
|
||||
expression: 'false',
|
||||
expectedResult: '''
|
||||
await driver.check(
|
||||
compiler: compiler,
|
||||
scope: <String, String>{},
|
||||
expression: 'false',
|
||||
expectedResult: '''
|
||||
(function() {
|
||||
return false;
|
||||
}(
|
||||
|
||||
))
|
||||
''');
|
||||
});
|
||||
});
|
||||
|
||||
test('some successful expression compilations', () async {
|
||||
var compiler = await driver.createCompiler();
|
||||
await driver.check(
|
||||
compiler: compiler,
|
||||
scope: <String, String>{},
|
||||
expression: 'true',
|
||||
expectedResult: '''
|
||||
test('some successful expression compilations', () async {
|
||||
var compiler = await driver.createCompiler();
|
||||
await driver.check(
|
||||
compiler: compiler,
|
||||
scope: <String, String>{},
|
||||
expression: 'true',
|
||||
expectedResult: '''
|
||||
(function() {
|
||||
return true;
|
||||
}(
|
||||
|
||||
))
|
||||
''');
|
||||
await driver.check(
|
||||
compiler: compiler,
|
||||
scope: <String, String>{},
|
||||
expression: 'blah',
|
||||
expectedError: "Undefined name 'blah'",
|
||||
);
|
||||
await driver.check(
|
||||
compiler: compiler,
|
||||
scope: <String, String>{},
|
||||
expression: 'false',
|
||||
expectedResult: '''
|
||||
await driver.check(
|
||||
compiler: compiler,
|
||||
scope: <String, String>{},
|
||||
expression: 'blah',
|
||||
expectedError: "Undefined name 'blah'",
|
||||
);
|
||||
await driver.check(
|
||||
compiler: compiler,
|
||||
scope: <String, String>{},
|
||||
expression: 'false',
|
||||
expectedResult: '''
|
||||
(function() {
|
||||
return false;
|
||||
}(
|
||||
|
||||
))
|
||||
''');
|
||||
});
|
||||
});
|
||||
|
||||
test('failing expression compilations', () async {
|
||||
var compiler = await driver.createCompiler();
|
||||
await driver.check(
|
||||
compiler: compiler,
|
||||
scope: <String, String>{},
|
||||
expression: 'blah1',
|
||||
expectedError: "Undefined name 'blah1'",
|
||||
);
|
||||
await driver.check(
|
||||
compiler: compiler,
|
||||
scope: <String, String>{},
|
||||
expression: 'blah2',
|
||||
expectedError: "Undefined name 'blah2'",
|
||||
);
|
||||
});
|
||||
});
|
||||
test('failing expression compilations', () async {
|
||||
var compiler = await driver.createCompiler();
|
||||
await driver.check(
|
||||
compiler: compiler,
|
||||
scope: <String, String>{},
|
||||
expression: 'blah1',
|
||||
expectedError: "Undefined name 'blah1'",
|
||||
);
|
||||
await driver.check(
|
||||
compiler: compiler,
|
||||
scope: <String, String>{},
|
||||
expression: 'blah2',
|
||||
expectedError: "Undefined name 'blah2'",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('Expression compiler import tests', () {
|
||||
var source = '''
|
||||
group('Expression compiler import tests', () {
|
||||
var source = '''
|
||||
${options.dartLangComment}
|
||||
import 'dart:io' show Directory;
|
||||
import 'dart:io' as p;
|
||||
|
@ -750,21 +764,21 @@ void main() {
|
|||
}
|
||||
''';
|
||||
|
||||
late TestDriver driver;
|
||||
late TestDriver driver;
|
||||
|
||||
setUp(() {
|
||||
driver = TestDriver(options, source);
|
||||
});
|
||||
setUp(() {
|
||||
driver = TestDriver(options, source);
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
driver.delete();
|
||||
});
|
||||
tearDown(() {
|
||||
driver.delete();
|
||||
});
|
||||
|
||||
test('expression referencing unnamed import', () async {
|
||||
await driver.check(
|
||||
scope: <String, String>{},
|
||||
expression: 'Directory.systemTemp',
|
||||
expectedResult: '''
|
||||
test('expression referencing unnamed import', () async {
|
||||
await driver.check(
|
||||
scope: <String, String>{},
|
||||
expression: 'Directory.systemTemp',
|
||||
expectedResult: '''
|
||||
(function() {
|
||||
const dart_sdk = ${options.loadModule}('dart_sdk');
|
||||
const io = dart_sdk.io;
|
||||
|
@ -773,13 +787,13 @@ void main() {
|
|||
|
||||
))
|
||||
''');
|
||||
});
|
||||
});
|
||||
|
||||
test('expression referencing named import', () async {
|
||||
await driver.check(
|
||||
scope: <String, String>{},
|
||||
expression: 'p.Directory.systemTemp',
|
||||
expectedResult: '''
|
||||
test('expression referencing named import', () async {
|
||||
await driver.check(
|
||||
scope: <String, String>{},
|
||||
expression: 'p.Directory.systemTemp',
|
||||
expectedResult: '''
|
||||
(function() {
|
||||
const dart_sdk = ${options.loadModule}('dart_sdk');
|
||||
const io = dart_sdk.io;
|
||||
|
@ -788,15 +802,14 @@ void main() {
|
|||
|
||||
))
|
||||
''');
|
||||
});
|
||||
});
|
||||
|
||||
test(
|
||||
'expression referencing another library with the same named import',
|
||||
() async {
|
||||
await driver.check(
|
||||
scope: <String, String>{},
|
||||
expression: 'p.utf8.decoder',
|
||||
expectedResult: '''
|
||||
test('expression referencing another library with the same named import',
|
||||
() async {
|
||||
await driver.check(
|
||||
scope: <String, String>{},
|
||||
expression: 'p.utf8.decoder',
|
||||
expectedResult: '''
|
||||
(function() {
|
||||
const dart_sdk = ${options.loadModule}('dart_sdk');
|
||||
const convert = dart_sdk.convert;
|
||||
|
@ -805,12 +818,11 @@ void main() {
|
|||
|
||||
))
|
||||
''');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
group('Expression compiler expressions that import extension symbols',
|
||||
() {
|
||||
var source = '''
|
||||
group('Expression compiler expressions that import extension symbols', () {
|
||||
var source = '''
|
||||
${options.dartLangComment}
|
||||
void bar() {
|
||||
/* evaluation placeholder */
|
||||
|
@ -819,21 +831,21 @@ void main() {
|
|||
void main() => bar();
|
||||
''';
|
||||
|
||||
late TestDriver driver;
|
||||
setUp(() {
|
||||
driver = TestDriver(options, source);
|
||||
});
|
||||
late TestDriver driver;
|
||||
setUp(() {
|
||||
driver = TestDriver(options, source);
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
driver.delete();
|
||||
});
|
||||
tearDown(() {
|
||||
driver.delete();
|
||||
});
|
||||
|
||||
test('map access', () async {
|
||||
await driver.check(
|
||||
scope: <String, String>{'inScope': '1', 'innerInScope': '0'},
|
||||
expression:
|
||||
'(Map<String, String> params) { return params["index"]; }({})',
|
||||
expectedResult: '''
|
||||
test('map access', () async {
|
||||
await driver.check(
|
||||
scope: <String, String>{'inScope': '1', 'innerInScope': '0'},
|
||||
expression:
|
||||
'(Map<String, String> params) { return params["index"]; }({})',
|
||||
expectedResult: '''
|
||||
(function() {
|
||||
const dart_sdk = ${options.loadModule}('dart_sdk');
|
||||
const core = dart_sdk.core;
|
||||
|
@ -852,9 +864,6 @@ void main() {
|
|||
|
||||
))
|
||||
''');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright (c) 2023, 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:dev_compiler/dev_compiler.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'expression_compiler_worker_shared.dart';
|
||||
|
||||
void main() async {
|
||||
// Set to true to enable debug output
|
||||
var debug = false;
|
||||
|
||||
group('canary -', () {
|
||||
group('amd module format -', () {
|
||||
for (var soundNullSafety in [true, false]) {
|
||||
group('${soundNullSafety ? "sound" : "unsound"} null safety -', () {
|
||||
runTests(
|
||||
moduleFormat: ModuleFormat.amd,
|
||||
soundNullSafety: soundNullSafety,
|
||||
canaryFeatures: true,
|
||||
verbose: debug,
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
|
@ -17,6 +17,7 @@ void main() async {
|
|||
runTests(
|
||||
moduleFormat: ModuleFormat.amd,
|
||||
soundNullSafety: soundNullSafety,
|
||||
canaryFeatures: false,
|
||||
verbose: debug,
|
||||
);
|
||||
});
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright (c) 2023, 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:dev_compiler/dev_compiler.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'expression_compiler_worker_shared.dart';
|
||||
|
||||
void main() async {
|
||||
// Set to true to enable debug output
|
||||
var debug = false;
|
||||
|
||||
group('canary -', () {
|
||||
group('ddc module format -', () {
|
||||
for (var soundNullSafety in [true, false]) {
|
||||
group('${soundNullSafety ? "sound" : "unsound"} null safety -', () {
|
||||
runTests(
|
||||
moduleFormat: ModuleFormat.ddc,
|
||||
soundNullSafety: soundNullSafety,
|
||||
canaryFeatures: true,
|
||||
verbose: debug,
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
|
@ -17,6 +17,7 @@ void main() async {
|
|||
runTests(
|
||||
moduleFormat: ModuleFormat.ddc,
|
||||
soundNullSafety: soundNullSafety,
|
||||
canaryFeatures: false,
|
||||
verbose: debug,
|
||||
);
|
||||
});
|
||||
|
|
|
@ -25,6 +25,7 @@ import 'package:test/test.dart';
|
|||
void runTests({
|
||||
required ModuleFormat moduleFormat,
|
||||
required bool soundNullSafety,
|
||||
required bool canaryFeatures,
|
||||
bool verbose = false,
|
||||
}) {
|
||||
group('expression compiler worker on startup', () {
|
||||
|
@ -64,6 +65,7 @@ void runTests({
|
|||
'--module-format',
|
||||
moduleFormat.name,
|
||||
soundNullSafety ? '--sound-null-safety' : '--no-sound-null-safety',
|
||||
if (canaryFeatures) '--canary',
|
||||
if (verbose) '--verbose',
|
||||
],
|
||||
sendPort: receivePort.sendPort,
|
||||
|
@ -75,18 +77,30 @@ void runTests({
|
|||
});
|
||||
|
||||
group('reading assets using standard file system - ', () {
|
||||
runExpressionCompilationTests(
|
||||
StandardFileSystemTestDriver(soundNullSafety, moduleFormat, verbose));
|
||||
runExpressionCompilationTests(StandardFileSystemTestDriver(
|
||||
soundNullSafety,
|
||||
moduleFormat,
|
||||
canaryFeatures,
|
||||
verbose,
|
||||
));
|
||||
});
|
||||
|
||||
group('reading assets using multiroot file system - ', () {
|
||||
runExpressionCompilationTests(
|
||||
MultiRootFileSystemTestDriver(soundNullSafety, moduleFormat, verbose));
|
||||
runExpressionCompilationTests(MultiRootFileSystemTestDriver(
|
||||
soundNullSafety,
|
||||
moduleFormat,
|
||||
canaryFeatures,
|
||||
verbose,
|
||||
));
|
||||
});
|
||||
|
||||
group('reading assets using asset file system -', () {
|
||||
runExpressionCompilationTests(
|
||||
AssetFileSystemTestDriver(soundNullSafety, moduleFormat, verbose));
|
||||
runExpressionCompilationTests(AssetFileSystemTestDriver(
|
||||
soundNullSafety,
|
||||
moduleFormat,
|
||||
canaryFeatures,
|
||||
verbose,
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -950,6 +964,7 @@ class E {
|
|||
abstract class TestDriver {
|
||||
final bool soundNullSafety;
|
||||
final ModuleFormat moduleFormat;
|
||||
final bool canaryFeatures;
|
||||
final bool verbose;
|
||||
|
||||
late FileSystem fileSystem;
|
||||
|
@ -964,7 +979,8 @@ abstract class TestDriver {
|
|||
ExpressionCompilerWorker? worker;
|
||||
Future<void>? workerDone;
|
||||
|
||||
TestDriver(this.soundNullSafety, this.moduleFormat, this.verbose);
|
||||
TestDriver(this.soundNullSafety, this.moduleFormat, this.canaryFeatures,
|
||||
this.verbose);
|
||||
|
||||
/// Initialize file systems, inputs, and start servers if needed.
|
||||
Future<void> start();
|
||||
|
@ -1005,6 +1021,7 @@ abstract class TestDriver {
|
|||
sendResponse: responseController.add,
|
||||
soundNullSafety: soundNullSafety,
|
||||
moduleFormat: moduleFormat,
|
||||
canaryFeatures: canaryFeatures,
|
||||
verbose: verbose,
|
||||
);
|
||||
workerDone = worker?.run();
|
||||
|
@ -1022,8 +1039,9 @@ class StandardFileSystemTestDriver extends TestDriver {
|
|||
StandardFileSystemTestDriver(
|
||||
bool soundNullSafety,
|
||||
ModuleFormat moduleFormat,
|
||||
bool canaryFeatures,
|
||||
bool verbose,
|
||||
) : super(soundNullSafety, moduleFormat, verbose);
|
||||
) : super(soundNullSafety, moduleFormat, canaryFeatures, verbose);
|
||||
|
||||
@override
|
||||
Future<void> start() async {
|
||||
|
@ -1038,8 +1056,9 @@ class MultiRootFileSystemTestDriver extends TestDriver {
|
|||
MultiRootFileSystemTestDriver(
|
||||
bool soundNullSafety,
|
||||
ModuleFormat moduleFormat,
|
||||
bool canaryFeatures,
|
||||
bool verbose,
|
||||
) : super(soundNullSafety, moduleFormat, verbose);
|
||||
) : super(soundNullSafety, moduleFormat, canaryFeatures, verbose);
|
||||
|
||||
@override
|
||||
Future<void> start() async {
|
||||
|
@ -1057,8 +1076,9 @@ class AssetFileSystemTestDriver extends TestDriver {
|
|||
AssetFileSystemTestDriver(
|
||||
bool soundNullSafety,
|
||||
ModuleFormat moduleFormat,
|
||||
bool canaryFeatures,
|
||||
bool verbose,
|
||||
) : super(soundNullSafety, moduleFormat, verbose);
|
||||
) : super(soundNullSafety, moduleFormat, canaryFeatures, verbose);
|
||||
|
||||
@override
|
||||
Future<void> start() async {
|
||||
|
|
|
@ -74,10 +74,13 @@ class SetupCompilerOptions {
|
|||
final String dartLangComment;
|
||||
final ModuleFormat moduleFormat;
|
||||
final bool soundNullSafety;
|
||||
final bool canaryFeatures;
|
||||
|
||||
SetupCompilerOptions(
|
||||
{this.soundNullSafety = true, this.moduleFormat = ModuleFormat.amd})
|
||||
: options = getOptions(soundNullSafety),
|
||||
SetupCompilerOptions({
|
||||
this.soundNullSafety = true,
|
||||
this.moduleFormat = ModuleFormat.amd,
|
||||
this.canaryFeatures = false,
|
||||
}) : options = getOptions(soundNullSafety),
|
||||
dartLangComment =
|
||||
soundNullSafety ? dartSoundComment : dartUnsoundComment {
|
||||
options.onDiagnostic = (DiagnosticMessage m) {
|
||||
|
|
Loading…
Reference in a new issue