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

Side by Side Diff: tests/compiler/dart2js/import_mirrors_test.dart

Issue 793653003: Display exports that lead to dart:mirrors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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 | Annotate | Revision Log
« no previous file with comments | « pkg/compiler/lib/src/library_loader.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 // Test that the compiler emits a warning on import of 'dart:mirrors' unless 5 // Test that the compiler emits a warning on import of 'dart:mirrors' unless
6 // the flag --enable-experimental-mirrors is used. 6 // the flag --enable-experimental-mirrors is used.
7 7
8 library dart2js.test.import; 8 library dart2js.test.import;
9 9
10 import 'dart:async';
10 import 'package:expect/expect.dart'; 11 import 'package:expect/expect.dart';
11 import 'package:async_helper/async_helper.dart'; 12 import 'package:async_helper/async_helper.dart';
12 import 'package:compiler/src/dart2jslib.dart' show MessageKind; 13 import 'package:compiler/src/dart2jslib.dart' show MessageKind;
13 import 'memory_compiler.dart'; 14 import 'memory_compiler.dart';
14 15
15 const DIRECT_IMPORT = const { 16 const DIRECT_IMPORT = const {
16 '/main.dart': ''' 17 '/main.dart': '''
17 import 'dart:mirrors'; 18 import 'dart:mirrors';
18 19
19 main() {} 20 main() {}
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 ''', 246 ''',
246 247
247 'paths': const 248 'paths': const
248 ["main.dart => package:package1 => dart:mirrors", 249 ["main.dart => package:package1 => dart:mirrors",
249 "first.dart => package:package2 => dart:mirrors"], 250 "first.dart => package:package2 => dart:mirrors"],
250 'verbosePaths': const 251 'verbosePaths': const
251 ["main.dart => package:package1/second.dart => dart:mirrors", 252 ["main.dart => package:package1/second.dart => dart:mirrors",
252 "main.dart => first.dart => package:package2/third.dart => dart:mirrors"] 253 "main.dart => first.dart => package:package2/third.dart => dart:mirrors"]
253 }; 254 };
254 255
256 const DIRECT_EXPORT = const {
257 '/main.dart': '''
258 export 'dart:mirrors';
255 259
256 test(Map sourceFiles, 260 main() {}
257 {expectedPaths, 261 ''',
258 bool verbose: false, 262
259 bool enableExperimentalMirrors: false}) { 263 'paths':
264 "main.dart => dart:mirrors",
265 };
266
267 const INDIRECT_EXPORT1 = const {
268 '/main.dart': '''
269 import 'first.dart';
270
271 main() {}
272 ''',
273 '/first.dart': '''
274 export 'dart:mirrors';
275 ''',
276
277 'paths':
278 "first.dart => dart:mirrors",
279 'verbosePaths':
280 "main.dart => first.dart => dart:mirrors",
281 };
282
283 const INDIRECT_EXPORT2 = const {
284 '/main.dart': '''
285 import 'first.dart';
286
287 main() {}
288 ''',
289 '/first.dart': '''
290 import 'second.dart';
291 ''',
292 '/second.dart': '''
293 export 'dart:mirrors';
294 ''',
295
296 'paths':
297 "second.dart => dart:mirrors",
298 'verbosePaths':
299 "main.dart => first.dart => second.dart => dart:mirrors",
300 };
301
302 const INDIRECT_PACKAGE_EXPORT1 = const {
303 '/main.dart': '''
304 import 'first.dart';
305
306 main() {}
307 ''',
308 '/first.dart': '''
309 import 'package:package-name/second.dart';
310 ''',
311 '/pkg/package-name/second.dart': '''
312 export 'dart:mirrors';
313 ''',
314
315 'paths':
316 "first.dart => package:package-name => dart:mirrors",
317 'verbosePaths':
318 "main.dart => first.dart => package:package-name/second.dart "
319 "=> dart:mirrors",
320 };
321
322 const INDIRECT_PACKAGE_EXPORT2 = const {
323 '/main.dart': '''
324 import 'first.dart';
325
326 main() {}
327 ''',
328 '/first.dart': '''
329 export 'package:package-name/second.dart';
330 ''',
331 '/pkg/package-name/second.dart': '''
332 import 'dart:mirrors';
333 ''',
334
335 'paths':
336 "first.dart => package:package-name => dart:mirrors",
337 'verbosePaths':
338 "main.dart => first.dart => package:package-name/second.dart "
339 "=> dart:mirrors",
340 };
341
342 Future test(Map sourceFiles,
343 {expectedPaths,
344 bool verbose: false,
345 bool enableExperimentalMirrors: false}) {
260 if (expectedPaths is! List) { 346 if (expectedPaths is! List) {
261 expectedPaths = [expectedPaths]; 347 expectedPaths = [expectedPaths];
262 } 348 }
263 var collector = new DiagnosticCollector(); 349 var collector = new DiagnosticCollector();
264 var options = []; 350 var options = [];
265 if (verbose) { 351 if (verbose) {
266 options.add('--verbose'); 352 options.add('--verbose');
267 } 353 }
268 if (enableExperimentalMirrors) { 354 if (enableExperimentalMirrors) {
269 options.add('--enable-experimental-mirrors'); 355 options.add('--enable-experimental-mirrors');
270 } 356 }
271 var compiler = compilerFor(sourceFiles, diagnosticHandler: collector, 357 var compiler = compilerFor(sourceFiles, diagnosticHandler: collector,
272 packageRoot: Uri.parse('memory:/pkg/'), 358 packageRoot: Uri.parse('memory:/pkg/'),
273 options: options); 359 options: options);
274 asyncTest(() => compiler.run(Uri.parse('memory:/main.dart')).then((_) { 360 return compiler.run(Uri.parse('memory:/main.dart')).then((_) {
275 Expect.equals(0, collector.errors.length, 'Errors: ${collector.errors}'); 361 Expect.equals(0, collector.errors.length, 'Errors: ${collector.errors}');
276 if (enableExperimentalMirrors) { 362 if (enableExperimentalMirrors) {
277 Expect.equals(0, collector.warnings.length, 363 Expect.equals(0, collector.warnings.length,
278 'Warnings: ${collector.errors}'); 364 'Warnings: ${collector.errors}');
279 } else { 365 } else {
280 Expect.equals(1, collector.warnings.length, 366 Expect.equals(1, collector.warnings.length,
281 'Warnings: ${collector.errors}'); 367 'Warnings: ${collector.errors}');
282 Expect.equals( 368 Expect.equals(
283 MessageKind.IMPORT_EXPERIMENTAL_MIRRORS.message( 369 MessageKind.IMPORT_EXPERIMENTAL_MIRRORS.message(
284 {'importChain': expectedPaths.join( 370 {'importChain': expectedPaths.join(
285 MessageKind.IMPORT_EXPERIMENTAL_MIRRORS_PADDING)}).toString(), 371 MessageKind.IMPORT_EXPERIMENTAL_MIRRORS_PADDING)}).toString(),
286 collector.warnings.first.message); 372 collector.warnings.first.message);
287 } 373 }
288 })); 374 });
289 } 375 }
290 376
291 checkPaths(Map sourceData) { 377 Future checkPaths(Map sourceData) {
292 Map sourceFiles = sourceData; 378 Map sourceFiles = sourceData;
293 var expectedPaths = sourceData['paths']; 379 var expectedPaths = sourceData['paths'];
294 var expectedVerbosePaths = sourceData['verbosePaths']; 380 var expectedVerbosePaths = sourceData['verbosePaths'];
295 if (expectedVerbosePaths == null) { 381 if (expectedVerbosePaths == null) {
296 expectedVerbosePaths = expectedPaths; 382 expectedVerbosePaths = expectedPaths;
297 } 383 }
298 test(sourceFiles, expectedPaths: expectedPaths); 384 return test(sourceFiles, expectedPaths: expectedPaths).then((_) {
299 test(sourceFiles, expectedPaths: expectedVerbosePaths, verbose: true); 385 return test(
300 test(sourceFiles, enableExperimentalMirrors: true); 386 sourceFiles, expectedPaths: expectedVerbosePaths, verbose: true);
387 }).then((_) {
388 return test(sourceFiles, enableExperimentalMirrors: true);
389 });
301 } 390 }
302 391
303 void main() { 392 void main() {
304 checkPaths(DIRECT_IMPORT); 393 asyncTest(() => Future.forEach([
305 checkPaths(INDIRECT_IMPORT1); 394 DIRECT_IMPORT,
306 checkPaths(INDIRECT_IMPORT2); 395 INDIRECT_IMPORT1,
307 checkPaths(INDIRECT_PACKAGE_IMPORT1); 396 INDIRECT_IMPORT2,
308 checkPaths(INDIRECT_PACKAGE_IMPORT2); 397 INDIRECT_PACKAGE_IMPORT1,
309 checkPaths(INDIRECT_PACKAGE_IMPORT3); 398 INDIRECT_PACKAGE_IMPORT2,
310 checkPaths(INDIRECT_PACKAGE_IMPORT4); 399 INDIRECT_PACKAGE_IMPORT3,
311 checkPaths(DUAL_DIRECT_IMPORT); 400 INDIRECT_PACKAGE_IMPORT4,
312 checkPaths(DUAL_INDIRECT_IMPORT1); 401 DUAL_DIRECT_IMPORT,
313 checkPaths(DUAL_INDIRECT_IMPORT2); 402 DUAL_INDIRECT_IMPORT1,
314 checkPaths(DUAL_INDIRECT_IMPORT3); 403 DUAL_INDIRECT_IMPORT2,
315 checkPaths(DUAL_INDIRECT_PACKAGE_IMPORT1); 404 DUAL_INDIRECT_IMPORT3,
405 DUAL_INDIRECT_PACKAGE_IMPORT1,
406 DIRECT_EXPORT,
407 INDIRECT_EXPORT1,
408 INDIRECT_EXPORT2,
409 INDIRECT_PACKAGE_EXPORT1,
410 INDIRECT_PACKAGE_EXPORT2],
411 (map) => checkPaths(map)
412 ));
316 } 413 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/library_loader.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698