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

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

Issue 1408253006: Introduce "platform configurations" to replace categories and libraries.dart. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fix create_sdk scripts according to review Created 5 years, 1 month 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
« no previous file with comments | « tests/compiler/dart2js/categories_test.dart ('k') | tests/compiler/dart2js/mock_libraries.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 Expect;
18 Expect;
19 18
20 import 'package:compiler/src/diagnostics/messages.dart' show 19 import 'package:compiler/src/diagnostics/messages.dart'
21 MessageKind, 20 show MessageKind, MessageTemplate;
22 MessageTemplate;
23 21
24 import 'package:compiler/src/elements/elements.dart' show 22 import 'package:compiler/src/elements/elements.dart' show LibraryElement;
25 LibraryElement;
26 23
27 import 'package:compiler/src/null_compiler_output.dart' show 24 import 'package:compiler/src/null_compiler_output.dart' show NullCompilerOutput;
28 NullCompilerOutput;
29 25
30 import 'package:compiler/src/old_to_new_api.dart' show 26 import 'package:compiler/src/old_to_new_api.dart'
31 LegacyCompilerDiagnostics, 27 show LegacyCompilerDiagnostics, LegacyCompilerInput;
32 LegacyCompilerInput;
33 28
34 import 'package:sdk_library_metadata/libraries.dart' show 29 Uri sdkRoot = Uri.base.resolve("sdk/");
35 DART2JS_PLATFORM, 30 Uri mock1LibraryUri = sdkRoot.resolve("lib/mock1.dart");
36 LibraryInfo; 31 Uri mock2LibraryUri = sdkRoot.resolve("lib/mock2.dart");
37
38 const LibraryInfo mock1LibraryInfo = const LibraryInfo(
39 "mock1.dart",
40 categories: "Client,Embedded",
41 documented: false,
42 platforms: DART2JS_PLATFORM);
43
44 const LibraryInfo mock2LibraryInfo = const LibraryInfo(
45 "mock2.dart",
46 categories: "Client,Embedded",
47 documented: false,
48 platforms: DART2JS_PLATFORM);
49
50 32
51 class CustomCompiler extends CompilerImpl { 33 class CustomCompiler extends CompilerImpl {
52 final Map<String, LibraryInfo> customLibraryInfo; 34 CustomCompiler(provider, handler, libraryRoot,
35 packageRoot, options, environment)
36 : super(provider, const NullCompilerOutput(), handler, libraryRoot,
37 packageRoot, options, environment);
53 38
54 CustomCompiler( 39 Uri lookupLibraryUri(String libraryName) {
55 this.customLibraryInfo, 40 if (libraryName == "m_o_c_k_1") return mock1LibraryUri;
56 provider, 41 if (libraryName == "m_o_c_k_2") return mock2LibraryUri;
57 handler, 42 return super.lookupLibraryUri(libraryName);
58 libraryRoot,
59 packageRoot,
60 options,
61 environment)
62 : super(
63 provider,
64 const NullCompilerOutput(),
65 handler,
66 libraryRoot,
67 packageRoot,
68 options,
69 environment);
70
71 LibraryInfo lookupLibraryInfo(String name) {
72 if (name == "m_o_c_k_1") return mock1LibraryInfo;
73 if (name == "m_o_c_k_2") return mock2LibraryInfo;
74 return super.lookupLibraryInfo(name);
75 } 43 }
76 } 44 }
77 45
78 main() { 46 main() async {
79 Uri sdkRoot = Uri.base.resolve("sdk/");
80 Uri packageRoot = Uri.base.resolve(Platform.packageRoot); 47 Uri packageRoot = Uri.base.resolve(Platform.packageRoot);
81 48
82 var provider = new MemorySourceFileProvider(MEMORY_SOURCE_FILES); 49 var provider = new MemorySourceFileProvider(MEMORY_SOURCE_FILES);
83 var handler = new FormattingDiagnosticHandler(provider); 50 var handler = new FormattingDiagnosticHandler(provider);
84 51
85 Future wrappedProvider(Uri uri) { 52 Future wrappedProvider(Uri uri) {
86 if (uri == sdkRoot.resolve('lib/mock1.dart')) { 53 if (uri == mock1LibraryUri) {
87 return provider.readStringFromUri(Uri.parse('memory:mock1.dart')); 54 return provider.readStringFromUri(Uri.parse('memory:mock1.dart'));
88 } 55 }
89 if (uri == sdkRoot.resolve('lib/mock2.dart')) { 56 if (uri == mock2LibraryUri) {
90 return provider.readStringFromUri(Uri.parse('memory:mock2.dart')); 57 return provider.readStringFromUri(Uri.parse('memory:mock2.dart'));
91 } 58 }
92 return provider.readStringFromUri(uri); 59 return provider.readStringFromUri(uri);
93 } 60 }
94 61
95 String expectedMessage = 62 String expectedMessage = MessageTemplate.TEMPLATES[
96 MessageTemplate.TEMPLATES[MessageKind.LIBRARY_NOT_FOUND].message( 63 MessageKind.LIBRARY_NOT_FOUND]
97 {'resolvedUri': 'dart:mock2.dart'}).computeMessage(); 64 .message({'resolvedUri': 'dart:mock2.dart'}).computeMessage();
98 65
99 int actualMessageCount = 0; 66 int actualMessageCount = 0;
100 67
101 wrappedHandler( 68 wrappedHandler(Uri uri, int begin, int end, String message, kind) {
102 Uri uri, int begin, int end, String message, kind) {
103 if (message == expectedMessage) { 69 if (message == expectedMessage) {
104 actualMessageCount++; 70 actualMessageCount++;
105 } else { 71 } else {
106 return handler(uri, begin, end, message, kind); 72 return handler(uri, begin, end, message, kind);
107 } 73 }
108 } 74 }
109 75
110 checkLibrary(LibraryElement library) { 76 checkLibrary(LibraryElement library) {
111 Expect.equals(1, actualMessageCount); 77 Expect.equals(1, actualMessageCount);
112 } 78 }
113 79
114 CompilerImpl compiler = new CustomCompiler( 80 CompilerImpl compiler = new CustomCompiler(
115 {},
116 new LegacyCompilerInput(wrappedProvider), 81 new LegacyCompilerInput(wrappedProvider),
117 new LegacyCompilerDiagnostics(wrappedHandler), 82 new LegacyCompilerDiagnostics(wrappedHandler),
118 sdkRoot, 83 sdkRoot,
119 packageRoot, 84 packageRoot,
120 [], 85 [],
121 {}); 86 {});
122 87
123 asyncStart(); 88 asyncStart();
124 compiler.libraryLoader.loadLibrary(Uri.parse("dart:m_o_c_k_1")) 89 await compiler.setupSdk();
125 .then(checkLibrary) 90 var library =
126 .then(asyncSuccess); 91 await compiler.libraryLoader.loadLibrary(Uri.parse("dart:m_o_c_k_1"));
92 await checkLibrary(library);
93 asyncSuccess(null);
127 } 94 }
128 95
129 const Map MEMORY_SOURCE_FILES = const { 96 const Map MEMORY_SOURCE_FILES = const {
130 "mock1.dart": "library mock1; import 'mock2.dart';", 97 "mock1.dart": "library mock1; import 'mock2.dart';",
131 "mock2.dart": "library mock2;", 98 "mock2.dart": "library mock2;",
132 }; 99 };
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/categories_test.dart ('k') | tests/compiler/dart2js/mock_libraries.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698