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

Side by Side Diff: tests/compiler/dart2js/library_resolution_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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 /// Check that relative URIs are resolved against the canonical name of a 5 /// Check that relative URIs are resolved against the canonical name of a
6 /// library. This only matters for dart:-libraries, so this test mocks up two 6 /// library. This only matters for dart:-libraries, so this test mocks up two
7 /// dart:-libraries. 7 /// dart:-libraries.
8 8
9 import "dart:io"; 9 import "dart:io";
10 10
11 import "dart:async"; 11 import "dart:async";
12 12
13 import "memory_source_file_helper.dart"; 13 import "memory_source_file_helper.dart";
14 14
15 import "package:async_helper/async_helper.dart"; 15 import "package:async_helper/async_helper.dart";
16 16
17 import 'package:expect/expect.dart' show 17 import 'package:expect/expect.dart' show
18 Expect; 18 Expect;
19 19
20 import 'package:compiler/src/elements/elements.dart' show 20 import 'package:compiler/src/elements/elements.dart' show
21 LibraryElement; 21 LibraryElement;
22 22
23 import 'package:compiler/src/dart2jslib.dart' show 23 import 'package:compiler/src/dart2jslib.dart' show
24 MessageKind, 24 MessageKind;
25 NullSink; 25
26 import 'package:compiler/src/null_compiler_output.dart' show
27 NullCompilerOutput;
28
29 import 'package:compiler/src/old_to_new_api.dart' show
30 LegacyCompilerDiagnostics,
31 LegacyCompilerInput;
26 32
27 import 'package:sdk_library_metadata/libraries.dart' show 33 import 'package:sdk_library_metadata/libraries.dart' show
28 DART2JS_PLATFORM, 34 DART2JS_PLATFORM,
29 LibraryInfo; 35 LibraryInfo;
30 36
31 const LibraryInfo mock1LibraryInfo = const LibraryInfo( 37 const LibraryInfo mock1LibraryInfo = const LibraryInfo(
32 "mock1.dart", 38 "mock1.dart",
33 category: "Shared", 39 category: "Shared",
34 documented: false, 40 documented: false,
35 platforms: DART2JS_PLATFORM); 41 platforms: DART2JS_PLATFORM);
36 42
37 const LibraryInfo mock2LibraryInfo = const LibraryInfo( 43 const LibraryInfo mock2LibraryInfo = const LibraryInfo(
38 "mock2.dart", 44 "mock2.dart",
39 category: "Shared", 45 category: "Shared",
40 documented: false, 46 documented: false,
41 platforms: DART2JS_PLATFORM); 47 platforms: DART2JS_PLATFORM);
42 48
49
43 class CustomCompiler extends Compiler { 50 class CustomCompiler extends Compiler {
44 final Map<String, LibraryInfo> customLibraryInfo; 51 final Map<String, LibraryInfo> customLibraryInfo;
45 52
46 CustomCompiler( 53 CustomCompiler(
47 this.customLibraryInfo, 54 this.customLibraryInfo,
48 provider, 55 provider,
49 outputProvider,
50 handler, 56 handler,
51 libraryRoot, 57 libraryRoot,
52 packageRoot, 58 packageRoot,
53 options, 59 options,
54 environment) 60 environment)
55 : super( 61 : super(
56 provider, 62 provider,
57 outputProvider, 63 const NullCompilerOutput(),
58 handler, 64 handler,
59 libraryRoot, 65 libraryRoot,
60 packageRoot, 66 packageRoot,
61 options, 67 options,
62 environment); 68 environment);
63 69
64 LibraryInfo lookupLibraryInfo(String name) { 70 LibraryInfo lookupLibraryInfo(String name) {
65 if (name == "m_o_c_k_1") return mock1LibraryInfo; 71 if (name == "m_o_c_k_1") return mock1LibraryInfo;
66 if (name == "m_o_c_k_2") return mock2LibraryInfo; 72 if (name == "m_o_c_k_2") return mock2LibraryInfo;
67 return super.lookupLibraryInfo(name); 73 return super.lookupLibraryInfo(name);
68 } 74 }
69 } 75 }
70 76
71 main() { 77 main() {
72 Uri sdkRoot = Uri.base.resolve("sdk/"); 78 Uri sdkRoot = Uri.base.resolve("sdk/");
73 Uri packageRoot = Uri.base.resolve(Platform.packageRoot); 79 Uri packageRoot = Uri.base.resolve(Platform.packageRoot);
74 80
75 var provider = new MemorySourceFileProvider(MEMORY_SOURCE_FILES); 81 var provider = new MemorySourceFileProvider(MEMORY_SOURCE_FILES);
76 var handler = new FormattingDiagnosticHandler(provider); 82 var handler = new FormattingDiagnosticHandler(provider);
77 83
78 outputProvider(String name, String extension) {
79 if (name != '') throw 'Attempt to output file "$name.$extension"';
80 return new NullSink('$name.$extension');
81 }
82
83 Future wrappedProvider(Uri uri) { 84 Future wrappedProvider(Uri uri) {
84 if (uri == sdkRoot.resolve('lib/mock1.dart')) { 85 if (uri == sdkRoot.resolve('lib/mock1.dart')) {
85 return provider.readStringFromUri(Uri.parse('memory:mock1.dart')); 86 return provider.readStringFromUri(Uri.parse('memory:mock1.dart'));
86 } 87 }
87 if (uri == sdkRoot.resolve('lib/mock2.dart')) { 88 if (uri == sdkRoot.resolve('lib/mock2.dart')) {
88 return provider.readStringFromUri(Uri.parse('memory:mock2.dart')); 89 return provider.readStringFromUri(Uri.parse('memory:mock2.dart'));
89 } 90 }
90 return provider.readStringFromUri(uri); 91 return provider.readStringFromUri(uri);
91 } 92 }
92 93
(...skipping 11 matching lines...) Expand all
104 return handler(uri, begin, end, message, kind); 105 return handler(uri, begin, end, message, kind);
105 } 106 }
106 } 107 }
107 108
108 checkLibrary(LibraryElement library) { 109 checkLibrary(LibraryElement library) {
109 Expect.equals(1, actualMessageCount); 110 Expect.equals(1, actualMessageCount);
110 } 111 }
111 112
112 Compiler compiler = new CustomCompiler( 113 Compiler compiler = new CustomCompiler(
113 {}, 114 {},
114 wrappedProvider, 115 new LegacyCompilerInput(wrappedProvider),
115 outputProvider, 116 new LegacyCompilerDiagnostics(wrappedHandler),
116 wrappedHandler,
117 sdkRoot, 117 sdkRoot,
118 packageRoot, 118 packageRoot,
119 [], 119 [],
120 {}); 120 {});
121 121
122 asyncStart(); 122 asyncStart();
123 compiler.libraryLoader.loadLibrary(Uri.parse("dart:m_o_c_k_1")) 123 compiler.libraryLoader.loadLibrary(Uri.parse("dart:m_o_c_k_1"))
124 .then(checkLibrary) 124 .then(checkLibrary)
125 .then(asyncSuccess); 125 .then(asyncSuccess);
126 } 126 }
127 127
128 const Map MEMORY_SOURCE_FILES = const { 128 const Map MEMORY_SOURCE_FILES = const {
129 "mock1.dart": "library mock1; import 'mock2.dart';", 129 "mock1.dart": "library mock1; import 'mock2.dart';",
130 "mock2.dart": "library mock2;", 130 "mock2.dart": "library mock2;",
131 }; 131 };
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/incremental/hello_test.dart ('k') | tests/compiler/dart2js/memory_compiler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698