| 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 'package:expect/expect.dart'; | 9 import 'package:expect/expect.dart'; |
| 10 import "package:async_helper/async_helper.dart"; | 10 import "package:async_helper/async_helper.dart"; |
| 11 import 'memory_source_file_helper.dart'; | 11 import 'memory_source_file_helper.dart'; |
| 12 | 12 |
| 13 import 'package:compiler/src/dart2jslib.dart' | 13 import 'package:compiler/src/dart2jslib.dart' |
| 14 show NullSink; | 14 show NullSink; |
| 15 | 15 |
| 16 import 'package:compiler/compiler.dart' | 16 import 'package:compiler/compiler.dart' |
| 17 show DiagnosticHandler, Diagnostic; | 17 show DiagnosticHandler, Diagnostic; |
| 18 | 18 |
| 19 import 'dart:async'; | 19 import 'dart:async'; |
| 20 | 20 |
| 21 const MEMORY_SOURCE_FILES = const { | 21 const MEMORY_SOURCE_FILES = const { |
| 22 'main.dart': ''' | 22 'main.dart': ''' |
| 23 | 23 |
| 24 import 'foo.dart'; | 24 import 'foo.dart'; |
| 25 | 25 |
| 26 main() {} | 26 main() {} |
| 27 ''', | 27 ''', |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 void runCompiler(Uri main, String expectedMessage) { | 30 Future runCompiler(Uri main, String expectedMessage) { |
| 31 print("\n\n\n"); |
| 31 Uri script = currentDirectory.resolveUri(Platform.script); | 32 Uri script = currentDirectory.resolveUri(Platform.script); |
| 32 Uri libraryRoot = script.resolve('../../../sdk/'); | 33 Uri libraryRoot = script.resolve('../../../sdk/'); |
| 33 Uri packageRoot = script.resolve('./packages/'); | 34 Uri packageRoot = script.resolve('./packages/'); |
| 34 | 35 |
| 35 var provider = new MemorySourceFileProvider(MEMORY_SOURCE_FILES); | 36 var provider = new MemorySourceFileProvider(MEMORY_SOURCE_FILES); |
| 36 var handler = new FormattingDiagnosticHandler(provider); | 37 var handler = new FormattingDiagnosticHandler(provider); |
| 37 var errors = []; | 38 var errors = []; |
| 38 | 39 |
| 39 void diagnosticHandler(Uri uri, int begin, int end, String message, | 40 void diagnosticHandler(Uri uri, int begin, int end, String message, |
| 40 Diagnostic kind) { | 41 Diagnostic kind) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 51 } | 52 } |
| 52 | 53 |
| 53 Compiler compiler = new Compiler(provider, | 54 Compiler compiler = new Compiler(provider, |
| 54 outputProvider, | 55 outputProvider, |
| 55 diagnosticHandler, | 56 diagnosticHandler, |
| 56 libraryRoot, | 57 libraryRoot, |
| 57 packageRoot, | 58 packageRoot, |
| 58 [], | 59 [], |
| 59 {}); | 60 {}); |
| 60 | 61 |
| 61 asyncTest(() => compiler.run(main).then((_) { | 62 return compiler.run(main).then((_) { |
| 62 Expect.equals(1, errors.length); | 63 Expect.equals(1, errors.length); |
| 63 Expect.equals(expectedMessage, | 64 Expect.equals(expectedMessage, |
| 64 errors[0]); | 65 errors[0]); |
| 65 })); | 66 }); |
| 66 } | 67 } |
| 67 | 68 |
| 68 void main() { | 69 void main() { |
| 69 runCompiler(Uri.parse('memory:main.dart'), | 70 asyncTest(() => Future.forEach([ |
| 70 "Can't read 'memory:foo.dart' " | 71 () => runCompiler( |
| 71 "(Exception: No such file memory:foo.dart)."); | 72 Uri.parse('memory:main.dart'), |
| 72 runCompiler(Uri.parse('memory:foo.dart'), | 73 "Can't read 'memory:foo.dart' " |
| 73 "Can't read 'memory:foo.dart' " | 74 "(Exception: No such file memory:foo.dart)."), |
| 74 "(Exception: No such file memory:foo.dart)."); | 75 () => runCompiler( |
| 75 runCompiler(Uri.parse('dart:foo'), | 76 Uri.parse('memory:foo.dart'), |
| 76 "Library not found 'dart:foo'."); | 77 "Exception: No such file memory:foo.dart"), |
| 78 () => runCompiler( |
| 79 Uri.parse('dart:foo'), |
| 80 "Library not found 'dart:foo'."), |
| 81 ], (f) => f())); |
| 77 } | 82 } |
| OLD | NEW |