| 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/dart2jslib.dart'; | 11 import 'package:compiler/src/dart2jslib.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 | 17 |
| 18 import 'foo.dart'; | 18 import 'foo.dart'; |
| 19 | 19 |
| 20 main() {} | 20 main() {} |
| 21 ''', | 21 ''', |
| 22 }; | 22 }; |
| 23 | 23 |
| 24 Future runCompiler(Uri main, String expectedMessage) { | 24 Future runTest(Uri main, MessageKind expectedMessageKind) async { |
| 25 print("\n\n\n"); | 25 print("\n\n\n"); |
| 26 | 26 |
| 27 DiagnosticCollector diagnostics = new DiagnosticCollector(); | 27 DiagnosticCollector diagnostics = new DiagnosticCollector(); |
| 28 OutputCollector output = new OutputCollector(); | 28 OutputCollector output = new OutputCollector(); |
| 29 Compiler compiler = compilerFor( | 29 await runCompiler( |
| 30 MEMORY_SOURCE_FILES, | 30 memorySourceFiles: MEMORY_SOURCE_FILES, |
| 31 diagnosticHandler: diagnostics, | 31 diagnosticHandler: diagnostics, |
| 32 outputProvider: output); | 32 outputProvider: output); |
| 33 | 33 |
| 34 return compiler.run(main).then((_) { | 34 Expect.isFalse(output.hasExtraOutput); |
| 35 Expect.isFalse(output.hasExtraOutput); | 35 Expect.equals(1, diagnostics.errors.length); |
| 36 Expect.equals(1, diagnostics.errors.length); | 36 Expect.equals(expectedMessageKind, diagnostics.errors.first.message.kind); |
| 37 Expect.equals(expectedMessage, diagnostics.errors.first.message); | |
| 38 }); | |
| 39 } | 37 } |
| 40 | 38 |
| 41 void main() { | 39 void main() { |
| 42 asyncTest(() => Future.forEach([ | 40 asyncTest(() async { |
| 43 () => runCompiler( | 41 await runTest( |
| 44 Uri.parse('memory:main.dart'), | 42 Uri.parse('memory:main.dart'), MessageKind.READ_SCRIPT_ERROR); |
| 45 "Can't read 'memory:foo.dart' " | 43 await runTest( |
| 46 "(Exception: No such file memory:foo.dart)."), | 44 Uri.parse('memory:foo.dart'), MessageKind.READ_SCRIPT_ERROR); |
| 47 () => runCompiler( | 45 await runTest( |
| 48 Uri.parse('memory:foo.dart'), | 46 Uri.parse('dart:foo'), MessageKind.READ_SCRIPT_ERROR); |
| 49 "Exception: No such file memory:foo.dart"), | 47 }); |
| 50 () => runCompiler( | |
| 51 Uri.parse('dart:foo'), | |
| 52 "Library not found 'dart:foo'."), | |
| 53 ], (f) => f())); | |
| 54 } | 48 } |
| OLD | NEW |