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

Side by Side Diff: pkg/front_end/test/src/base/processed_options_test.dart

Issue 2976543002: Reapply "Tweak public APIs and use them in patch_sdk, dart2js, and kernel-service."" (Closed)
Patch Set: fix Created 3 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) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 import 'dart:async'; 5 import 'dart:async';
6 6
7 import 'package:front_end/compiler_options.dart'; 7 import 'package:front_end/compiler_options.dart';
8 import 'package:front_end/memory_file_system.dart'; 8 import 'package:front_end/memory_file_system.dart';
9 import 'package:front_end/src/base/processed_options.dart'; 9 import 'package:front_end/src/base/processed_options.dart';
10 import 'package:front_end/src/fasta/fasta.dart' show ByteSink; 10 import 'package:front_end/src/fasta/fasta.dart' show ByteSink;
11 import 'package:kernel/binary/ast_to_binary.dart' show BinaryPrinter; 11 import 'package:kernel/binary/ast_to_binary.dart' show BinaryPrinter;
12 import 'package:kernel/kernel.dart' show Program, Library; 12 import 'package:kernel/kernel.dart' show Program, Library, CanonicalName;
13 13
14 import 'package:test/test.dart'; 14 import 'package:test/test.dart';
15 import 'package:test_reflective_loader/test_reflective_loader.dart'; 15 import 'package:test_reflective_loader/test_reflective_loader.dart';
16 16
17 main() { 17 main() {
18 defineReflectiveSuite(() { 18 defineReflectiveSuite(() {
19 defineReflectiveTests(ProcessedOptionsTest); 19 defineReflectiveTests(ProcessedOptionsTest);
20 }); 20 });
21 } 21 }
22 22
23 @reflectiveTest 23 @reflectiveTest
24 class ProcessedOptionsTest { 24 class ProcessedOptionsTest {
25 final fileSystem = new MemoryFileSystem(Uri.parse('file:///')); 25 final fileSystem = new MemoryFileSystem(Uri.parse('file:///'));
26 26
27 Program _mockOutline; 27 Program _mockOutline;
28 28
29 Program get mockSummary => _mockOutline ??= 29 Program get mockSummary => _mockOutline ??=
30 new Program(libraries: [new Library(Uri.parse('file:///a/b.dart'))]); 30 new Program(libraries: [new Library(Uri.parse('file:///a/b.dart'))]);
31 31
32 test_compileSdk_false() { 32 test_compileSdk_false() {
33 for (var value in [false, true]) { 33 for (var value in [false, true]) {
34 var raw = new CompilerOptions()..compileSdk = value; 34 var raw = new CompilerOptions()..compileSdk = value;
35 var processed = new ProcessedOptions(raw); 35 var processed = new ProcessedOptions(raw);
36 expect(processed.compileSdk, value); 36 expect(processed.compileSdk, value);
37 } 37 }
38 } 38 }
39 39
40 test_sdk_summary_inferred() {
41 // The sdk-summary is inferred by default form sdk-root, when compile-sdk is
42 // false
43 var raw = new CompilerOptions()
44 ..sdkRoot = Uri.parse('file:///sdk/dir/')
45 ..compileSdk = false;
46 expect(new ProcessedOptions(raw).sdkSummary,
47 Uri.parse('file:///sdk/dir/outline.dill'));
48
49 // But it is left null when compile-sdk is true
50 raw = new CompilerOptions()
51 ..sdkRoot = Uri.parse('file:///sdk/dir/')
52 ..compileSdk = true;
53 expect(new ProcessedOptions(raw).sdkSummary, null);
54 }
55
40 test_fileSystem_noBazelRoots() { 56 test_fileSystem_noBazelRoots() {
41 // When no bazel roots are specified, the filesystem should be passed 57 // When no bazel roots are specified, the filesystem should be passed
42 // through unmodified. 58 // through unmodified.
43 var raw = new CompilerOptions()..fileSystem = fileSystem; 59 var raw = new CompilerOptions()..fileSystem = fileSystem;
44 var processed = new ProcessedOptions(raw); 60 var processed = new ProcessedOptions(raw);
45 expect(processed.fileSystem, same(fileSystem)); 61 expect(processed.fileSystem, same(fileSystem));
46 } 62 }
47 63
48 test_getSdkSummary_summaryLocationProvided() async { 64 test_getSdkSummary_summaryLocationProvided() async {
49 var uri = Uri.parse('file:///sdkSummary'); 65 var uri = Uri.parse('file:///sdkSummary');
50 writeMockSummaryTo(uri); 66 writeMockSummaryTo(uri);
51 checkMockSummary(new CompilerOptions() 67 checkMockSummary(new CompilerOptions()
52 ..fileSystem = fileSystem 68 ..fileSystem = fileSystem
53 ..sdkSummary = uri); 69 ..sdkSummary = uri);
54 } 70 }
55 71
56 void writeMockSummaryTo(Uri uri) { 72 void writeMockSummaryTo(Uri uri) {
57 var sink = new ByteSink(); 73 var sink = new ByteSink();
58 new BinaryPrinter(sink).writeProgramFile(mockSummary); 74 new BinaryPrinter(sink).writeProgramFile(mockSummary);
59 fileSystem.entityForUri(uri).writeAsBytesSync(sink.builder.takeBytes()); 75 fileSystem.entityForUri(uri).writeAsBytesSync(sink.builder.takeBytes());
60 } 76 }
61 77
62 Future<Null> checkMockSummary(CompilerOptions raw) async { 78 Future<Null> checkMockSummary(CompilerOptions raw) async {
63 var processed = new ProcessedOptions(raw); 79 var processed = new ProcessedOptions(raw);
64 var sdkSummary = await processed.sdkSummaryProgram; 80 var sdkSummary = await processed.loadSdkSummary(new CanonicalName.root());
65 expect(sdkSummary.libraries.single.importUri, 81 expect(sdkSummary.libraries.single.importUri,
66 mockSummary.libraries.single.importUri); 82 mockSummary.libraries.single.importUri);
67 } 83 }
68 84
69 test_getUriTranslator_explicitPackagesFile() async { 85 test_getUriTranslator_explicitPackagesFile() async {
70 // This .packages file should be ignored. 86 // This .packages file should be ignored.
71 fileSystem 87 fileSystem
72 .entityForUri(Uri.parse('file:///.packages')) 88 .entityForUri(Uri.parse('file:///.packages'))
73 .writeAsStringSync('foo:bar\n'); 89 .writeAsStringSync('foo:bar\n');
74 // This one should be used. 90 // This one should be used.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 fileSystem 122 fileSystem
107 .entityForUri(Uri.parse('file:///.packages')) 123 .entityForUri(Uri.parse('file:///.packages'))
108 .writeAsStringSync('foo:bar\n'); 124 .writeAsStringSync('foo:bar\n');
109 var raw = new CompilerOptions() 125 var raw = new CompilerOptions()
110 ..fileSystem = fileSystem 126 ..fileSystem = fileSystem
111 ..packagesFileUri = new Uri(); 127 ..packagesFileUri = new Uri();
112 var processed = new ProcessedOptions(raw); 128 var processed = new ProcessedOptions(raw);
113 var uriTranslator = await processed.getUriTranslator(); 129 var uriTranslator = await processed.getUriTranslator();
114 expect(uriTranslator.packages, isEmpty); 130 expect(uriTranslator.packages, isEmpty);
115 } 131 }
132
133 test_validateOptions_root_exists() async {
134 var sdkRoot = Uri.parse('file:///sdk/root/');
135 fileSystem
136 // Note: this test is a bit hackish because the memory file system
137 // doesn't have the notion of directories.
138 .entityForUri(sdkRoot)
139 .writeAsStringSync('\n');
140 fileSystem
141 .entityForUri(sdkRoot.resolve('outline.dill'))
142 .writeAsStringSync('\n');
143
144 var errors = [];
145 var raw = new CompilerOptions()
146 ..sdkRoot = sdkRoot
147 ..fileSystem = fileSystem
148 ..onError = (e) => errors.add(e);
149 var options = new ProcessedOptions(raw);
150 var result = await options.validateOptions();
151 // Note: we check this first so test failures show the cause directly.
152 expect(errors, isEmpty);
153 expect(result, isTrue);
154 }
155
156 test_validateOptions_root_doesnt_exists() async {
157 var sdkRoot = Uri.parse('file:///sdk/root');
158 var errors = [];
159 var raw = new CompilerOptions()
160 ..sdkRoot = sdkRoot
161 ..fileSystem = fileSystem
162 ..onError = (e) => errors.add(e);
163 var options = new ProcessedOptions(raw);
164 expect(await options.validateOptions(), isFalse);
165 expect('${errors.first}', contains("SDK root directory not found"));
166 }
167
168 test_validateOptions_summary_exists() async {
169 var sdkSummary = Uri.parse('file:///sdk/root/outline.dill');
170 fileSystem.entityForUri(sdkSummary).writeAsStringSync('\n');
171
172 var errors = [];
173 var raw = new CompilerOptions()
174 ..sdkSummary = sdkSummary
175 ..fileSystem = fileSystem
176 ..onError = (e) => errors.add(e);
177 var options = new ProcessedOptions(raw);
178 var result = await options.validateOptions();
179 expect(errors, isEmpty);
180 expect(result, isTrue);
181 }
182
183 test_validateOptions_summary_doesnt_exists() async {
184 var sdkSummary = Uri.parse('file:///sdk/root/outline.dill');
185 var errors = [];
186 var raw = new CompilerOptions()
187 ..sdkSummary = sdkSummary
188 ..fileSystem = fileSystem
189 ..onError = (e) => errors.add(e);
190 var options = new ProcessedOptions(raw);
191 expect(await options.validateOptions(), isFalse);
192 expect('${errors.first}', contains("SDK summary not found"));
193 }
194
195 test_validateOptions_inferred_summary_exists() async {
196 var sdkRoot = Uri.parse('file:///sdk/root/');
197 var sdkSummary = Uri.parse('file:///sdk/root/outline.dill');
198 fileSystem.entityForUri(sdkRoot).writeAsStringSync('\n');
199 fileSystem.entityForUri(sdkSummary).writeAsStringSync('\n');
200
201 var errors = [];
202 var raw = new CompilerOptions()
203 ..sdkRoot = sdkRoot
204 ..fileSystem = fileSystem
205 ..onError = (e) => errors.add(e);
206 var options = new ProcessedOptions(raw);
207 var result = await options.validateOptions();
208 expect(errors, isEmpty);
209 expect(result, isTrue);
210 }
211
212 test_validateOptions_inferred_summary_doesnt_exists() async {
213 var sdkRoot = Uri.parse('file:///sdk/root/');
214 var sdkSummary = Uri.parse('file:///sdk/root/outline.dill');
215 fileSystem.entityForUri(sdkRoot).writeAsStringSync('\n');
216 var errors = [];
217 var raw = new CompilerOptions()
218 ..sdkSummary = sdkSummary
219 ..fileSystem = fileSystem
220 ..onError = (e) => errors.add(e);
221 var options = new ProcessedOptions(raw);
222 expect(await options.validateOptions(), isFalse);
223 expect('${errors.first}', contains("SDK summary not found"));
224 }
116 } 225 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698