Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(318)

Side by Side Diff: tests/compiler/dart2js/package_root_test.dart

Issue 1205373002: Translate package URIs to resource URIs for diagnostics. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Use resourceUri instead of readableUri in source spans. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.package_root;
8 8
9 import 'dart:async';
10
11 import 'package:async_helper/async_helper.dart';
9 import 'package:expect/expect.dart'; 12 import 'package:expect/expect.dart';
10 import "package:async_helper/async_helper.dart"; 13 import 'package:compiler/compiler.dart'
14 show DiagnosticHandler, Diagnostic, PackagesDiscoveryProvider;
15 import 'package:package_config/packages.dart';
16
17 import 'memory_compiler.dart';
11 import 'memory_source_file_helper.dart'; 18 import 'memory_source_file_helper.dart';
12 19
13 import 'package:compiler/src/dart2jslib.dart'
14 show NullSink;
15
16 import 'package:compiler/compiler.dart'
17 show DiagnosticHandler, Diagnostic;
18
19 import 'dart:async';
20
21 const MEMORY_SOURCE_FILES = const { 20 const MEMORY_SOURCE_FILES = const {
22 'main.dart': ''' 21 'main.dart': '''
23 22
24 import 'package:foo/foo.dart'; 23 import 'package:foo/foo.dart';
25 24
26 main() {} 25 main() {}
27 ''', 26 ''',
27 'package.config': '''
28 ''',
28 }; 29 };
29 30
30 void runCompiler(Uri main) { 31 final Uri PACKAGE_CONFIG_URI = Uri.parse('memory:package.config');
31 Uri script = currentDirectory.resolveUri(Platform.script);
32 Uri libraryRoot = script.resolve('../../../sdk/');
33 Uri packageRoot = script.resolve('./packages/');
34 32
35 var provider = new MemorySourceFileProvider(MEMORY_SOURCE_FILES); 33 void runCompiler(Uri main,
36 var handler = new FormattingDiagnosticHandler(provider); 34 bool checkError(DiagnosticMessage message),
37 var errors = []; 35 {Uri packageRoot,
38 36 Uri packageConfig,
39 void diagnosticHandler(Uri uri, int begin, int end, String message, 37 PackagesDiscoveryProvider packagesDiscoveryProvider}) {
40 Diagnostic kind) { 38 DiagnosticCollector collector = new DiagnosticCollector();
41 if (kind == Diagnostic.ERROR) { 39 Compiler compiler = compilerFor(
42 errors.add(message); 40 MEMORY_SOURCE_FILES,
43 } 41 diagnosticHandler: collector,
44 handler(uri, begin, end, message, kind); 42 packageRoot: packageRoot,
45 } 43 packageConfig: packageConfig,
46 44 packagesDiscoveryProvider: packagesDiscoveryProvider);
47
48 EventSink<String> outputProvider(String name, String extension) {
49 if (name != '') throw 'Attempt to output file "$name.$extension"';
50 return new NullSink('$name.$extension');
51 }
52
53 Compiler compiler = new Compiler(provider,
54 outputProvider,
55 diagnosticHandler,
56 libraryRoot,
57 packageRoot,
58 [],
59 {});
60 45
61 asyncTest(() => compiler.run(main).then((_) { 46 asyncTest(() => compiler.run(main).then((_) {
62 Expect.equals(1, errors.length); 47 Expect.equals(1, collector.errors.length,
63 Expect.isTrue(errors[0].contains("Error reading ")); 48 "Unexpected errors: ${collector.errors}");
49 Expect.isTrue(checkError(collector.errors.first),
50 "Unexpected error: ${collector.errors.first}");
64 })); 51 }));
65 } 52 }
66 53
67 void main() { 54 void main() {
68 runCompiler(Uri.parse('memory:main.dart')); 55 Uri script = currentDirectory.resolveUri(Platform.script);
69 runCompiler(Uri.parse('package:foo/foo.dart')); 56 Uri packageRoot = script.resolve('./packages/');
57
58 PackagesDiscoveryProvider noPackagesDiscovery = (Uri uri) {
59 return new Future.value(Packages.noPackages);
60 };
61
62 bool containsErrorReading(DiagnosticMessage message) {
63 return message.message.contains("Error reading ");
64 }
65
66 bool isLibraryNotFound(DiagnosticMessage message) {
67 return message.message.startsWith("Library not found ");
68 }
69
70 runCompiler(Uri.parse('memory:main.dart'),
71 containsErrorReading,
72 packageRoot: packageRoot);
73 runCompiler(Uri.parse('memory:main.dart'),
74 isLibraryNotFound,
75 packageConfig: PACKAGE_CONFIG_URI);
76 runCompiler(Uri.parse('memory:main.dart'),
77 isLibraryNotFound,
78 packagesDiscoveryProvider: noPackagesDiscovery);
79
80 runCompiler(Uri.parse('package:foo/foo.dart'),
81 containsErrorReading,
82 packageRoot: packageRoot);
83 runCompiler(Uri.parse('package:foo/foo.dart'),
84 isLibraryNotFound,
85 packageConfig: PACKAGE_CONFIG_URI);
86 runCompiler(Uri.parse('package:foo/foo.dart'),
87 isLibraryNotFound,
88 packagesDiscoveryProvider: noPackagesDiscovery);
70 } 89 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/memory_compiler.dart ('k') | tests/compiler/dart2js/show_package_warnings_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698