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.missing_file; |
8 | 8 |
9 import 'package:expect/expect.dart'; | 9 import 'package:expect/expect.dart'; |
10 import 'memory_source_file_helper.dart'; | 10 import 'memory_source_file_helper.dart'; |
11 | 11 |
12 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' | 12 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' |
13 show NullSink; | 13 show NullSink; |
14 | 14 |
15 import '../../../sdk/lib/_internal/compiler/compiler.dart' | 15 import '../../../sdk/lib/_internal/compiler/compiler.dart' |
16 show DiagnosticHandler, Diagnostic; | 16 show DiagnosticHandler, Diagnostic; |
17 | 17 |
18 import 'dart:async'; | 18 import 'dart:async'; |
19 | 19 |
20 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart' ; | 20 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart' ; |
21 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirro r.dart'; | 21 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirro r.dart'; |
22 | 22 |
23 const MEMORY_SOURCE_FILES = const { | 23 const MEMORY_SOURCE_FILES = const { |
24 'main.dart': ''' | 24 'main.dart': ''' |
25 | 25 |
26 import 'package:foo/foo.dart'; | 26 import 'foo.dart'; |
27 | 27 |
28 main() {} | 28 main() {} |
29 ''', | 29 ''', |
30 }; | 30 }; |
31 | 31 |
32 void runCompiler(Uri main) { | 32 void runCompiler(Uri main, String expectedMessage) { |
33 Uri script = currentDirectory.resolve(nativeToUriPath(Platform.script)); | 33 Uri script = currentDirectory.resolve(nativeToUriPath(Platform.script)); |
34 Uri libraryRoot = script.resolve('../../../sdk/'); | 34 Uri libraryRoot = script.resolve('../../../sdk/'); |
35 | 35 |
36 MemorySourceFileProvider.MEMORY_SOURCE_FILES = MEMORY_SOURCE_FILES; | 36 MemorySourceFileProvider.MEMORY_SOURCE_FILES = MEMORY_SOURCE_FILES; |
37 var provider = new MemorySourceFileProvider(); | 37 var provider = new MemorySourceFileProvider(); |
38 var handler = new FormattingDiagnosticHandler(provider); | 38 var handler = new FormattingDiagnosticHandler(provider); |
39 var errors = []; | 39 var errors = []; |
40 | 40 |
41 void diagnosticHandler(Uri uri, int begin, int end, String message, | 41 void diagnosticHandler(Uri uri, int begin, int end, String message, |
42 Diagnostic kind) { | 42 Diagnostic kind) { |
43 if (kind == Diagnostic.ERROR) { | 43 if (kind == Diagnostic.ERROR) { |
44 errors.add(message); | 44 errors.add(message); |
45 } | 45 } |
46 handler(uri, begin, end, message, kind); | 46 handler(uri, begin, end, message, kind); |
47 } | 47 } |
48 | 48 |
49 | 49 |
50 EventSink<String> outputProvider(String name, String extension) { | 50 EventSink<String> outputProvider(String name, String extension) { |
51 if (name != '') throw 'Attempt to output file "$name.$extension"'; | 51 if (name != '') throw 'Attempt to output file "$name.$extension"'; |
52 return new NullSink('$name.$extension'); | 52 return new NullSink('$name.$extension'); |
53 } | 53 } |
54 | 54 |
55 Compiler compiler = new Compiler(provider.readStringFromUri, | 55 Compiler compiler = new Compiler(provider, |
56 outputProvider, | 56 outputProvider, |
57 diagnosticHandler, | 57 diagnosticHandler, |
58 libraryRoot, | 58 libraryRoot, |
59 null, | 59 null, |
60 []); | 60 []); |
61 | 61 |
62 compiler.run(main); | 62 compiler.run(main).then((_) { |
ahe
2013/08/06 16:29:17
This test is async and must use dart/tests/async_h
Johnni Winther
2013/08/27 11:05:00
Done.
| |
63 Expect.equals(1, errors.length); | 63 Expect.equals(1, errors.length); |
64 Expect.equals('Error: Cannot resolve "package:foo/foo.dart". ' | 64 Expect.equals(expectedMessage, |
65 'Package root has not been set.', | 65 errors[0]); |
66 errors[0]); | 66 }); |
67 } | 67 } |
68 | 68 |
69 void main() { | 69 void main() { |
70 runCompiler(Uri.parse('memory:main.dart')); | 70 runCompiler(Uri.parse('memory:main.dart'), |
71 runCompiler(Uri.parse('package:foo/foo.dart')); | 71 'Error: No such file memory:foo.dart'); |
72 runCompiler(Uri.parse('memory:foo.dart'), | |
73 'Error: No such file memory:foo.dart'); | |
74 runCompiler(Uri.parse('dart:foo'), | |
75 'Error: Library not found dart:foo.'); | |
72 } | 76 } |
OLD | NEW |