| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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 of "recursive" imports using the dart2js compiler API. | 5 // Test of "recursive" imports using the dart2js compiler API. |
| 6 | 6 |
| 7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import '../../sdk/lib/_internal/compiler/compiler.dart'; | 9 import '../../sdk/lib/_internal/compiler/compiler.dart'; |
| 10 import 'dart:uri'; | 10 import 'dart:uri'; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 const String RECURSIVE_MAIN = """ | 54 const String RECURSIVE_MAIN = """ |
| 55 library fisk; | 55 library fisk; |
| 56 import 'recurse/fisk.dart'; | 56 import 'recurse/fisk.dart'; |
| 57 main() {} | 57 main() {} |
| 58 """; | 58 """; |
| 59 | 59 |
| 60 | 60 |
| 61 main() { | 61 main() { |
| 62 int count = 0; | 62 int count = 0; |
| 63 Future<String> provider(Uri uri) { | 63 Future<String> provider(Uri uri) { |
| 64 Completer<String> completer = new Completer<String>(); | |
| 65 String source; | 64 String source; |
| 66 if (uri.path.length > 100) { | 65 if (uri.path.length > 100) { |
| 67 // Simulate an OS error. | 66 // Simulate an OS error. |
| 68 throw 'Path length exceeded'; | 67 throw 'Path length exceeded'; |
| 69 } else if (uri.scheme == "main") { | 68 } else if (uri.scheme == "main") { |
| 70 count++; | 69 count++; |
| 71 source = RECURSIVE_MAIN; | 70 source = RECURSIVE_MAIN; |
| 72 } else if (uri.scheme == "lib") { | 71 } else if (uri.scheme == "lib") { |
| 73 if (uri.path.endsWith("/core.dart")) { | 72 if (uri.path.endsWith("/core.dart")) { |
| 74 source = CORE_LIB; | 73 source = CORE_LIB; |
| 75 } else if (uri.path.endsWith('_patch.dart')) { | 74 } else if (uri.path.endsWith('_patch.dart')) { |
| 76 source = ''; | 75 source = ''; |
| 77 } else if (uri.path.endsWith('isolate_helper.dart')) { | 76 } else if (uri.path.endsWith('isolate_helper.dart')) { |
| 78 source = 'class _WorkerStub {}'; | 77 source = 'class _WorkerStub {}'; |
| 79 } else if (uri.path.endsWith('interceptors.dart')) { | 78 } else if (uri.path.endsWith('interceptors.dart')) { |
| 80 source = INTERCEPTORS_LIB; | 79 source = INTERCEPTORS_LIB; |
| 81 } else { | 80 } else { |
| 82 source = "library lib${uri.path.replaceAll('/', '.')};"; | 81 source = "library lib${uri.path.replaceAll('/', '.')};"; |
| 83 } | 82 } |
| 84 } else { | 83 } else { |
| 85 throw "unexpected URI $uri"; | 84 throw "unexpected URI $uri"; |
| 86 } | 85 } |
| 87 completer.complete(source); | 86 return new Future.value(source); |
| 88 return completer.future; | |
| 89 } | 87 } |
| 90 | 88 |
| 91 int warningCount = 0; | 89 int warningCount = 0; |
| 92 int errorCount = 0; | 90 int errorCount = 0; |
| 93 void handler(Uri uri, int begin, int end, String message, Diagnostic kind) { | 91 void handler(Uri uri, int begin, int end, String message, Diagnostic kind) { |
| 94 if (uri != null) { | 92 if (uri != null) { |
| 95 // print('$uri:$begin:$end: $kind: $message'); | 93 // print('$uri:$begin:$end: $kind: $message'); |
| 96 Expect.equals('main', uri.scheme); | 94 Expect.equals('main', uri.scheme); |
| 97 if (kind == Diagnostic.WARNING) { | 95 if (kind == Diagnostic.WARNING) { |
| 98 warningCount++; | 96 warningCount++; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 113 Expect.isNull(code); | 111 Expect.isNull(code); |
| 114 Expect.isTrue(10 < count); | 112 Expect.isTrue(10 < count); |
| 115 // Two warnings for each time RECURSIVE_MAIN is read, except the | 113 // Two warnings for each time RECURSIVE_MAIN is read, except the |
| 116 // first time. | 114 // first time. |
| 117 Expect.equals(2 * (count - 1), warningCount); | 115 Expect.equals(2 * (count - 1), warningCount); |
| 118 Expect.equals(1, errorCount); | 116 Expect.equals(1, errorCount); |
| 119 }, onError: (e) { | 117 }, onError: (e) { |
| 120 throw 'Compilation failed'; | 118 throw 'Compilation failed'; |
| 121 }); | 119 }); |
| 122 } | 120 } |
| OLD | NEW |