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

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

Issue 2625533002: Add code to ProcessedOptions to fetch the SDK summary bundle. (Closed)
Patch Set: Created 3 years, 11 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';
6
7 import 'package:analyzer/src/summary/format.dart';
5 import 'package:front_end/compiler_options.dart'; 8 import 'package:front_end/compiler_options.dart';
6 import 'package:front_end/memory_file_system.dart'; 9 import 'package:front_end/memory_file_system.dart';
7 import 'package:front_end/src/base/processed_options.dart'; 10 import 'package:front_end/src/base/processed_options.dart';
8 import 'package:path/path.dart' as pathos; 11 import 'package:path/path.dart' as pathos;
9 import 'package:test/test.dart'; 12 import 'package:test/test.dart';
10 import 'package:test_reflective_loader/test_reflective_loader.dart'; 13 import 'package:test_reflective_loader/test_reflective_loader.dart';
11 14
12 main() { 15 main() {
13 defineReflectiveSuite(() { 16 defineReflectiveSuite(() {
14 defineReflectiveTests(ProcessedOptionsTest); 17 defineReflectiveTests(ProcessedOptionsTest);
15 }); 18 });
16 } 19 }
17 20
18 @reflectiveTest 21 @reflectiveTest
19 class ProcessedOptionsTest { 22 class ProcessedOptionsTest {
20 final fileSystem = new MemoryFileSystem(pathos.posix, Uri.parse('file:///')); 23 final fileSystem = new MemoryFileSystem(pathos.posix, Uri.parse('file:///'));
21 24
25 PackageBundleBuilder _mockSdkSummary;
26
27 PackageBundleBuilder get mockSdkSummary => _mockSdkSummary ??=
28 new PackageBundleBuilder(apiSignature: 'mock summary signature');
29
30 Future<Null> checkMockSummary(CompilerOptions raw) async {
31 var processed = new ProcessedOptions(raw);
32 var sdkSummary = await processed.getSdkSummary();
33 expect(sdkSummary.apiSignature, mockSdkSummary.apiSignature);
34 }
35
22 test_compileSdk_false() { 36 test_compileSdk_false() {
23 for (var value in [false, true]) { 37 for (var value in [false, true]) {
24 var raw = new CompilerOptions()..compileSdk = value; 38 var raw = new CompilerOptions()..compileSdk = value;
25 var processed = new ProcessedOptions(raw); 39 var processed = new ProcessedOptions(raw);
26 expect(processed.compileSdk, value); 40 expect(processed.compileSdk, value);
27 } 41 }
28 } 42 }
29 43
30 test_fileSystem_noBazelRoots() { 44 test_fileSystem_noBazelRoots() {
31 // When no bazel roots are specified, the filesystem should be passed 45 // When no bazel roots are specified, the filesystem should be passed
32 // through unmodified. 46 // through unmodified.
33 var raw = new CompilerOptions()..fileSystem = fileSystem; 47 var raw = new CompilerOptions()..fileSystem = fileSystem;
34 var processed = new ProcessedOptions(raw); 48 var processed = new ProcessedOptions(raw);
35 expect(processed.fileSystem, same(fileSystem)); 49 expect(processed.fileSystem, same(fileSystem));
36 } 50 }
37 51
52 test_getSdkSummary_sdkLocationProvided_noTrailingSlash() async {
53 var uri = Uri.parse('file:///sdk');
54 writeMockSummaryTo(Uri.parse('$uri/lib/_internal/strong.sum'));
55 checkMockSummary(new CompilerOptions()
56 ..fileSystem = fileSystem
57 ..sdkRoot = uri);
58 }
59
60 test_getSdkSummary_sdkLocationProvided_spec() async {
61 var uri = Uri.parse('file:///sdk');
62 writeMockSummaryTo(Uri.parse('$uri/lib/_internal/spec.sum'));
63 checkMockSummary(new CompilerOptions()
64 ..fileSystem = fileSystem
65 ..strongMode = false
66 ..sdkRoot = uri);
67 }
68
69 test_getSdkSummary_sdkLocationProvided_trailingSlash() async {
70 var uri = Uri.parse('file:///sdk');
71 writeMockSummaryTo(Uri.parse('$uri/lib/_internal/strong.sum'));
72 checkMockSummary(new CompilerOptions()
73 ..fileSystem = fileSystem
74 ..sdkRoot = Uri.parse('$uri/'));
75 }
76
77 test_getSdkSummary_summaryLocationProvided() async {
78 var uri = Uri.parse('file:///sdkSummary');
79 writeMockSummaryTo(uri);
80 checkMockSummary(new CompilerOptions()
81 ..fileSystem = fileSystem
82 ..sdkSummary = uri);
83 }
84
38 test_getUriResolver_explicitPackagesFile() async { 85 test_getUriResolver_explicitPackagesFile() async {
39 // This .packages file should be ignored. 86 // This .packages file should be ignored.
40 fileSystem 87 fileSystem
41 .entityForUri(Uri.parse('file:///.packages')) 88 .entityForUri(Uri.parse('file:///.packages'))
42 .writeAsStringSync('foo:bar\n'); 89 .writeAsStringSync('foo:bar\n');
43 // This one should be used. 90 // This one should be used.
44 fileSystem 91 fileSystem
45 .entityForUri(Uri.parse('file:///explicit.packages')) 92 .entityForUri(Uri.parse('file:///explicit.packages'))
46 .writeAsStringSync('foo:baz\n'); 93 .writeAsStringSync('foo:baz\n');
47 var raw = new CompilerOptions() 94 var raw = new CompilerOptions()
(...skipping 27 matching lines...) Expand all
75 fileSystem 122 fileSystem
76 .entityForUri(Uri.parse('file:///.packages')) 123 .entityForUri(Uri.parse('file:///.packages'))
77 .writeAsStringSync('foo:bar\n'); 124 .writeAsStringSync('foo:bar\n');
78 var raw = new CompilerOptions() 125 var raw = new CompilerOptions()
79 ..fileSystem = fileSystem 126 ..fileSystem = fileSystem
80 ..packagesFileUri = new Uri(); 127 ..packagesFileUri = new Uri();
81 var processed = new ProcessedOptions(raw); 128 var processed = new ProcessedOptions(raw);
82 var uriResolver = await processed.getUriResolver(); 129 var uriResolver = await processed.getUriResolver();
83 expect(uriResolver.packages, isEmpty); 130 expect(uriResolver.packages, isEmpty);
84 } 131 }
132
133 void writeMockSummaryTo(Uri uri) {
134 fileSystem.entityForUri(uri).writeAsBytesSync(mockSdkSummary.toBuffer());
135 }
85 } 136 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698