| Index: tests/compiler/dart2js/package_root_test.dart
|
| diff --git a/tests/compiler/dart2js/package_root_test.dart b/tests/compiler/dart2js/package_root_test.dart
|
| index 5a173f55361fc892b4ba804aa9cc52da988c76cb..f1e6ee6eb89f99212f1fe7cb8ee1248399154e99 100644
|
| --- a/tests/compiler/dart2js/package_root_test.dart
|
| +++ b/tests/compiler/dart2js/package_root_test.dart
|
| @@ -6,17 +6,16 @@
|
|
|
| library dart2js.test.package_root;
|
|
|
| -import 'package:expect/expect.dart';
|
| -import "package:async_helper/async_helper.dart";
|
| -import 'memory_source_file_helper.dart';
|
| -
|
| -import 'package:compiler/src/dart2jslib.dart'
|
| - show NullSink;
|
| +import 'dart:async';
|
|
|
| +import 'package:async_helper/async_helper.dart';
|
| +import 'package:expect/expect.dart';
|
| import 'package:compiler/compiler.dart'
|
| - show DiagnosticHandler, Diagnostic;
|
| + show DiagnosticHandler, Diagnostic, PackagesDiscoveryProvider;
|
| +import 'package:package_config/packages.dart';
|
|
|
| -import 'dart:async';
|
| +import 'memory_compiler.dart';
|
| +import 'memory_source_file_helper.dart';
|
|
|
| const MEMORY_SOURCE_FILES = const {
|
| 'main.dart': '''
|
| @@ -25,46 +24,66 @@ import 'package:foo/foo.dart';
|
|
|
| main() {}
|
| ''',
|
| + 'package.config': '''
|
| +''',
|
| };
|
|
|
| -void runCompiler(Uri main) {
|
| +final Uri PACKAGE_CONFIG_URI = Uri.parse('memory:package.config');
|
| +
|
| +void runCompiler(Uri main,
|
| + bool checkError(DiagnosticMessage message),
|
| + {Uri packageRoot,
|
| + Uri packageConfig,
|
| + PackagesDiscoveryProvider packagesDiscoveryProvider}) {
|
| + DiagnosticCollector collector = new DiagnosticCollector();
|
| + Compiler compiler = compilerFor(
|
| + MEMORY_SOURCE_FILES,
|
| + diagnosticHandler: collector,
|
| + packageRoot: packageRoot,
|
| + packageConfig: packageConfig,
|
| + packagesDiscoveryProvider: packagesDiscoveryProvider);
|
| +
|
| + asyncTest(() => compiler.run(main).then((_) {
|
| + Expect.equals(1, collector.errors.length,
|
| + "Unexpected errors: ${collector.errors}");
|
| + Expect.isTrue(checkError(collector.errors.first),
|
| + "Unexpected error: ${collector.errors.first}");
|
| + }));
|
| +}
|
| +
|
| +void main() {
|
| Uri script = currentDirectory.resolveUri(Platform.script);
|
| - Uri libraryRoot = script.resolve('../../../sdk/');
|
| Uri packageRoot = script.resolve('./packages/');
|
|
|
| - var provider = new MemorySourceFileProvider(MEMORY_SOURCE_FILES);
|
| - var handler = new FormattingDiagnosticHandler(provider);
|
| - var errors = [];
|
| + PackagesDiscoveryProvider noPackagesDiscovery = (Uri uri) {
|
| + return new Future.value(Packages.noPackages);
|
| + };
|
|
|
| - 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);
|
| + bool containsErrorReading(DiagnosticMessage message) {
|
| + return message.message.contains("Error reading ");
|
| }
|
|
|
| -
|
| - EventSink<String> outputProvider(String name, String extension) {
|
| - if (name != '') throw 'Attempt to output file "$name.$extension"';
|
| - return new NullSink('$name.$extension');
|
| + bool isLibraryNotFound(DiagnosticMessage message) {
|
| + return message.message.startsWith("Library not found ");
|
| }
|
|
|
| - Compiler compiler = new Compiler(provider,
|
| - outputProvider,
|
| - diagnosticHandler,
|
| - libraryRoot,
|
| - packageRoot,
|
| - [],
|
| - {});
|
| -
|
| - asyncTest(() => compiler.run(main).then((_) {
|
| - Expect.equals(1, errors.length);
|
| - Expect.isTrue(errors[0].contains("Error reading "));
|
| - }));
|
| -}
|
| -
|
| -void main() {
|
| - runCompiler(Uri.parse('memory:main.dart'));
|
| - runCompiler(Uri.parse('package:foo/foo.dart'));
|
| + runCompiler(Uri.parse('memory:main.dart'),
|
| + containsErrorReading,
|
| + packageRoot: packageRoot);
|
| + runCompiler(Uri.parse('memory:main.dart'),
|
| + isLibraryNotFound,
|
| + packageConfig: PACKAGE_CONFIG_URI);
|
| + runCompiler(Uri.parse('memory:main.dart'),
|
| + isLibraryNotFound,
|
| + packagesDiscoveryProvider: noPackagesDiscovery);
|
| +
|
| + runCompiler(Uri.parse('package:foo/foo.dart'),
|
| + containsErrorReading,
|
| + packageRoot: packageRoot);
|
| + runCompiler(Uri.parse('package:foo/foo.dart'),
|
| + isLibraryNotFound,
|
| + packageConfig: PACKAGE_CONFIG_URI);
|
| + runCompiler(Uri.parse('package:foo/foo.dart'),
|
| + isLibraryNotFound,
|
| + packagesDiscoveryProvider: noPackagesDiscovery);
|
| }
|
|
|