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

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

Issue 2986303003: Switch FE to use the libraries.json format. (Closed)
Patch Set: fix issues found on bots 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';
11 import 'package:front_end/src/fasta/fasta_codes.dart'; 12 import 'package:front_end/src/fasta/fasta_codes.dart';
12 import 'package:kernel/binary/ast_to_binary.dart' show BinaryPrinter; 13 import 'package:kernel/binary/ast_to_binary.dart' show BinaryPrinter;
13 import 'package:kernel/kernel.dart' show Program, Library, CanonicalName; 14 import 'package:kernel/kernel.dart' show Program, Library, CanonicalName;
14 import 'package:package_config/packages.dart' show Packages; 15 import 'package:package_config/packages.dart' show Packages;
15 16
16 import 'package:test/test.dart'; 17 import 'package:test/test.dart';
17 import 'package:test_reflective_loader/test_reflective_loader.dart'; 18 import 'package:test_reflective_loader/test_reflective_loader.dart';
18 19
19 main() { 20 main() {
20 defineReflectiveSuite(() { 21 CompilerContext.runWithDefaultOptions((_) {
21 defineReflectiveTests(ProcessedOptionsTest); 22 defineReflectiveSuite(() {
23 defineReflectiveTests(ProcessedOptionsTest);
24 });
22 }); 25 });
23 } 26 }
24 27
25 @reflectiveTest 28 @reflectiveTest
26 class ProcessedOptionsTest { 29 class ProcessedOptionsTest {
27 MemoryFileSystem fileSystem = new MemoryFileSystem(Uri.parse('file:///')); 30 MemoryFileSystem fileSystem = new MemoryFileSystem(Uri.parse('file:///'));
28 31
29 Program _mockOutline; 32 Program _mockOutline;
30 33
31 Program get mockSummary => _mockOutline ??= 34 Program get mockSummary => _mockOutline ??=
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 fileSystem.entityForUri(uri).writeAsBytesSync(sink.builder.takeBytes()); 80 fileSystem.entityForUri(uri).writeAsBytesSync(sink.builder.takeBytes());
78 } 81 }
79 82
80 Future<Null> checkMockSummary(CompilerOptions raw) async { 83 Future<Null> checkMockSummary(CompilerOptions raw) async {
81 var processed = new ProcessedOptions(raw); 84 var processed = new ProcessedOptions(raw);
82 var sdkSummary = await processed.loadSdkSummary(new CanonicalName.root()); 85 var sdkSummary = await processed.loadSdkSummary(new CanonicalName.root());
83 expect(sdkSummary.libraries.single.importUri, 86 expect(sdkSummary.libraries.single.importUri,
84 mockSummary.libraries.single.importUri); 87 mockSummary.libraries.single.importUri);
85 } 88 }
86 89
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
87 checkPackageExpansion( 142 checkPackageExpansion(
88 String packageName, String packageDir, Packages packages) { 143 String packageName, String packageDir, Packages packages) {
89 var input = Uri.parse('package:$packageName/a.dart'); 144 var input = Uri.parse('package:$packageName/a.dart');
90 var expected = Uri.parse('file:///$packageDir/a.dart'); 145 var expected = Uri.parse('file:///$packageDir/a.dart');
91 expect(packages.resolve(input), expected); 146 expect(packages.resolve(input), expected);
92 } 147 }
93 148
94 test_getUriTranslator_explicitPackagesFile() async { 149 test_getUriTranslator_explicitPackagesFile() async {
95 // This .packages file should be ignored. 150 // This .packages file should be ignored.
96 fileSystem 151 fileSystem
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 var index = messageTemplate.indexOf('#'); 446 var index = messageTemplate.indexOf('#');
392 var prefix = messageTemplate.substring(0, index - 1); 447 var prefix = messageTemplate.substring(0, index - 1);
393 448
394 // Check that the prefix is not empty and that it contains more than one 449 // Check that the prefix is not empty and that it contains more than one
395 // word. 450 // word.
396 expect(prefix.length > 0, isTrue); 451 expect(prefix.length > 0, isTrue);
397 expect(prefix.contains(' '), isTrue); 452 expect(prefix.contains(' '), isTrue);
398 return prefix; 453 return prefix;
399 } 454 }
400 } 455 }
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