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

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

Issue 2894283002: Reapply CL: first step for modular support in fasta (Closed)
Patch Set: new changes since first CL Created 3 years, 7 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:analyzer/src/summary/format.dart';
8 import 'package:front_end/compiler_options.dart'; 7 import 'package:front_end/compiler_options.dart';
9 import 'package:front_end/memory_file_system.dart'; 8 import 'package:front_end/memory_file_system.dart';
10 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;
11 import 'package:kernel/binary/ast_to_binary.dart' show BinaryPrinter;
12 import 'package:kernel/kernel.dart' show Program, Library;
13
11 import 'package:test/test.dart'; 14 import 'package:test/test.dart';
12 import 'package:test_reflective_loader/test_reflective_loader.dart'; 15 import 'package:test_reflective_loader/test_reflective_loader.dart';
13 16
14 main() { 17 main() {
15 defineReflectiveSuite(() { 18 defineReflectiveSuite(() {
16 defineReflectiveTests(ProcessedOptionsTest); 19 defineReflectiveTests(ProcessedOptionsTest);
17 }); 20 });
18 } 21 }
19 22
20 @reflectiveTest 23 @reflectiveTest
21 class ProcessedOptionsTest { 24 class ProcessedOptionsTest {
22 final fileSystem = new MemoryFileSystem(Uri.parse('file:///')); 25 final fileSystem = new MemoryFileSystem(Uri.parse('file:///'));
23 26
24 PackageBundleBuilder _mockSdkSummary; 27 Program _mockOutline;
25 28
26 PackageBundleBuilder get mockSdkSummary => _mockSdkSummary ??= 29 Program get mockSummary => _mockOutline ??=
27 new PackageBundleBuilder(apiSignature: 'mock summary signature'); 30 new Program(libraries: [new Library(Uri.parse('file:///a/b.dart'))]);
28
29 Future<Null> checkMockSummary(CompilerOptions raw) async {
30 var processed = new ProcessedOptions(raw);
31 var sdkSummary = await processed.getSdkSummary();
32 expect(sdkSummary.apiSignature, mockSdkSummary.apiSignature);
33 }
34 31
35 test_compileSdk_false() { 32 test_compileSdk_false() {
36 for (var value in [false, true]) { 33 for (var value in [false, true]) {
37 var raw = new CompilerOptions()..compileSdk = value; 34 var raw = new CompilerOptions()..compileSdk = value;
38 var processed = new ProcessedOptions(raw); 35 var processed = new ProcessedOptions(raw);
39 expect(processed.compileSdk, value); 36 expect(processed.compileSdk, value);
40 } 37 }
41 } 38 }
42 39
43 test_fileSystem_noBazelRoots() { 40 test_fileSystem_noBazelRoots() {
44 // When no bazel roots are specified, the filesystem should be passed 41 // When no bazel roots are specified, the filesystem should be passed
45 // through unmodified. 42 // through unmodified.
46 var raw = new CompilerOptions()..fileSystem = fileSystem; 43 var raw = new CompilerOptions()..fileSystem = fileSystem;
47 var processed = new ProcessedOptions(raw); 44 var processed = new ProcessedOptions(raw);
48 expect(processed.fileSystem, same(fileSystem)); 45 expect(processed.fileSystem, same(fileSystem));
49 } 46 }
50 47
51 test_getSdkSummary_sdkLocationProvided_noTrailingSlash() async {
52 var uri = Uri.parse('file:///sdk');
53 writeMockSummaryTo(Uri.parse('$uri/lib/_internal/strong.sum'));
54 checkMockSummary(new CompilerOptions()
55 ..fileSystem = fileSystem
56 ..sdkRoot = uri);
57 }
58
59 test_getSdkSummary_sdkLocationProvided_spec() async {
60 var uri = Uri.parse('file:///sdk');
61 writeMockSummaryTo(Uri.parse('$uri/lib/_internal/spec.sum'));
62 checkMockSummary(new CompilerOptions()
63 ..fileSystem = fileSystem
64 ..strongMode = false
65 ..sdkRoot = uri);
66 }
67
68 test_getSdkSummary_sdkLocationProvided_trailingSlash() async {
69 var uri = Uri.parse('file:///sdk');
70 writeMockSummaryTo(Uri.parse('$uri/lib/_internal/strong.sum'));
71 checkMockSummary(new CompilerOptions()
72 ..fileSystem = fileSystem
73 ..sdkRoot = Uri.parse('$uri/'));
74 }
75
76 test_getSdkSummary_summaryLocationProvided() async { 48 test_getSdkSummary_summaryLocationProvided() async {
77 var uri = Uri.parse('file:///sdkSummary'); 49 var uri = Uri.parse('file:///sdkSummary');
78 writeMockSummaryTo(uri); 50 writeMockSummaryTo(uri);
79 checkMockSummary(new CompilerOptions() 51 checkMockSummary(new CompilerOptions()
80 ..fileSystem = fileSystem 52 ..fileSystem = fileSystem
81 ..sdkSummary = uri); 53 ..sdkSummary = uri);
82 } 54 }
83 55
56 void writeMockSummaryTo(Uri uri) {
57 var sink = new ByteSink();
58 new BinaryPrinter(sink).writeProgramFile(mockSummary);
59 fileSystem.entityForUri(uri).writeAsBytesSync(sink.builder.takeBytes());
60 }
61
62 Future<Null> checkMockSummary(CompilerOptions raw) async {
63 var processed = new ProcessedOptions(raw);
64 var sdkSummary = await processed.sdkSummaryProgram;
65 expect(sdkSummary.libraries.single.importUri,
66 mockSummary.libraries.single.importUri);
67 }
68
84 test_getUriTranslator_explicitPackagesFile() async { 69 test_getUriTranslator_explicitPackagesFile() async {
85 // This .packages file should be ignored. 70 // This .packages file should be ignored.
86 fileSystem 71 fileSystem
87 .entityForUri(Uri.parse('file:///.packages')) 72 .entityForUri(Uri.parse('file:///.packages'))
88 .writeAsStringSync('foo:bar\n'); 73 .writeAsStringSync('foo:bar\n');
89 // This one should be used. 74 // This one should be used.
90 fileSystem 75 fileSystem
91 .entityForUri(Uri.parse('file:///explicit.packages')) 76 .entityForUri(Uri.parse('file:///explicit.packages'))
92 .writeAsStringSync('foo:baz\n'); 77 .writeAsStringSync('foo:baz\n');
93 var raw = new CompilerOptions() 78 var raw = new CompilerOptions()
(...skipping 27 matching lines...) Expand all
121 fileSystem 106 fileSystem
122 .entityForUri(Uri.parse('file:///.packages')) 107 .entityForUri(Uri.parse('file:///.packages'))
123 .writeAsStringSync('foo:bar\n'); 108 .writeAsStringSync('foo:bar\n');
124 var raw = new CompilerOptions() 109 var raw = new CompilerOptions()
125 ..fileSystem = fileSystem 110 ..fileSystem = fileSystem
126 ..packagesFileUri = new Uri(); 111 ..packagesFileUri = new Uri();
127 var processed = new ProcessedOptions(raw); 112 var processed = new ProcessedOptions(raw);
128 var uriTranslator = await processed.getUriTranslator(); 113 var uriTranslator = await processed.getUriTranslator();
129 expect(uriTranslator.packages, isEmpty); 114 expect(uriTranslator.packages, isEmpty);
130 } 115 }
131
132 void writeMockSummaryTo(Uri uri) {
133 fileSystem.entityForUri(uri).writeAsBytesSync(mockSdkSummary.toBuffer());
134 }
135 } 116 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698