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.package_root; | 7 library dart2js.test.package_root; |
8 | 8 |
9 import 'dart:async'; | 9 import 'dart:async'; |
10 | 10 |
11 import 'package:async_helper/async_helper.dart'; | 11 import 'package:async_helper/async_helper.dart'; |
12 import 'package:expect/expect.dart'; | 12 import 'package:expect/expect.dart'; |
13 import 'package:compiler/compiler.dart' | 13 import 'package:compiler/compiler.dart' |
14 show DiagnosticHandler, Diagnostic, PackagesDiscoveryProvider; | 14 show DiagnosticHandler, Diagnostic, PackagesDiscoveryProvider; |
15 import 'package:compiler/src/diagnostics/messages.dart' | 15 import 'package:compiler/src/diagnostics/messages.dart' show MessageKind; |
16 show MessageKind; | |
17 import 'package:package_config/packages.dart'; | 16 import 'package:package_config/packages.dart'; |
18 | 17 |
19 import 'memory_compiler.dart'; | 18 import 'memory_compiler.dart'; |
20 import 'memory_source_file_helper.dart'; | 19 import 'memory_source_file_helper.dart'; |
21 | 20 |
22 const MEMORY_SOURCE_FILES = const { | 21 const MEMORY_SOURCE_FILES = const { |
23 'main.dart': ''' | 22 'main.dart': ''' |
24 | 23 |
25 import 'package:foo/foo.dart'; | 24 import 'package:foo/foo.dart'; |
26 | 25 |
27 main() {} | 26 main() {} |
28 ''', | 27 ''', |
29 'package.config': ''' | 28 'package.config': ''' |
30 ''', | 29 ''', |
31 }; | 30 }; |
32 | 31 |
33 final Uri PACKAGE_CONFIG_URI = Uri.parse('memory:package.config'); | 32 final Uri PACKAGE_CONFIG_URI = Uri.parse('memory:package.config'); |
34 | 33 |
35 Future runTest(Uri main, | 34 Future runTest(Uri main, MessageKind expectedMessageKind, |
36 MessageKind expectedMessageKind, | 35 {Uri packageRoot, |
37 {Uri packageRoot, | 36 Uri packageConfig, |
38 Uri packageConfig, | 37 PackagesDiscoveryProvider packagesDiscoveryProvider}) async { |
39 PackagesDiscoveryProvider packagesDiscoveryProvider}) async { | |
40 DiagnosticCollector collector = new DiagnosticCollector(); | 38 DiagnosticCollector collector = new DiagnosticCollector(); |
41 await runCompiler( | 39 await runCompiler( |
42 entryPoint: main, | 40 entryPoint: main, |
43 memorySourceFiles: MEMORY_SOURCE_FILES, | 41 memorySourceFiles: MEMORY_SOURCE_FILES, |
44 diagnosticHandler: collector, | 42 diagnosticHandler: collector, |
45 packageRoot: packageRoot, | 43 packageRoot: packageRoot, |
46 packageConfig: packageConfig, | 44 packageConfig: packageConfig, |
47 packagesDiscoveryProvider: packagesDiscoveryProvider); | 45 packagesDiscoveryProvider: packagesDiscoveryProvider); |
48 Expect.equals(1, collector.errors.length, | 46 Expect.equals( |
49 "Unexpected errors: ${collector.errors}"); | 47 1, collector.errors.length, "Unexpected errors: ${collector.errors}"); |
50 Expect.equals(expectedMessageKind, collector.errors.first.message.kind, | 48 Expect.equals(expectedMessageKind, collector.errors.first.message.kind, |
51 "Unexpected error: ${collector.errors.first}"); | 49 "Unexpected error: ${collector.errors.first}"); |
52 } | 50 } |
53 | 51 |
54 void main() { | 52 void main() { |
55 asyncTest(() async { | 53 asyncTest(() async { |
56 Uri script = currentDirectory.resolveUri(Platform.script); | 54 Uri script = currentDirectory.resolveUri(Platform.script); |
57 Uri packageRoot = script.resolve('./packages/'); | 55 Uri packageRoot = script.resolve('./packages/'); |
58 | 56 |
59 PackagesDiscoveryProvider noPackagesDiscovery = (Uri uri) { | 57 PackagesDiscoveryProvider noPackagesDiscovery = (Uri uri) { |
60 return new Future.value(Packages.noPackages); | 58 return new Future.value(Packages.noPackages); |
61 }; | 59 }; |
62 | 60 |
63 await runTest( | 61 await runTest(Uri.parse('memory:main.dart'), MessageKind.READ_SCRIPT_ERROR, |
64 Uri.parse('memory:main.dart'), | |
65 MessageKind.READ_SCRIPT_ERROR, | |
66 packageRoot: packageRoot); | 62 packageRoot: packageRoot); |
67 await runTest( | 63 await runTest(Uri.parse('memory:main.dart'), MessageKind.LIBRARY_NOT_FOUND, |
68 Uri.parse('memory:main.dart'), | |
69 MessageKind.LIBRARY_NOT_FOUND, | |
70 packageConfig: PACKAGE_CONFIG_URI); | 64 packageConfig: PACKAGE_CONFIG_URI); |
71 await runTest( | 65 await runTest(Uri.parse('memory:main.dart'), MessageKind.LIBRARY_NOT_FOUND, |
72 Uri.parse('memory:main.dart'), | |
73 MessageKind.LIBRARY_NOT_FOUND, | |
74 packagesDiscoveryProvider: noPackagesDiscovery); | 66 packagesDiscoveryProvider: noPackagesDiscovery); |
75 | 67 |
76 await runTest( | 68 await runTest( |
77 Uri.parse('package:foo/foo.dart'), | 69 Uri.parse('package:foo/foo.dart'), MessageKind.READ_SELF_ERROR, |
78 MessageKind.READ_SELF_ERROR, | |
79 packageRoot: packageRoot); | 70 packageRoot: packageRoot); |
80 await runTest( | 71 await runTest( |
81 Uri.parse('package:foo/foo.dart'), | 72 Uri.parse('package:foo/foo.dart'), MessageKind.LIBRARY_NOT_FOUND, |
82 MessageKind.LIBRARY_NOT_FOUND, | |
83 packageConfig: PACKAGE_CONFIG_URI); | 73 packageConfig: PACKAGE_CONFIG_URI); |
84 await runTest( | 74 await runTest( |
85 Uri.parse('package:foo/foo.dart'), | 75 Uri.parse('package:foo/foo.dart'), MessageKind.LIBRARY_NOT_FOUND, |
86 MessageKind.LIBRARY_NOT_FOUND, | |
87 packagesDiscoveryProvider: noPackagesDiscovery); | 76 packagesDiscoveryProvider: noPackagesDiscovery); |
88 }); | 77 }); |
89 } | 78 } |
OLD | NEW |