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 "package:async_helper/async_helper.dart"; |
8 import 'dart:async'; | 9 import 'dart:async'; |
9 import '../../sdk/lib/_internal/compiler/compiler.dart'; | 10 import '../../sdk/lib/_internal/compiler/compiler.dart'; |
10 | 11 |
11 const CORE_LIB = """ | 12 const CORE_LIB = """ |
12 library core; | 13 library core; |
13 class Object { | 14 class Object { |
14 Object(); | 15 Object(); |
15 operator==(other) {} | 16 operator==(other) {} |
16 } | 17 } |
17 class bool {} | 18 class bool {} |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 } else if (uri.path.endsWith('_patch.dart')) { | 84 } else if (uri.path.endsWith('_patch.dart')) { |
84 source = ''; | 85 source = ''; |
85 } else if (uri.path.endsWith('isolate_helper.dart')) { | 86 } else if (uri.path.endsWith('isolate_helper.dart')) { |
86 source = 'class _WorkerStub {}'; | 87 source = 'class _WorkerStub {}'; |
87 } else if (uri.path.endsWith('interceptors.dart')) { | 88 } else if (uri.path.endsWith('interceptors.dart')) { |
88 source = INTERCEPTORS_LIB; | 89 source = INTERCEPTORS_LIB; |
89 } else { | 90 } else { |
90 source = "library lib${uri.path.replaceAll('/', '.')};"; | 91 source = "library lib${uri.path.replaceAll('/', '.')};"; |
91 } | 92 } |
92 } else { | 93 } else { |
93 throw "unexpected URI $uri"; | 94 return new Future.error("unexpected URI $uri"); |
94 } | 95 } |
95 return new Future.value(source); | 96 return new Future.value(source); |
96 } | 97 } |
97 | 98 |
98 int warningCount = 0; | 99 int warningCount = 0; |
99 int errorCount = 0; | 100 int errorCount = 0; |
100 void handler(Uri uri, int begin, int end, String message, Diagnostic kind) { | 101 void handler(Uri uri, int begin, int end, String message, Diagnostic kind) { |
101 if (uri != null) { | 102 if (uri != null) { |
102 // print('$uri:$begin:$end: $kind: $message'); | 103 // print('$uri:$begin:$end: $kind: $message'); |
103 Expect.equals('main', uri.scheme); | 104 Expect.equals('main', uri.scheme); |
104 if (kind == Diagnostic.WARNING) { | 105 if (kind == Diagnostic.WARNING) { |
105 warningCount++; | 106 warningCount++; |
106 } else if (kind == Diagnostic.ERROR) { | 107 } else if (kind == Diagnostic.ERROR) { |
107 errorCount++; | 108 errorCount++; |
108 } else { | 109 } else { |
109 throw kind; | 110 throw kind; |
110 } | 111 } |
111 } | 112 } |
112 } | 113 } |
113 | 114 |
| 115 asyncStart(); |
114 Future<String> result = | 116 Future<String> result = |
115 compile(new Uri(scheme: 'main'), | 117 compile(new Uri(scheme: 'main'), |
116 new Uri(scheme: 'lib', path: '/'), | 118 new Uri(scheme: 'lib', path: '/'), |
117 new Uri(scheme: 'package', path: '/'), | 119 new Uri(scheme: 'package', path: '/'), |
118 provider, handler); | 120 provider, handler); |
119 result.then((String code) { | 121 result.then((String code) { |
120 Expect.isNull(code); | 122 Expect.isNull(code); |
121 Expect.isTrue(10 < count); | 123 Expect.isTrue(10 < count); |
122 // Two warnings for each time RECURSIVE_MAIN is read, except the | 124 // Two warnings for each time RECURSIVE_MAIN is read, except the |
123 // first time. | 125 // first time. |
124 Expect.equals(2 * (count - 1), warningCount); | 126 Expect.equals(2 * (count - 1), warningCount); |
125 Expect.equals(1, errorCount); | 127 Expect.equals(1, errorCount); |
126 }, onError: (e) { | 128 }, onError: (e) { |
127 throw 'Compilation failed'; | 129 throw 'Compilation failed'; |
128 }); | 130 }).whenComplete(() => asyncEnd()); |
129 } | 131 } |
OLD | NEW |