OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'package:front_end/front_end.dart'; | 5 import 'package:front_end/front_end.dart'; |
6 import 'package:front_end/src/fasta/fasta_codes.dart'; | 6 import 'package:front_end/src/fasta/fasta_codes.dart'; |
7 import 'package:front_end/src/fasta/kernel/utils.dart'; | 7 import 'package:front_end/src/fasta/kernel/utils.dart'; |
8 import 'package:front_end/src/fasta/deprecated_problems.dart' | 8 import 'package:front_end/src/fasta/deprecated_problems.dart' |
9 show deprecated_InputError; | 9 show deprecated_InputError; |
10 import 'package:front_end/src/testing/compiler_common.dart'; | 10 import 'package:front_end/src/testing/compiler_common.dart'; |
11 import 'package:kernel/ast.dart'; | 11 import 'package:kernel/ast.dart'; |
12 | 12 |
13 import 'package:test/test.dart'; | 13 import 'package:test/test.dart'; |
14 | 14 |
15 main() { | 15 main() { |
16 group('kernelForProgram', () { | 16 group('kernelForProgram', () { |
17 test('compiler fails if it cannot find sdk sources', () async { | 17 test('compiler fails if it cannot find sdk sources', () async { |
18 var errors = []; | 18 var errors = []; |
19 var options = new CompilerOptions() | 19 var options = new CompilerOptions() |
20 ..librariesSpecificationUri = invalidCoreLibsSpecUri | 20 ..dartLibraries = invalidCoreLibs |
21 ..sdkSummary = null | 21 ..sdkSummary = null |
22 ..compileSdk = true // To prevent FE from loading an sdk-summary. | 22 ..compileSdk = true // To prevent FE from loading an sdk-summary. |
23 ..onError = (e) => errors.add(e); | 23 ..onError = (e) => errors.add(e); |
24 | 24 |
25 var program = | 25 var program = |
26 await compileScript('main() => print("hi");', options: options); | 26 await compileScript('main() => print("hi");', options: options); |
27 expect(program, isNull); | 27 expect(program, isNull); |
28 expect(errors, isNotEmpty); | 28 expect(errors, isNotEmpty); |
29 }); | 29 }); |
30 | 30 |
31 test('compiler fails if it cannot find sdk summary', () async { | 31 test('compiler fails if it cannot find sdk summary', () async { |
32 var errors = []; | 32 var errors = []; |
33 var options = new CompilerOptions() | 33 var options = new CompilerOptions() |
34 ..sdkSummary = Uri.parse('file:///not_existing_summary_file') | 34 ..sdkSummary = Uri.parse('file:///not_existing_summary_file') |
35 ..onError = (e) => errors.add(e); | 35 ..onError = (e) => errors.add(e); |
36 | 36 |
37 var program = | 37 var program = |
38 await compileScript('main() => print("hi");', options: options); | 38 await compileScript('main() => print("hi");', options: options); |
39 expect(program, isNull); | 39 expect(program, isNull); |
40 expect(errors, isNotEmpty); | 40 expect(errors, isNotEmpty); |
41 }); | 41 }); |
42 | 42 |
43 test('by default program is compiled using summaries', () async { | 43 test('by default program is compiled using summaries', () async { |
44 var options = new CompilerOptions() | 44 var options = new CompilerOptions() |
45 // Note: we define [librariesSpecificationUri] with a specification that | 45 // Note: we define [dartLibraries] with broken URIs to ensure we do not |
46 // contains broken URIs to ensure we do not attempt to lookup for | 46 // attempt to lookup for sources of the sdk directly. |
47 // sources of the sdk directly. | 47 ..dartLibraries = invalidCoreLibs; |
48 ..librariesSpecificationUri = invalidCoreLibsSpecUri; | |
49 var program = | 48 var program = |
50 await compileScript('main() => print("hi");', options: options); | 49 await compileScript('main() => print("hi");', options: options); |
51 var core = program.libraries.firstWhere(isDartCoreLibrary); | 50 var core = program.libraries.firstWhere(isDartCoreLibrary); |
52 var printMember = core.members.firstWhere((m) => m.name.name == 'print'); | 51 var printMember = core.members.firstWhere((m) => m.name.name == 'print'); |
53 | 52 |
54 // Note: summaries created by the SDK today contain empty statements as | 53 // Note: summaries created by the SDK today contain empty statements as |
55 // method bodies. | 54 // method bodies. |
56 expect(printMember.function.body is EmptyStatement, isTrue); | 55 expect(printMember.function.body is EmptyStatement, isTrue); |
57 }); | 56 }); |
58 | 57 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 checkDCallsC(unitD1); | 205 checkDCallsC(unitD1); |
207 | 206 |
208 var unitD2 = await compileUnit(['d.dart'], sources, | 207 var unitD2 = await compileUnit(['d.dart'], sources, |
209 inputSummaries: ['bc.dill', 'a.dill']); | 208 inputSummaries: ['bc.dill', 'a.dill']); |
210 checkDCallsC(unitD2); | 209 checkDCallsC(unitD2); |
211 }); | 210 }); |
212 | 211 |
213 // TODO(sigmund): add tests with trimming dependencies | 212 // TODO(sigmund): add tests with trimming dependencies |
214 }); | 213 }); |
215 } | 214 } |
OLD | NEW |