67d752aa12
- Allow running the tests with asserts enabled
- Allow running the tests in canary mode
- Unify common test code and remove duplication
- merge expression_compiler/setup_compiler_options.dart
into share_compiler_options.dart
- Merge TestCompiler code from expression evaluation and
expression compilation tests and move into
expression_compiler/test_compiler.dart
- Rename various TestDrivers so they have more descriptive names
- Remove 'golden' JS comparison tests from expression_compiler_test.dart
- replace by evaluation tests where needed
Closes: https://github.com/dart-lang/sdk/issues/53145
Change-Id: Ic797fa4ee9bfa6b858b924be9f9a53fd10ae1448
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/318080
Commit-Queue: Anna Gringauze <annagrin@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
159 lines
4.3 KiB
Dart
159 lines
4.3 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 |', () {
|
|
group('Unsound null safety |', () {
|
|
runTests(SetupCompilerOptions(
|
|
soundNullSafety: false,
|
|
moduleFormat: moduleFormat,
|
|
args: args,
|
|
));
|
|
});
|
|
});
|
|
}
|
|
|
|
for (var moduleFormat in [ModuleFormat.amd, ModuleFormat.ddc]) {
|
|
group('Module format: $moduleFormat |', () {
|
|
group('Sound null safety |', () {
|
|
runTests(SetupCompilerOptions(
|
|
soundNullSafety: true,
|
|
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 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;'));
|
|
});
|
|
});
|
|
}
|