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

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

Issue 588183002: Emit warning on import of dart:mirrors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments Created 6 years, 1 month 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 // Test that the compiler emits a warning on import of 'dart:mirrors' unless
6 // the flag --enable-experimental-mirrors is used.
7
8 library dart2js.test.import;
9
10 import 'package:expect/expect.dart';
11 import 'package:async_helper/async_helper.dart';
12 import 'package:compiler/src/dart2jslib.dart' show MessageKind;
13 import 'memory_compiler.dart';
14
15 const DIRECT_IMPORT = const {
16 '/main.dart': '''
17 import 'dart:mirrors';
18
19 main() {}
20 ''',
21
22 'paths':
23 "main.dart => dart:mirrors",
24 };
25
26 const INDIRECT_IMPORT1 = const {
27 '/main.dart': '''
28 import 'first.dart';
29
30 main() {}
31 ''',
32 '/first.dart': '''
33 import 'dart:mirrors';
34 ''',
35
36 'paths':
37 "first.dart => dart:mirrors",
38 'verbosePaths':
39 "main.dart => first.dart => dart:mirrors",
40 };
41
42 const INDIRECT_IMPORT2 = const {
43 '/main.dart': '''
44 import 'first.dart';
45
46 main() {}
47 ''',
48 '/first.dart': '''
49 import 'second.dart';
50 ''',
51 '/second.dart': '''
52 import 'dart:mirrors';
53 ''',
54
55 'paths':
56 "second.dart => dart:mirrors",
57 'verbosePaths':
58 "main.dart => first.dart => second.dart => dart:mirrors",
59 };
60
61 const INDIRECT_PACKAGE_IMPORT1 = const {
62 '/main.dart': '''
63 import 'first.dart';
64
65 main() {}
66 ''',
67 '/first.dart': '''
68 import 'package:second.dart';
69 ''',
70 '/pkg/second.dart': '''
71 import 'dart:mirrors';
72 ''',
73
74 'paths':
75 "first.dart => package:second.dart => dart:mirrors",
76 'verbosePaths':
77 "main.dart => first.dart => package:second.dart => dart:mirrors",
78 };
79
80 const INDIRECT_PACKAGE_IMPORT2 = const {
81 '/main.dart': '''
82 import 'first.dart';
83
84 main() {}
85 ''',
86 '/first.dart': '''
87 import 'package:package-name/second.dart';
88 ''',
89 '/pkg/package-name/second.dart': '''
90 import 'dart:mirrors';
91 ''',
92
93 'paths':
94 "first.dart => package:package-name => dart:mirrors",
95 'verbosePaths':
96 "main.dart => first.dart => package:package-name/second.dart "
97 "=> dart:mirrors",
98 };
99
100 const INDIRECT_PACKAGE_IMPORT3 = const {
101 '/main.dart': '''
102 import 'first.dart';
103
104 main() {}
105 ''',
106 '/first.dart': '''
107 import 'package:package1/second.dart';
108 ''',
109 '/pkg/package1/second.dart': '''
110 import 'package:package2/third.dart';
111 ''',
112 '/pkg/package2/third.dart': '''
113 import 'dart:mirrors';
114 ''',
115
116 'paths':
117 "first.dart => package:package1 => package:package2 => dart:mirrors",
118 'verbosePaths':
119 "main.dart => first.dart => package:package1/second.dart "
120 "=> package:package2/third.dart => dart:mirrors",
121 };
122
123 const INDIRECT_PACKAGE_IMPORT4 = const {
124 '/main.dart': '''
125 import 'first.dart';
126
127 main() {}
128 ''',
129 '/first.dart': '''
130 import 'package:package1/second.dart';
131 ''',
132 '/pkg/package1/second.dart': '''
133 import 'sub/third.dart';
134 ''',
135 '/pkg/package1/sub/third.dart': '''
136 import 'package:package2/fourth.dart';
137 ''',
138 '/pkg/package2/fourth.dart': '''
139 import 'lib/src/fifth.dart';
140 ''',
141 '/pkg/package2/lib/src/fifth.dart': '''
142 import 'dart:mirrors';
143 ''',
144
145 'paths':
146 "first.dart => package:package1 => package:package2 => dart:mirrors",
147 'verbosePaths':
148 "main.dart => first.dart => package:package1/second.dart "
149 "=> package:package1/sub/third.dart => package:package2/fourth.dart "
150 "=> package:package2/lib/src/fifth.dart => dart:mirrors",
151 };
152
153 const DUAL_DIRECT_IMPORT = const {
154 '/main.dart': '''
155 import 'dart:mirrors';
156 import 'dart:mirrors';
157
158 main() {}
159 ''',
160
161 'paths':
162 "main.dart => dart:mirrors",
163 };
164
165 const DUAL_INDIRECT_IMPORT1 = const {
166 '/main.dart': '''
167 import 'dart:mirrors';
168 import 'first.dart';
169
170 main() {}
171 ''',
172 '/first.dart': '''
173 import 'dart:mirrors';
174 ''',
175
176 'paths': const
177 ["main.dart => dart:mirrors",
178 "first.dart => dart:mirrors"],
179 'verbosePaths': const
180 ["main.dart => dart:mirrors",
181 "main.dart => first.dart => dart:mirrors"],
182 };
183
184 const DUAL_INDIRECT_IMPORT2 = const {
185 '/main.dart': '''
186 import 'first.dart';
187 import 'second.dart';
188
189 main() {}
190 ''',
191 '/first.dart': '''
192 import 'dart:mirrors';
193 ''',
194 '/second.dart': '''
195 import 'dart:mirrors';
196 ''',
197
198 'paths': const
199 ["first.dart => dart:mirrors",
200 "second.dart => dart:mirrors"],
201 'verbosePaths': const
202 ["main.dart => first.dart => dart:mirrors",
203 "main.dart => second.dart => dart:mirrors"],
204 };
205
206 const DUAL_INDIRECT_IMPORT3 = const {
207 '/main.dart': '''
208 import 'first.dart';
209 import 'second.dart';
210
211 main() {}
212 ''',
213 '/first.dart': '''
214 import 'third.dart';
215 ''',
216 '/second.dart': '''
217 import 'third.dart';
218 ''',
219 '/third.dart': '''
220 import 'dart:mirrors';
221 ''',
222
223 'paths':
224 "third.dart => dart:mirrors",
225 'verbosePaths': const
226 ["main.dart => first.dart => third.dart => dart:mirrors",
227 "main.dart => second.dart => third.dart => dart:mirrors"],
228 };
229
230 const DUAL_INDIRECT_PACKAGE_IMPORT1 = const {
231 '/main.dart': '''
232 import 'package:package1/second.dart';
233 import 'first.dart';
234
235 main() {}
236 ''',
237 '/first.dart': '''
238 import 'package:package2/third.dart';
239 ''',
240 '/pkg/package1/second.dart': '''
241 import 'dart:mirrors';
242 ''',
243 '/pkg/package2/third.dart': '''
244 import 'dart:mirrors';
245 ''',
246
247 'paths': const
248 ["main.dart => package:package1 => dart:mirrors",
249 "first.dart => package:package2 => dart:mirrors"],
250 'verbosePaths': const
251 ["main.dart => package:package1/second.dart => dart:mirrors",
252 "main.dart => first.dart => package:package2/third.dart => dart:mirrors"]
253 };
254
255
256 test(Map sourceFiles,
257 {expectedPaths,
258 bool verbose: false,
259 bool enableExperimentalMirrors: false}) {
260 if (expectedPaths is! List) {
261 expectedPaths = [expectedPaths];
262 }
263 var collector = new DiagnosticCollector();
264 var options = [];
265 if (verbose) {
266 options.add('--verbose');
267 }
268 if (enableExperimentalMirrors) {
269 options.add('--enable-experimental-mirrors');
270 }
271 var compiler = compilerFor(sourceFiles, diagnosticHandler: collector,
272 packageRoot: Uri.parse('memory:/pkg/'),
273 options: options);
274 asyncTest(() => compiler.run(Uri.parse('memory:/main.dart')).then((_) {
275 Expect.equals(0, collector.errors.length, 'Errors: ${collector.errors}');
276 if (enableExperimentalMirrors) {
277 Expect.equals(0, collector.warnings.length,
278 'Warnings: ${collector.errors}');
279 } else {
280 Expect.equals(1, collector.warnings.length,
281 'Warnings: ${collector.errors}');
282 Expect.equals(
283 MessageKind.IMPORT_EXPERIMENTAL_MIRRORS.message(
284 {'importChain': expectedPaths.join(
285 MessageKind.IMPORT_EXPERIMENTAL_MIRRORS_PADDING)}).toString(),
286 collector.warnings.first.message);
287 }
288 }));
289 }
290
291 checkPaths(Map sourceData) {
292 Map sourceFiles = sourceData;
293 var expectedPaths = sourceData['paths'];
294 var expectedVerbosePaths = sourceData['verbosePaths'];
295 if (expectedVerbosePaths == null) {
296 expectedVerbosePaths = expectedPaths;
297 }
298 test(sourceFiles, expectedPaths: expectedPaths);
299 test(sourceFiles, expectedPaths: expectedVerbosePaths, verbose: true);
300 test(sourceFiles, enableExperimentalMirrors: true);
301 }
302
303 void main() {
304 checkPaths(DIRECT_IMPORT);
305 checkPaths(INDIRECT_IMPORT1);
306 checkPaths(INDIRECT_IMPORT2);
307 checkPaths(INDIRECT_PACKAGE_IMPORT1);
308 checkPaths(INDIRECT_PACKAGE_IMPORT2);
309 checkPaths(INDIRECT_PACKAGE_IMPORT3);
310 checkPaths(INDIRECT_PACKAGE_IMPORT4);
311 checkPaths(DUAL_DIRECT_IMPORT);
312 checkPaths(DUAL_INDIRECT_IMPORT1);
313 checkPaths(DUAL_INDIRECT_IMPORT2);
314 checkPaths(DUAL_INDIRECT_IMPORT3);
315 checkPaths(DUAL_INDIRECT_PACKAGE_IMPORT1);
316 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698