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

Side by Side Diff: pkg/front_end/test/fasta/shaker_test.dart

Issue 3011663002: Restructure outline shaker tests. (Closed)
Patch Set: Created 3 years, 3 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
« no previous file with comments | « no previous file | pkg/front_end/testcases/shaker/classes_in_signatures.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.md file. 3 // BSD-style license that can be found in the LICENSE.md file.
4 4
5 /// Tests basic functionality of the API tree-shaker. 5 /// Tests basic functionality of the API tree-shaker.
6 /// 6 ///
7 /// Each input file is built and tree-shaken, then we check that the set of 7 /// Each input file is built and tree-shaken, then we check that the set of
8 /// libraries, classes, and members that are retained match those declared in an 8 /// libraries, classes, and members that are retained match those declared in an
9 /// expectations file. 9 /// expectations file.
10 /// 10 ///
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 platformOutline.unbindCanonicalNames(); 101 platformOutline.unbindCanonicalNames();
102 var uriTranslator = await context.options.getUriTranslator(); 102 var uriTranslator = await context.options.getUriTranslator();
103 var dillTarget = new DillTarget(context.options.ticker, uriTranslator, 103 var dillTarget = new DillTarget(context.options.ticker, uriTranslator,
104 new VmFastaTarget(new TargetFlags(strongMode: false))); 104 new VmFastaTarget(new TargetFlags(strongMode: false)));
105 dillTarget.loader.appendLibraries(platformOutline); 105 dillTarget.loader.appendLibraries(platformOutline);
106 var sourceTarget = new KernelTarget( 106 var sourceTarget = new KernelTarget(
107 context.options.fileSystem, false, dillTarget, uriTranslator); 107 context.options.fileSystem, false, dillTarget, uriTranslator);
108 await dillTarget.buildOutlines(); 108 await dillTarget.buildOutlines();
109 109
110 var inputUri = description.uri; 110 var inputUri = description.uri;
111 var libUri = inputUri.resolve('lib/lib.dart');
112 sourceTarget.read(libUri);
113 sourceTarget.read(inputUri); 111 sourceTarget.read(inputUri);
114 var contents = new File.fromUri(inputUri).readAsStringSync(); 112 var contents = new File.fromUri(inputUri).readAsStringSync();
115 var showCoreLibraries = contents.contains("@@SHOW_CORE_LIBRARIES@@"); 113 var showCoreLibraries = contents.contains("@@SHOW_CORE_LIBRARIES@@");
116 await sourceTarget.buildOutlines(); 114 await sourceTarget.buildOutlines();
117 var program = await sourceTarget.buildProgram(); 115 var program = await sourceTarget.buildProgram();
118 bool isIncluded(Uri uri) => !_isTreeShaken(uri); 116 bool isIncluded(Uri uri) => uri == inputUri;
119 trimProgram(program, isIncluded); 117 trimProgram(program, isIncluded);
120 return pass( 118 return pass(
121 new _IntermediateData(inputUri, program, showCoreLibraries)); 119 new _IntermediateData(inputUri, program, showCoreLibraries));
122 } on deprecated_InputError catch (e, s) { 120 } on deprecated_InputError catch (e, s) {
123 return fail(null, e.error, s); 121 return fail(null, e.error, s);
124 } 122 }
125 }); 123 });
126 } 124 }
127 } 125 }
128 126
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 return new Result<String>( 159 return new Result<String>(
162 null, context.expectationSet["VerificationError"], errors, null); 160 null, context.expectationSet["VerificationError"], errors, null);
163 } 161 }
164 162
165 // Build a text representation of what we expect to be retained. 163 // Build a text representation of what we expect to be retained.
166 var buffer = new StringBuffer(); 164 var buffer = new StringBuffer();
167 buffer.writeln('DO NOT EDIT -- this file is autogenerated ---'); 165 buffer.writeln('DO NOT EDIT -- this file is autogenerated ---');
168 buffer.writeln('Tree-shaker preserved the following:'); 166 buffer.writeln('Tree-shaker preserved the following:');
169 for (var library in program.libraries) { 167 for (var library in program.libraries) {
170 var importUri = library.importUri; 168 var importUri = library.importUri;
171 if (!_isTreeShaken(importUri)) continue; 169 if (importUri == entryUri) continue;
172 if (importUri.isScheme('dart') && !data.showCoreLibraries) continue; 170 if (importUri.isScheme('dart') && !data.showCoreLibraries) continue;
173 String uri = relativizeUri(library.importUri); 171 String uri = relativizeUri(library.importUri);
174 buffer.writeln('\nlibrary $uri:'); 172 buffer.writeln('\nlibrary $uri:');
175 for (var member in library.members) { 173 for (var member in library.members) {
176 buffer.writeln(' - member ${member.name}'); 174 buffer.writeln(' - member ${member.name}');
177 } 175 }
178 for (var typedef_ in library.typedefs) { 176 for (var typedef_ in library.typedefs) {
179 buffer.writeln(' - typedef ${typedef_.name}'); 177 buffer.writeln(' - typedef ${typedef_.name}');
180 } 178 }
181 for (var cls in library.classes) { 179 for (var cls in library.classes) {
(...skipping 28 matching lines...) Expand all
210 if (updateExpectations) { 208 if (updateExpectations) {
211 expectedFile.writeAsStringSync(actualResult); 209 expectedFile.writeAsStringSync(actualResult);
212 return pass(actualResult); 210 return pass(actualResult);
213 } else { 211 } else {
214 return fail(actualResult, """ 212 return fail(actualResult, """
215 Please create file ${expectedFile.path} with this content: 213 Please create file ${expectedFile.path} with this content:
216 $buffer"""); 214 $buffer""");
217 } 215 }
218 } 216 }
219 } 217 }
220
221 /// A special library used only to test the shaker. The suite above will
222 /// tree-shake the contents of this library.
223 const _specialLibraryPath = 'pkg/front_end/testcases/shaker/lib/lib.dart';
224
225 /// Tree-shake dart:* libraries and the library under [_specialLibraryPath].
226 bool _isTreeShaken(Uri uri) =>
227 uri.isScheme('dart') ||
228 Uri.base.resolveUri(uri).path.endsWith(_specialLibraryPath);
OLDNEW
« no previous file with comments | « no previous file | pkg/front_end/testcases/shaker/classes_in_signatures.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698