Chromium Code Reviews| Index: tests/compiler/dart2js/missing_file_test.dart |
| diff --git a/tests/compiler/dart2js/package_root_test.dart b/tests/compiler/dart2js/missing_file_test.dart |
| similarity index 73% |
| copy from tests/compiler/dart2js/package_root_test.dart |
| copy to tests/compiler/dart2js/missing_file_test.dart |
| index 62c106d693c93ab9db9c0214251a91e7171f6923..4227b262b19b4e871a7bf789be96b25ebb444c9f 100644 |
| --- a/tests/compiler/dart2js/package_root_test.dart |
| +++ b/tests/compiler/dart2js/missing_file_test.dart |
| @@ -1,72 +1,76 @@ |
| -// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| -// for details. All rights reserved. Use of this source code is governed by a |
| -// BSD-style license that can be found in the LICENSE file. |
| - |
| -// Test that the compiler can handle imports when package root has not been set. |
| - |
| -library dart2js.test.package_root; |
| - |
| -import 'package:expect/expect.dart'; |
| -import 'memory_source_file_helper.dart'; |
| - |
| -import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' |
| - show NullSink; |
| - |
| -import '../../../sdk/lib/_internal/compiler/compiler.dart' |
| - show DiagnosticHandler, Diagnostic; |
| - |
| -import 'dart:async'; |
| - |
| -import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart'; |
| -import '../../../sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirror.dart'; |
| - |
| -const MEMORY_SOURCE_FILES = const { |
| - 'main.dart': ''' |
| - |
| -import 'package:foo/foo.dart'; |
| - |
| -main() {} |
| -''', |
| -}; |
| - |
| -void runCompiler(Uri main) { |
| - Uri script = currentDirectory.resolve(nativeToUriPath(Platform.script)); |
| - Uri libraryRoot = script.resolve('../../../sdk/'); |
| - |
| - MemorySourceFileProvider.MEMORY_SOURCE_FILES = MEMORY_SOURCE_FILES; |
| - var provider = new MemorySourceFileProvider(); |
| - var handler = new FormattingDiagnosticHandler(provider); |
| - var errors = []; |
| - |
| - void diagnosticHandler(Uri uri, int begin, int end, String message, |
| - Diagnostic kind) { |
| - if (kind == Diagnostic.ERROR) { |
| - errors.add(message); |
| - } |
| - handler(uri, begin, end, message, kind); |
| - } |
| - |
| - |
| - EventSink<String> outputProvider(String name, String extension) { |
| - if (name != '') throw 'Attempt to output file "$name.$extension"'; |
| - return new NullSink('$name.$extension'); |
| - } |
| - |
| - Compiler compiler = new Compiler(provider.readStringFromUri, |
| - outputProvider, |
| - diagnosticHandler, |
| - libraryRoot, |
| - null, |
| - []); |
| - |
| - compiler.run(main); |
| - Expect.equals(1, errors.length); |
| - Expect.equals('Error: Cannot resolve "package:foo/foo.dart". ' |
| - 'Package root has not been set.', |
| - errors[0]); |
| -} |
| - |
| -void main() { |
| - runCompiler(Uri.parse('memory:main.dart')); |
| - runCompiler(Uri.parse('package:foo/foo.dart')); |
| -} |
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +// Test that the compiler can handle imports when package root has not been set. |
| + |
| +library dart2js.test.missing_file; |
| + |
| +import 'package:expect/expect.dart'; |
| +import 'memory_source_file_helper.dart'; |
| + |
| +import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' |
| + show NullSink; |
| + |
| +import '../../../sdk/lib/_internal/compiler/compiler.dart' |
| + show DiagnosticHandler, Diagnostic; |
| + |
| +import 'dart:async'; |
| + |
| +import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart'; |
| +import '../../../sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirror.dart'; |
| + |
| +const MEMORY_SOURCE_FILES = const { |
| + 'main.dart': ''' |
| + |
| +import 'foo.dart'; |
| + |
| +main() {} |
| +''', |
| +}; |
| + |
| +void runCompiler(Uri main, String expectedMessage) { |
| + Uri script = currentDirectory.resolve(nativeToUriPath(Platform.script)); |
| + Uri libraryRoot = script.resolve('../../../sdk/'); |
| + |
| + MemorySourceFileProvider.MEMORY_SOURCE_FILES = MEMORY_SOURCE_FILES; |
| + var provider = new MemorySourceFileProvider(); |
| + var handler = new FormattingDiagnosticHandler(provider); |
| + var errors = []; |
| + |
| + void diagnosticHandler(Uri uri, int begin, int end, String message, |
| + Diagnostic kind) { |
| + if (kind == Diagnostic.ERROR) { |
| + errors.add(message); |
| + } |
| + handler(uri, begin, end, message, kind); |
| + } |
| + |
| + |
| + EventSink<String> outputProvider(String name, String extension) { |
| + if (name != '') throw 'Attempt to output file "$name.$extension"'; |
| + return new NullSink('$name.$extension'); |
| + } |
| + |
| + Compiler compiler = new Compiler(provider, |
| + outputProvider, |
| + diagnosticHandler, |
| + libraryRoot, |
| + null, |
| + []); |
| + |
| + 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.
|
| + Expect.equals(1, errors.length); |
| + Expect.equals(expectedMessage, |
| + errors[0]); |
| + }); |
| +} |
| + |
| +void main() { |
| + runCompiler(Uri.parse('memory:main.dart'), |
| + 'Error: No such file memory:foo.dart'); |
| + runCompiler(Uri.parse('memory:foo.dart'), |
| + 'Error: No such file memory:foo.dart'); |
| + runCompiler(Uri.parse('dart:foo'), |
| + 'Error: Library not found dart:foo.'); |
| +} |