OLD | NEW |
---|---|
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 import 'package:sdk_library_metadata/libraries.dart' |
Johnni Winther
2015/10/30 10:38:39
Remove this.
sigurdm
2015/10/30 11:38:27
Done.
| |
35 DART2JS_PLATFORM, | 30 show DART2JS_PLATFORM, LibraryInfo; |
36 LibraryInfo; | |
37 | 31 |
38 const LibraryInfo mock1LibraryInfo = const LibraryInfo( | 32 Uri sdkRoot = Uri.base.resolve("sdk/"); |
39 "mock1.dart", | 33 Uri mock1LibraryUri = sdkRoot.resolve("lib/mock1.dart"); |
40 categories: "Client,Embedded", | 34 Uri mock2LibraryUri = sdkRoot.resolve("lib/mock2.dart"); |
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 | 35 |
51 class CustomCompiler extends CompilerImpl { | 36 class CustomCompiler extends CompilerImpl { |
52 final Map<String, LibraryInfo> customLibraryInfo; | 37 final Map<String, LibraryInfo> customLibraryInfo; |
53 | 38 |
54 CustomCompiler( | 39 CustomCompiler(this.customLibraryInfo, provider, handler, libraryRoot, |
55 this.customLibraryInfo, | 40 packageRoot, options, environment) |
56 provider, | 41 : super(provider, const NullCompilerOutput(), handler, libraryRoot, |
57 handler, | 42 packageRoot, options, environment); |
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 | 43 |
71 LibraryInfo lookupLibraryInfo(String name) { | 44 Uri lookupLibraryUri(String libraryName) { |
72 if (name == "m_o_c_k_1") return mock1LibraryInfo; | 45 if (libraryName == "m_o_c_k_1") return mock1LibraryUri; |
73 if (name == "m_o_c_k_2") return mock2LibraryInfo; | 46 if (libraryName == "m_o_c_k_2") return mock2LibraryUri; |
74 return super.lookupLibraryInfo(name); | 47 return super.lookupLibraryUri(libraryName); |
75 } | 48 } |
76 } | 49 } |
77 | 50 |
78 main() { | 51 main() async { |
79 Uri sdkRoot = Uri.base.resolve("sdk/"); | |
80 Uri packageRoot = Uri.base.resolve(Platform.packageRoot); | 52 Uri packageRoot = Uri.base.resolve(Platform.packageRoot); |
81 | 53 |
82 var provider = new MemorySourceFileProvider(MEMORY_SOURCE_FILES); | 54 var provider = new MemorySourceFileProvider(MEMORY_SOURCE_FILES); |
83 var handler = new FormattingDiagnosticHandler(provider); | 55 var handler = new FormattingDiagnosticHandler(provider); |
84 | 56 |
85 Future wrappedProvider(Uri uri) { | 57 Future wrappedProvider(Uri uri) { |
86 if (uri == sdkRoot.resolve('lib/mock1.dart')) { | 58 if (uri == mock1LibraryUri) { |
87 return provider.readStringFromUri(Uri.parse('memory:mock1.dart')); | 59 return provider.readStringFromUri(Uri.parse('memory:mock1.dart')); |
88 } | 60 } |
89 if (uri == sdkRoot.resolve('lib/mock2.dart')) { | 61 if (uri == mock2LibraryUri) { |
90 return provider.readStringFromUri(Uri.parse('memory:mock2.dart')); | 62 return provider.readStringFromUri(Uri.parse('memory:mock2.dart')); |
91 } | 63 } |
92 return provider.readStringFromUri(uri); | 64 return provider.readStringFromUri(uri); |
93 } | 65 } |
94 | 66 |
95 String expectedMessage = | 67 String expectedMessage = MessageTemplate.TEMPLATES[ |
96 MessageTemplate.TEMPLATES[MessageKind.LIBRARY_NOT_FOUND].message( | 68 MessageKind.LIBRARY_NOT_FOUND] |
97 {'resolvedUri': 'dart:mock2.dart'}).computeMessage(); | 69 .message({'resolvedUri': 'dart:mock2.dart'}).computeMessage(); |
98 | 70 |
99 int actualMessageCount = 0; | 71 int actualMessageCount = 0; |
100 | 72 |
101 wrappedHandler( | 73 wrappedHandler(Uri uri, int begin, int end, String message, kind) { |
102 Uri uri, int begin, int end, String message, kind) { | |
103 if (message == expectedMessage) { | 74 if (message == expectedMessage) { |
104 actualMessageCount++; | 75 actualMessageCount++; |
105 } else { | 76 } else { |
106 return handler(uri, begin, end, message, kind); | 77 return handler(uri, begin, end, message, kind); |
107 } | 78 } |
108 } | 79 } |
109 | 80 |
110 checkLibrary(LibraryElement library) { | 81 checkLibrary(LibraryElement library) { |
111 Expect.equals(1, actualMessageCount); | 82 Expect.equals(1, actualMessageCount); |
112 } | 83 } |
113 | 84 |
114 CompilerImpl compiler = new CustomCompiler( | 85 CompilerImpl compiler = new CustomCompiler( |
115 {}, | 86 {}, |
116 new LegacyCompilerInput(wrappedProvider), | 87 new LegacyCompilerInput(wrappedProvider), |
117 new LegacyCompilerDiagnostics(wrappedHandler), | 88 new LegacyCompilerDiagnostics(wrappedHandler), |
118 sdkRoot, | 89 sdkRoot, |
119 packageRoot, | 90 packageRoot, |
120 [], | 91 [], |
121 {}); | 92 {}); |
122 | 93 |
123 asyncStart(); | 94 asyncStart(); |
124 compiler.libraryLoader.loadLibrary(Uri.parse("dart:m_o_c_k_1")) | 95 await compiler.setupSdk(); |
125 .then(checkLibrary) | 96 var library = |
126 .then(asyncSuccess); | 97 await compiler.libraryLoader.loadLibrary(Uri.parse("dart:m_o_c_k_1")); |
98 await checkLibrary(library); | |
99 asyncSuccess(null); | |
127 } | 100 } |
128 | 101 |
129 const Map MEMORY_SOURCE_FILES = const { | 102 const Map MEMORY_SOURCE_FILES = const { |
130 "mock1.dart": "library mock1; import 'mock2.dart';", | 103 "mock1.dart": "library mock1; import 'mock2.dart';", |
131 "mock2.dart": "library mock2;", | 104 "mock2.dart": "library mock2;", |
132 }; | 105 }; |
OLD | NEW |