Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: pkg/front_end/test/kernel_generator_test.dart

Issue 2979623002: Use messages for (some) public API errors (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 expect(errors.first.message, contains("No 'main' method found"));
Paul Berry 2017/07/11 16:00:59 Would it be possible to change these test assertio
Siggi Cherem (dart-lang) 2017/07/12 00:29:46 In the future, yes, right now we don't expose the
60 }); 60 });
61 61
62 test('default error handler throws', () async { 62 test('default error handler throws', () async {
63 var exceptionThrown = false; 63 var exceptionThrown = false;
64 try { 64 try {
65 await compileScript('a() => print("hi");'); 65 await compileScript('a() => print("hi");');
66 } catch (e) { 66 } on CompilationError catch (e) {
67 exceptionThrown = true; 67 exceptionThrown = true;
68 expect('$e', contains("No 'main' method found")); 68 expect(e.message, contains("No 'main' method found"));
69 } 69 }
70 expect(exceptionThrown, isTrue); 70 expect(exceptionThrown, isTrue);
71 }); 71 });
72 72
73 test('generated program contains source-info', () async { 73 test('generated program contains source-info', () async {
74 var program = await compileScript('a() => print("hi"); main() {}', 74 var program = await compileScript('a() => print("hi"); main() {}',
75 fileName: 'a.dart'); 75 fileName: 'a.dart');
76 // Kernel always store an empty '' key in the map, so there is always at 76 // 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. 77 // least one. Having more means that source-info is added.
78 expect(program.uriToSource.keys.length, greaterThan(1)); 78 expect(program.uriToSource.keys.length, greaterThan(1));
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 }); 139 });
140 140
141 test('compiler by default is hermetic', () async { 141 test('compiler by default is hermetic', () async {
142 var errors = []; 142 var errors = [];
143 var options = new CompilerOptions()..onError = (e) => errors.add(e); 143 var options = new CompilerOptions()..onError = (e) => errors.add(e);
144 var sources = { 144 var sources = {
145 'a.dart': 'import "b.dart"; a() => print("hi");', 145 'a.dart': 'import "b.dart"; a() => print("hi");',
146 'b.dart': '' 146 'b.dart': ''
147 }; 147 };
148 await compileUnit(['a.dart'], sources, options: options); 148 await compileUnit(['a.dart'], sources, options: options);
149 expect(errors.first.toString(), contains('Invalid access')); 149 expect(errors.first.message, contains('Invalid access'));
150 errors.clear(); 150 errors.clear();
151 151
152 await compileUnit(['a.dart', 'b.dart'], sources, options: options); 152 await compileUnit(['a.dart', 'b.dart'], sources, options: options);
153 expect(errors, isEmpty); 153 expect(errors, isEmpty);
154 }); 154 });
155 155
156 test('chaseDependencies=true removes hermetic restriction', () async { 156 test('chaseDependencies=true removes hermetic restriction', () async {
157 var errors = []; 157 var errors = [];
158 var options = new CompilerOptions() 158 var options = new CompilerOptions()
159 ..chaseDependencies = true 159 ..chaseDependencies = true
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 checkDCallsC(unitD1); 201 checkDCallsC(unitD1);
202 202
203 var unitD2 = await compileUnit(['d.dart'], sources, 203 var unitD2 = await compileUnit(['d.dart'], sources,
204 inputSummaries: ['bc.dill', 'a.dill']); 204 inputSummaries: ['bc.dill', 'a.dill']);
205 checkDCallsC(unitD2); 205 checkDCallsC(unitD2);
206 }); 206 });
207 207
208 // TODO(sigmund): add tests with trimming dependencies 208 // TODO(sigmund): add tests with trimming dependencies
209 }); 209 });
210 } 210 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698