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

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

Issue 1235563003: Add interfaces for a new compiler API. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Rebased 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.missing_file; 7 library dart2js.test.missing_file;
8 8
9 import 'dart:async';
10 import 'package:async_helper/async_helper.dart';
11 import 'package:compiler/src/dart2jslib.dart';
9 import 'package:expect/expect.dart'; 12 import 'package:expect/expect.dart';
10 import "package:async_helper/async_helper.dart"; 13 import 'memory_compiler.dart';
11 import 'memory_source_file_helper.dart';
12
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 14
21 const MEMORY_SOURCE_FILES = const { 15 const MEMORY_SOURCE_FILES = const {
22 'main.dart': ''' 16 'main.dart': '''
23 17
24 import 'foo.dart'; 18 import 'foo.dart';
25 19
26 main() {} 20 main() {}
27 ''', 21 ''',
28 }; 22 };
29 23
30 Future runCompiler(Uri main, String expectedMessage) { 24 Future runCompiler(Uri main, String expectedMessage) {
31 print("\n\n\n"); 25 print("\n\n\n");
32 Uri script = currentDirectory.resolveUri(Platform.script);
33 Uri libraryRoot = script.resolve('../../../sdk/');
34 Uri packageRoot = script.resolve('./packages/');
35 26
36 var provider = new MemorySourceFileProvider(MEMORY_SOURCE_FILES); 27 DiagnosticCollector diagnostics = new DiagnosticCollector();
37 var handler = new FormattingDiagnosticHandler(provider); 28 OutputCollector output = new OutputCollector();
38 var errors = []; 29 Compiler compiler = compilerFor(
39 30 MEMORY_SOURCE_FILES,
40 void diagnosticHandler(Uri uri, int begin, int end, String message, 31 diagnosticHandler: diagnostics,
41 Diagnostic kind) { 32 outputProvider: output);
42 if (kind == Diagnostic.ERROR) {
43 errors.add(message);
44 }
45 handler(uri, begin, end, message, kind);
46 }
47
48
49 EventSink<String> outputProvider(String name, String extension) {
50 if (name != '') throw 'Attempt to output file "$name.$extension"';
51 return new NullSink('$name.$extension');
52 }
53
54 Compiler compiler = new Compiler(provider,
55 outputProvider,
56 diagnosticHandler,
57 libraryRoot,
58 packageRoot,
59 [],
60 {});
61 33
62 return compiler.run(main).then((_) { 34 return compiler.run(main).then((_) {
63 Expect.equals(1, errors.length); 35 Expect.isFalse(output.hasExtraOutput);
64 Expect.equals(expectedMessage, 36 Expect.equals(1, diagnostics.errors.length);
65 errors[0]); 37 Expect.equals(expectedMessage, diagnostics.errors.first.message);
66 }); 38 });
67 } 39 }
68 40
69 void main() { 41 void main() {
70 asyncTest(() => Future.forEach([ 42 asyncTest(() => Future.forEach([
71 () => runCompiler( 43 () => runCompiler(
72 Uri.parse('memory:main.dart'), 44 Uri.parse('memory:main.dart'),
73 "Can't read 'memory:foo.dart' " 45 "Can't read 'memory:foo.dart' "
74 "(Exception: No such file memory:foo.dart)."), 46 "(Exception: No such file memory:foo.dart)."),
75 () => runCompiler( 47 () => runCompiler(
76 Uri.parse('memory:foo.dart'), 48 Uri.parse('memory:foo.dart'),
77 "Exception: No such file memory:foo.dart"), 49 "Exception: No such file memory:foo.dart"),
78 () => runCompiler( 50 () => runCompiler(
79 Uri.parse('dart:foo'), 51 Uri.parse('dart:foo'),
80 "Library not found 'dart:foo'."), 52 "Library not found 'dart:foo'."),
81 ], (f) => f())); 53 ], (f) => f()));
82 } 54 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/mirrors_used_test.dart ('k') | tests/compiler/dart2js/mock_compiler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698