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

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

Issue 2993113003: Revert "Switch FE to use the libraries.json format." (Closed)
Patch Set: Created 3 years, 4 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:front_end/src/fasta/compiler_context.dart';
12 import 'package:front_end/src/fasta/fasta_codes.dart'; 11 import 'package:front_end/src/fasta/fasta_codes.dart';
13 import 'package:kernel/binary/ast_to_binary.dart' show BinaryPrinter; 12 import 'package:kernel/binary/ast_to_binary.dart' show BinaryPrinter;
14 import 'package:kernel/kernel.dart' show Program, Library, CanonicalName; 13 import 'package:kernel/kernel.dart' show Program, Library, CanonicalName;
15 import 'package:package_config/packages.dart' show Packages; 14 import 'package:package_config/packages.dart' show Packages;
16 15
17 import 'package:test/test.dart'; 16 import 'package:test/test.dart';
18 import 'package:test_reflective_loader/test_reflective_loader.dart'; 17 import 'package:test_reflective_loader/test_reflective_loader.dart';
19 18
20 main() { 19 main() {
21 CompilerContext.runWithDefaultOptions((_) { 20 defineReflectiveSuite(() {
22 defineReflectiveSuite(() { 21 defineReflectiveTests(ProcessedOptionsTest);
23 defineReflectiveTests(ProcessedOptionsTest);
24 });
25 }); 22 });
26 } 23 }
27 24
28 @reflectiveTest 25 @reflectiveTest
29 class ProcessedOptionsTest { 26 class ProcessedOptionsTest {
30 MemoryFileSystem fileSystem = new MemoryFileSystem(Uri.parse('file:///')); 27 MemoryFileSystem fileSystem = new MemoryFileSystem(Uri.parse('file:///'));
31 28
32 Program _mockOutline; 29 Program _mockOutline;
33 30
34 Program get mockSummary => _mockOutline ??= 31 Program get mockSummary => _mockOutline ??=
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 fileSystem.entityForUri(uri).writeAsBytesSync(sink.builder.takeBytes()); 77 fileSystem.entityForUri(uri).writeAsBytesSync(sink.builder.takeBytes());
81 } 78 }
82 79
83 Future<Null> checkMockSummary(CompilerOptions raw) async { 80 Future<Null> checkMockSummary(CompilerOptions raw) async {
84 var processed = new ProcessedOptions(raw); 81 var processed = new ProcessedOptions(raw);
85 var sdkSummary = await processed.loadSdkSummary(new CanonicalName.root()); 82 var sdkSummary = await processed.loadSdkSummary(new CanonicalName.root());
86 expect(sdkSummary.libraries.single.importUri, 83 expect(sdkSummary.libraries.single.importUri,
87 mockSummary.libraries.single.importUri); 84 mockSummary.libraries.single.importUri);
88 } 85 }
89 86
90 test_getUriTranslator_explicitLibrariesSpec() async {
91 fileSystem
92 .entityForUri(Uri.parse('file:///.packages'))
93 .writeAsStringSync('');
94 fileSystem
95 .entityForUri(Uri.parse('file:///libraries.json'))
96 .writeAsStringSync('{"vm":{"libraries":{"foo":{"uri":"bar.dart"}}}}');
97 var raw = new CompilerOptions()
98 ..packagesFileUri = Uri.parse('file:///.packages')
99 ..fileSystem = fileSystem
100 ..librariesSpecificationUri = Uri.parse('file:///libraries.json');
101 var processed = new ProcessedOptions(raw);
102 var uriTranslator = await processed.getUriTranslator();
103 expect(uriTranslator.dartLibraries.libraryInfoFor('foo').uri.path,
104 '/bar.dart');
105 }
106
107 test_getUriTranslator_inferredLibrariesSpec() async {
108 fileSystem
109 .entityForUri(Uri.parse('file:///.packages'))
110 .writeAsStringSync('');
111 fileSystem
112 .entityForUri(Uri.parse('file:///mysdk/lib/libraries.json'))
113 .writeAsStringSync('{"vm":{"libraries":{"foo":{"uri":"bar.dart"}}}}');
114 var raw = new CompilerOptions()
115 ..fileSystem = fileSystem
116 ..packagesFileUri = Uri.parse('file:///.packages')
117 ..compileSdk = true
118 ..sdkRoot = Uri.parse('file:///mysdk/');
119 var processed = new ProcessedOptions(raw);
120 var uriTranslator = await processed.getUriTranslator();
121 expect(uriTranslator.dartLibraries.libraryInfoFor('foo').uri.path,
122 '/mysdk/lib/bar.dart');
123 }
124
125 test_getUriTranslator_notInferredLibrariesSpec() async {
126 fileSystem
127 .entityForUri(Uri.parse('file:///.packages'))
128 .writeAsStringSync('');
129 fileSystem
130 .entityForUri(Uri.parse('file:///mysdk/lib/libraries.json'))
131 .writeAsStringSync('{"vm":{"libraries":{"foo":{"uri":"bar.dart"}}}}');
132 var raw = new CompilerOptions()
133 ..fileSystem = fileSystem
134 ..packagesFileUri = Uri.parse('file:///.packages')
135 ..compileSdk = false // libraries.json is only inferred if true
136 ..sdkRoot = Uri.parse('file:///mysdk/');
137 var processed = new ProcessedOptions(raw);
138 var uriTranslator = await processed.getUriTranslator();
139 expect(uriTranslator.dartLibraries.libraryInfoFor('foo'), isNull);
140 }
141
142 checkPackageExpansion( 87 checkPackageExpansion(
143 String packageName, String packageDir, Packages packages) { 88 String packageName, String packageDir, Packages packages) {
144 var input = Uri.parse('package:$packageName/a.dart'); 89 var input = Uri.parse('package:$packageName/a.dart');
145 var expected = Uri.parse('file:///$packageDir/a.dart'); 90 var expected = Uri.parse('file:///$packageDir/a.dart');
146 expect(packages.resolve(input), expected); 91 expect(packages.resolve(input), expected);
147 } 92 }
148 93
149 test_getUriTranslator_explicitPackagesFile() async { 94 test_getUriTranslator_explicitPackagesFile() async {
150 // This .packages file should be ignored. 95 // This .packages file should be ignored.
151 fileSystem 96 fileSystem
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 var index = messageTemplate.indexOf('#'); 391 var index = messageTemplate.indexOf('#');
447 var prefix = messageTemplate.substring(0, index - 1); 392 var prefix = messageTemplate.substring(0, index - 1);
448 393
449 // Check that the prefix is not empty and that it contains more than one 394 // Check that the prefix is not empty and that it contains more than one
450 // word. 395 // word.
451 expect(prefix.length > 0, isTrue); 396 expect(prefix.length > 0, isTrue);
452 expect(prefix.contains(' '), isTrue); 397 expect(prefix.contains(' '), isTrue);
453 return prefix; 398 return prefix;
454 } 399 }
455 } 400 }
OLDNEW
« no previous file with comments | « pkg/front_end/test/src/base/libraries_specification_test.dart ('k') | pkg/front_end/test/src/incremental/file_state_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698