OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 can handle imports when package root has not been set. | 5 // Test that the compiler can handle imports when package root has not been set. |
6 | 6 |
7 library dart2js.test.missing_file; | 7 library dart2js.test.missing_file; |
8 | 8 |
9 import 'dart:async'; | 9 import 'dart:async'; |
10 import 'package:async_helper/async_helper.dart'; | 10 import 'package:async_helper/async_helper.dart'; |
11 import "package:compiler/src/diagnostics/messages.dart"; | 11 import "package:compiler/src/diagnostics/messages.dart"; |
12 import 'package:expect/expect.dart'; | 12 import 'package:expect/expect.dart'; |
13 import 'memory_compiler.dart'; | 13 import 'memory_compiler.dart'; |
14 | 14 |
15 const MEMORY_SOURCE_FILES = const { | 15 const MEMORY_SOURCE_FILES = const { |
16 'main.dart': ''' | 16 'main.dart': ''' |
| 17 import 'foo.dart'; |
| 18 main() {} |
| 19 ''', |
17 | 20 |
18 import 'foo.dart'; | 21 'bar.dart': ''' |
| 22 import 'dart:foo'; |
| 23 main() {} |
| 24 ''', |
19 | 25 |
| 26 'baz.dart': ''' |
| 27 import 'dart:io'; |
20 main() {} | 28 main() {} |
21 ''', | 29 ''', |
22 }; | 30 }; |
23 | 31 |
24 Future runTest(Uri main, MessageKind expectedMessageKind) async { | 32 Future runTest(Uri main, |
25 print("\n\n\n"); | 33 {MessageKind error, |
| 34 MessageKind info}) async { |
| 35 print("----\nentry-point: $main\n"); |
26 | 36 |
27 DiagnosticCollector diagnostics = new DiagnosticCollector(); | 37 DiagnosticCollector diagnostics = new DiagnosticCollector(); |
28 OutputCollector output = new OutputCollector(); | 38 OutputCollector output = new OutputCollector(); |
29 await runCompiler( | 39 await runCompiler( |
| 40 entryPoint: main, |
30 memorySourceFiles: MEMORY_SOURCE_FILES, | 41 memorySourceFiles: MEMORY_SOURCE_FILES, |
31 diagnosticHandler: diagnostics, | 42 diagnosticHandler: diagnostics, |
32 outputProvider: output); | 43 outputProvider: output); |
33 | 44 |
34 Expect.isFalse(output.hasExtraOutput); | 45 Expect.isFalse(output.hasExtraOutput); |
35 Expect.equals(1, diagnostics.errors.length); | 46 Expect.equals(error != null ? 1 : 0, diagnostics.errors.length); |
36 Expect.equals(expectedMessageKind, diagnostics.errors.first.message.kind); | 47 if (error != null) { |
| 48 Expect.equals(error, diagnostics.errors.first.message.kind); |
| 49 } |
| 50 Expect.equals(info != null ? 1 : 0, diagnostics.infos.length); |
| 51 if (info != null) { |
| 52 Expect.equals(info, diagnostics.infos.first.message.kind); |
| 53 } |
| 54 Expect.equals(0, diagnostics.warnings.length); |
| 55 Expect.equals(0, diagnostics.hints.length); |
37 } | 56 } |
38 | 57 |
39 void main() { | 58 void main() { |
40 asyncTest(() async { | 59 asyncTest(() async { |
41 await runTest( | 60 await runTest( |
42 Uri.parse('memory:main.dart'), MessageKind.READ_SCRIPT_ERROR); | 61 Uri.parse('memory:main.dart'), |
| 62 error: MessageKind.READ_SCRIPT_ERROR); |
| 63 |
43 await runTest( | 64 await runTest( |
44 Uri.parse('memory:foo.dart'), MessageKind.READ_SCRIPT_ERROR); | 65 Uri.parse('memory:foo.dart'), |
| 66 error: MessageKind.READ_SELF_ERROR); |
| 67 |
45 await runTest( | 68 await runTest( |
46 Uri.parse('dart:foo'), MessageKind.READ_SCRIPT_ERROR); | 69 Uri.parse('dart:foo'), |
| 70 error: MessageKind.LIBRARY_NOT_FOUND); |
| 71 |
| 72 await runTest( |
| 73 Uri.parse('dart:io'), |
| 74 error: MessageKind.LIBRARY_NOT_SUPPORTED, |
| 75 info: MessageKind.DISALLOWED_LIBRARY_IMPORT); |
| 76 |
| 77 await runTest( |
| 78 Uri.parse('memory:bar.dart'), |
| 79 error: MessageKind.LIBRARY_NOT_FOUND); |
| 80 |
| 81 await runTest( |
| 82 Uri.parse('memory:baz.dart'), |
| 83 error: MessageKind.LIBRARY_NOT_SUPPORTED, |
| 84 info: MessageKind.DISALLOWED_LIBRARY_IMPORT); |
47 }); | 85 }); |
48 } | 86 } |
OLD | NEW |