| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 // Test of "recursive" imports using the dart2js compiler API. | |
| 6 | |
| 7 import "package:expect/expect.dart"; | |
| 8 import "package:async_helper/async_helper.dart"; | |
| 9 import 'dart:async'; | |
| 10 import 'dummy_compiler_test.dart'; | |
| 11 import 'package:compiler/compiler.dart'; | |
| 12 | |
| 13 const String RECURSIVE_MAIN = """ | |
| 14 library fisk; | |
| 15 import 'recurse/fisk.dart'; | |
| 16 main() {} | |
| 17 """; | |
| 18 | |
| 19 main() { | |
| 20 int count = 0; | |
| 21 Future<String> provider(Uri uri) { | |
| 22 String source; | |
| 23 if (uri.path.length > 100) { | |
| 24 // Simulate an OS error. | |
| 25 throw 'Path length exceeded'; | |
| 26 } else if (uri.scheme == "main") { | |
| 27 count++; | |
| 28 source = RECURSIVE_MAIN; | |
| 29 } else if (uri.scheme == "lib") { | |
| 30 source = libProvider(uri); | |
| 31 } else { | |
| 32 return new Future.error("unexpected URI $uri"); | |
| 33 } | |
| 34 return new Future.value(source); | |
| 35 } | |
| 36 | |
| 37 int warningCount = 0; | |
| 38 int errorCount = 0; | |
| 39 void handler(Uri uri, int begin, int end, String message, Diagnostic kind) { | |
| 40 if (uri != null) { | |
| 41 print('$uri:$begin:$end: $kind: $message'); | |
| 42 Expect.equals('main', uri.scheme); | |
| 43 if (kind == Diagnostic.WARNING) { | |
| 44 warningCount++; | |
| 45 } else if (kind == Diagnostic.ERROR) { | |
| 46 errorCount++; | |
| 47 } else { | |
| 48 throw kind; | |
| 49 } | |
| 50 } else { | |
| 51 print('$kind: $message'); | |
| 52 } | |
| 53 } | |
| 54 | |
| 55 asyncStart(); | |
| 56 Future<CompilationResult> result = compile( | |
| 57 new Uri(scheme: 'main'), | |
| 58 new Uri(scheme: 'lib', path: '/'), | |
| 59 new Uri(scheme: 'package', path: '/'), | |
| 60 provider, | |
| 61 handler); | |
| 62 result.then((CompilationResult result) { | |
| 63 Expect.isFalse(result.isSuccess); | |
| 64 Expect.isTrue(10 < count); | |
| 65 // Two warnings for each time RECURSIVE_MAIN is read, except the | |
| 66 // first time. | |
| 67 Expect.equals(2 * (count - 1), warningCount); | |
| 68 Expect.equals(1, errorCount); | |
| 69 }, onError: (e, s) { | |
| 70 throw 'Compilation failed: $e\n$s'; | |
| 71 }).then(asyncSuccess); | |
| 72 } | |
| OLD | NEW |