Chromium Code Reviews| 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/kernel/utils.dart'; | 6 import 'package:front_end/src/fasta/kernel/utils.dart'; |
| 7 import 'package:front_end/src/testing/compiler_common.dart'; | 7 import 'package:front_end/src/testing/compiler_common.dart'; |
| 8 import 'package:kernel/ast.dart'; | 8 import 'package:kernel/ast.dart'; |
| 9 | 9 |
| 10 import 'package:test/test.dart'; | 10 import 'package:test/test.dart'; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 | 49 |
| 50 // Note: summaries created by the SDK today contain empty statements as | 50 // Note: summaries created by the SDK today contain empty statements as |
| 51 // method bodies. | 51 // method bodies. |
| 52 expect(printMember.function.body is EmptyStatement, isTrue); | 52 expect(printMember.function.body is EmptyStatement, isTrue); |
| 53 }); | 53 }); |
| 54 | 54 |
| 55 test('compiler requires a main method', () async { | 55 test('compiler requires a main method', () async { |
| 56 var errors = []; | 56 var errors = []; |
| 57 var options = new CompilerOptions()..onError = (e) => errors.add(e); | 57 var options = new CompilerOptions()..onError = (e) => errors.add(e); |
| 58 await compileScript('a() => print("hi");', options: options); | 58 await compileScript('a() => print("hi");', options: options); |
| 59 expect('${errors.first}', contains("No 'main' method found")); | 59 // TODO(sigmund): when we expose codes in the public APIs, we should |
| 60 // compare the code here and not the message. | |
| 61 expect(errors.first.message, contains("No 'main' method found")); | |
|
ahe
2017/07/12 13:14:44
Since this is a front_end test, you can import fas
Siggi Cherem (dart-lang)
2017/07/12 21:54:59
Not quite: we are not exposing the `Code` class fr
| |
| 60 }); | 62 }); |
| 61 | 63 |
| 62 test('default error handler throws', () async { | 64 test('default error handler throws', () async { |
| 63 var exceptionThrown = false; | 65 var exceptionThrown = false; |
| 64 try { | 66 try { |
| 65 await compileScript('a() => print("hi");'); | 67 await compileScript('a() => print("hi");'); |
| 66 } catch (e) { | 68 } on CompilationError catch (e) { |
| 67 exceptionThrown = true; | 69 exceptionThrown = true; |
| 68 expect('$e', contains("No 'main' method found")); | 70 expect(e.message, contains("No 'main' method found")); |
| 69 } | 71 } |
| 70 expect(exceptionThrown, isTrue); | 72 expect(exceptionThrown, isTrue); |
| 71 }); | 73 }); |
| 72 | 74 |
| 73 test('generated program contains source-info', () async { | 75 test('generated program contains source-info', () async { |
| 74 var program = await compileScript('a() => print("hi"); main() {}', | 76 var program = await compileScript('a() => print("hi"); main() {}', |
| 75 fileName: 'a.dart'); | 77 fileName: 'a.dart'); |
| 76 // Kernel always store an empty '' key in the map, so there is always at | 78 // Kernel always store an empty '' key in the map, so there is always at |
| 77 // least one. Having more means that source-info is added. | 79 // least one. Having more means that source-info is added. |
| 78 expect(program.uriToSource.keys.length, greaterThan(1)); | 80 expect(program.uriToSource.keys.length, greaterThan(1)); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 }); | 141 }); |
| 140 | 142 |
| 141 test('compiler by default is hermetic', () async { | 143 test('compiler by default is hermetic', () async { |
| 142 var errors = []; | 144 var errors = []; |
| 143 var options = new CompilerOptions()..onError = (e) => errors.add(e); | 145 var options = new CompilerOptions()..onError = (e) => errors.add(e); |
| 144 var sources = { | 146 var sources = { |
| 145 'a.dart': 'import "b.dart"; a() => print("hi");', | 147 'a.dart': 'import "b.dart"; a() => print("hi");', |
| 146 'b.dart': '' | 148 'b.dart': '' |
| 147 }; | 149 }; |
| 148 await compileUnit(['a.dart'], sources, options: options); | 150 await compileUnit(['a.dart'], sources, options: options); |
| 149 expect(errors.first.toString(), contains('Invalid access')); | 151 expect(errors.first.message, contains('Invalid access')); |
| 150 errors.clear(); | 152 errors.clear(); |
| 151 | 153 |
| 152 await compileUnit(['a.dart', 'b.dart'], sources, options: options); | 154 await compileUnit(['a.dart', 'b.dart'], sources, options: options); |
| 153 expect(errors, isEmpty); | 155 expect(errors, isEmpty); |
| 154 }); | 156 }); |
| 155 | 157 |
| 156 test('chaseDependencies=true removes hermetic restriction', () async { | 158 test('chaseDependencies=true removes hermetic restriction', () async { |
| 157 var errors = []; | 159 var errors = []; |
| 158 var options = new CompilerOptions() | 160 var options = new CompilerOptions() |
| 159 ..chaseDependencies = true | 161 ..chaseDependencies = true |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 checkDCallsC(unitD1); | 203 checkDCallsC(unitD1); |
| 202 | 204 |
| 203 var unitD2 = await compileUnit(['d.dart'], sources, | 205 var unitD2 = await compileUnit(['d.dart'], sources, |
| 204 inputSummaries: ['bc.dill', 'a.dill']); | 206 inputSummaries: ['bc.dill', 'a.dill']); |
| 205 checkDCallsC(unitD2); | 207 checkDCallsC(unitD2); |
| 206 }); | 208 }); |
| 207 | 209 |
| 208 // TODO(sigmund): add tests with trimming dependencies | 210 // TODO(sigmund): add tests with trimming dependencies |
| 209 }); | 211 }); |
| 210 } | 212 } |
| OLD | NEW |