559b8552a8
Update the last known good component after a recompile reject back to the expected state before the recompile. Adds tests for expression compilation after recompile accept and recompile reject cases with `--target=dartdevc`. Similar to existing tests for the VM. Removes calls to `_generator.accept()` and `component.computeCanonicalNames()` from `compileExpressionToJs()`. These were added very early in the prototype implementation and it is no longer clear why they would be needed. Added some additional test cases for expression compilation involving import resolution because the change that originally added the `component.computeCanonicalNames()` call implies it was needed for that reason. See: https://dart-review.googlesource.com/c/sdk/+/138010 TEST=pkg/frontend_server/test/frontend_server_test.dart,pkg/dev_compiler/test/expression_compiler/expression_compiler_test.dart Change-Id: I9c04bd46e56b33dc654d00fb330de29c3c643a5b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/434522 Reviewed-by: Alexander Markov <alexmarkov@google.com> Commit-Queue: Nicholas Shahan <nshahan@google.com> Reviewed-by: Nate Biggs <natebiggs@google.com> Reviewed-by: Jens Johansen <jensj@google.com>
211 lines
5.6 KiB
Dart
211 lines
5.6 KiB
Dart
// Copyright (c) 2020, 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/src/compiler/module_builder.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
import '../shared_test_options.dart';
|
|
import 'expression_compiler_suite.dart';
|
|
|
|
void main(List<String> args) {
|
|
for (var moduleFormat in [ModuleFormat.amd, ModuleFormat.ddc]) {
|
|
group('Module format: $moduleFormat |', () {
|
|
runTests(SetupCompilerOptions(moduleFormat: moduleFormat, args: args));
|
|
});
|
|
}
|
|
}
|
|
|
|
void runTests(SetupCompilerOptions setup) {
|
|
group('Expression compilations on the same expression compiler |', () {
|
|
var source = '''
|
|
main() {
|
|
}
|
|
|
|
void foo() {
|
|
// Breakpoint
|
|
}
|
|
''';
|
|
|
|
late ExpressionCompilerTestDriver driver;
|
|
|
|
setUp(() {
|
|
driver = ExpressionCompilerTestDriver(setup, source);
|
|
});
|
|
|
|
tearDown(() {
|
|
driver.delete();
|
|
});
|
|
|
|
test('successful expression compilations', () async {
|
|
var compiler = await driver.createCompiler();
|
|
await driver.check(
|
|
compiler: compiler,
|
|
scope: <String, String>{},
|
|
expression: 'true',
|
|
expectedResult: contains('return true;'),
|
|
);
|
|
await driver.check(
|
|
compiler: compiler,
|
|
scope: <String, String>{},
|
|
expression: 'false',
|
|
expectedResult: contains('return false;'),
|
|
);
|
|
});
|
|
|
|
test('some successful expression compilations', () async {
|
|
var compiler = await driver.createCompiler();
|
|
await driver.check(
|
|
compiler: compiler,
|
|
scope: <String, String>{},
|
|
expression: 'true',
|
|
expectedResult: contains('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: contains('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'",
|
|
);
|
|
});
|
|
});
|
|
|
|
group('Expression compiler dart: import tests', () {
|
|
var source = '''
|
|
import 'dart:io' show Directory;
|
|
import 'dart:io' as p;
|
|
import 'dart:convert' as p;
|
|
|
|
main() {
|
|
print(Directory.systemTemp);
|
|
print(p.Directory.systemTemp);
|
|
print(p.utf8.decoder);
|
|
}
|
|
|
|
void foo() {
|
|
// Breakpoint
|
|
}
|
|
''';
|
|
|
|
late ExpressionCompilerTestDriver driver;
|
|
|
|
setUp(() {
|
|
driver = ExpressionCompilerTestDriver(setup, source);
|
|
});
|
|
|
|
tearDown(() {
|
|
driver.delete();
|
|
});
|
|
|
|
test('expression referencing unnamed import', () async {
|
|
await driver.check(
|
|
scope: <String, String>{},
|
|
expression: 'Directory.systemTemp',
|
|
expectedResult: contains('return io.Directory.systemTemp;'),
|
|
);
|
|
});
|
|
|
|
test('expression referencing named import', () async {
|
|
await driver.check(
|
|
scope: <String, String>{},
|
|
expression: 'p.Directory.systemTemp',
|
|
expectedResult: contains('return io.Directory.systemTemp;'),
|
|
);
|
|
});
|
|
|
|
test(
|
|
'expression referencing another library with the same named import',
|
|
() async {
|
|
await driver.check(
|
|
scope: <String, String>{},
|
|
expression: 'p.utf8.decoder',
|
|
expectedResult: contains('return convert.utf8.decoder;'),
|
|
);
|
|
},
|
|
);
|
|
});
|
|
group('Expression compiler package: import tests', () {
|
|
var source = '''
|
|
import 'package:a/a.dart' show topLevelMethod;
|
|
import 'package:a/a.dart' as prefix;
|
|
import 'package:b/b.dart' as prefix;
|
|
|
|
main() {
|
|
print(topLevelMethod(99));
|
|
print(prefix.topLevelMethod(99));
|
|
print(prefix.anotherTopLevelMethod('hello'));
|
|
}
|
|
|
|
void foo() {
|
|
// Breakpoint
|
|
}
|
|
''';
|
|
|
|
var a = 'bool topLevelMethod(int i) => i.isEven;';
|
|
var b = 'int anotherTopLevelMethod(String s) => s.length;';
|
|
|
|
late ExpressionCompilerTestDriver driver;
|
|
|
|
setUp(() {
|
|
driver = ExpressionCompilerTestDriver(
|
|
setup,
|
|
source,
|
|
additionalLibraries: [(name: 'a', source: a), (name: 'b', source: b)],
|
|
);
|
|
});
|
|
|
|
tearDown(() {
|
|
driver.delete();
|
|
});
|
|
|
|
test('expression referencing unnamed import', () async {
|
|
await driver.check(
|
|
scope: <String, String>{},
|
|
expression: 'topLevelMethod(99)',
|
|
expectedResult: contains('return a.topLevelMethod(99);'),
|
|
);
|
|
});
|
|
|
|
test('expression referencing named import', () async {
|
|
await driver.check(
|
|
scope: <String, String>{},
|
|
expression: 'prefix.topLevelMethod(99)',
|
|
expectedResult: contains('return a.topLevelMethod(99);'),
|
|
);
|
|
});
|
|
|
|
test(
|
|
'expression referencing another library with the same named import',
|
|
() async {
|
|
await driver.check(
|
|
scope: <String, String>{},
|
|
expression: 'prefix.anotherTopLevelMethod("hello")',
|
|
expectedResult: contains('return b.anotherTopLevelMethod("hello")'),
|
|
);
|
|
},
|
|
);
|
|
});
|
|
}
|