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

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

Issue 2980033004: Throw if there is no compiler context available (Closed)
Patch Set: Created 3 years, 5 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.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 ///
11 /// Input files may contain markers to turn on flags that configure this 11 /// Input files may contain markers to turn on flags that configure this
12 /// runner. Currently only the following marker is recognized: 12 /// runner. Currently only the following marker is recognized:
13 /// @@SHOW_CORE_LIBRARIES@@ - whether to check for retained information from 13 /// @@SHOW_CORE_LIBRARIES@@ - whether to check for retained information from
14 /// the core libraries. By default this runner only checks for members of 14 /// the core libraries. By default this runner only checks for members of
15 /// pkg/front_end/testcases/shaker/lib/lib.dart. 15 /// pkg/front_end/testcases/shaker/lib/lib.dart.
16 library fasta.test.shaker_test; 16 library fasta.test.shaker_test;
17 17
18 import 'dart:async' show Future; 18 import 'dart:async' show Future;
19 import 'dart:convert' show JSON; 19 import 'dart:convert' show JSON;
20 import 'dart:io' show File; 20 import 'dart:io' show File;
21 21
22 export 'package:testing/testing.dart' show Chain, runMe; 22 export 'package:testing/testing.dart' show Chain, runMe;
23 import 'package:front_end/physical_file_system.dart'; 23 import 'package:front_end/physical_file_system.dart';
24 import 'package:front_end/src/fasta/compiler_command_line.dart';
24 import 'package:front_end/src/fasta/dill/dill_target.dart' show DillTarget; 25 import 'package:front_end/src/fasta/dill/dill_target.dart' show DillTarget;
25 import 'package:front_end/src/fasta/deprecated_problems.dart' 26 import 'package:front_end/src/fasta/deprecated_problems.dart'
26 show deprecated_InputError; 27 show deprecated_InputError;
27 import 'package:front_end/src/fasta/kernel/kernel_outline_shaker.dart'; 28 import 'package:front_end/src/fasta/kernel/kernel_outline_shaker.dart';
28 import 'package:front_end/src/fasta/kernel/kernel_target.dart' 29 import 'package:front_end/src/fasta/kernel/kernel_target.dart'
29 show KernelTarget; 30 show KernelTarget;
30 import 'package:front_end/src/fasta/kernel/verifier.dart' show verifyProgram; 31 import 'package:front_end/src/fasta/kernel/verifier.dart' show verifyProgram;
31 import 'package:front_end/src/fasta/testing/kernel_chain.dart' show runDiff; 32 import 'package:front_end/src/fasta/testing/kernel_chain.dart' show runDiff;
32 import 'package:front_end/src/fasta/testing/patched_sdk_location.dart'; 33 import 'package:front_end/src/fasta/testing/patched_sdk_location.dart';
33 import 'package:front_end/src/fasta/ticker.dart' show Ticker; 34 import 'package:front_end/src/fasta/ticker.dart' show Ticker;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 } 91 }
91 92
92 /// Step that extracts the test-specific options and builds the program without 93 /// Step that extracts the test-specific options and builds the program without
93 /// applying tree-shaking. 94 /// applying tree-shaking.
94 class BuildProgram 95 class BuildProgram
95 extends Step<TestDescription, _IntermediateData, TreeShakerContext> { 96 extends Step<TestDescription, _IntermediateData, TreeShakerContext> {
96 const BuildProgram(); 97 const BuildProgram();
97 String get name => "build program"; 98 String get name => "build program";
98 Future<Result<_IntermediateData>> run( 99 Future<Result<_IntermediateData>> run(
99 TestDescription description, TreeShakerContext context) async { 100 TestDescription description, TreeShakerContext context) async {
100 try { 101 return await CompilerCommandLine.withGlobalOptions("", [""], (_) async {
101 var platformOutline = context.loadPlatformOutline(); 102 try {
102 platformOutline.unbindCanonicalNames(); 103 var platformOutline = context.loadPlatformOutline();
103 var dillTarget = new DillTarget( 104 platformOutline.unbindCanonicalNames();
104 new Ticker(isVerbose: false), 105 var dillTarget = new DillTarget(
105 context.uriTranslator, 106 new Ticker(isVerbose: false),
106 new VmFastaTarget(new TargetFlags(strongMode: false))); 107 context.uriTranslator,
107 dillTarget.loader.appendLibraries(platformOutline); 108 new VmFastaTarget(new TargetFlags(strongMode: false)));
108 var sourceTarget = new KernelTarget( 109 dillTarget.loader.appendLibraries(platformOutline);
109 PhysicalFileSystem.instance, dillTarget, context.uriTranslator); 110 var sourceTarget = new KernelTarget(
110 await dillTarget.buildOutlines(); 111 PhysicalFileSystem.instance, dillTarget, context.uriTranslator);
112 await dillTarget.buildOutlines();
111 113
112 var inputUri = description.uri; 114 var inputUri = description.uri;
113 var libUri = inputUri.resolve('lib/lib.dart'); 115 var libUri = inputUri.resolve('lib/lib.dart');
114 sourceTarget.read(libUri); 116 sourceTarget.read(libUri);
115 sourceTarget.read(inputUri); 117 sourceTarget.read(inputUri);
116 var contents = new File.fromUri(inputUri).readAsStringSync(); 118 var contents = new File.fromUri(inputUri).readAsStringSync();
117 var showCoreLibraries = contents.contains("@@SHOW_CORE_LIBRARIES@@"); 119 var showCoreLibraries = contents.contains("@@SHOW_CORE_LIBRARIES@@");
118 await sourceTarget.buildOutlines(); 120 await sourceTarget.buildOutlines();
119 var program = await sourceTarget.buildProgram(); 121 var program = await sourceTarget.buildProgram();
120 bool isIncluded(Uri uri) => !_isTreeShaken(uri); 122 bool isIncluded(Uri uri) => !_isTreeShaken(uri);
121 trimProgram(program, isIncluded); 123 trimProgram(program, isIncluded);
122 return pass(new _IntermediateData(inputUri, program, showCoreLibraries)); 124 return pass(
123 } on deprecated_InputError catch (e, s) { 125 new _IntermediateData(inputUri, program, showCoreLibraries));
124 return fail(null, e.error, s); 126 } on deprecated_InputError catch (e, s) {
125 } 127 return fail(null, e.error, s);
128 }
129 });
126 } 130 }
127 } 131 }
128 132
129 /// Intermediate result from the testing chain. 133 /// Intermediate result from the testing chain.
130 class _IntermediateData { 134 class _IntermediateData {
131 /// The input URI provided to the test. 135 /// The input URI provided to the test.
132 final Uri uri; 136 final Uri uri;
133 137
134 /// Program built by [BuildProgram]. 138 /// Program built by [BuildProgram].
135 final Program program; 139 final Program program;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 } 223 }
220 224
221 /// A special library used only to test the shaker. The suite above will 225 /// A special library used only to test the shaker. The suite above will
222 /// tree-shake the contents of this library. 226 /// tree-shake the contents of this library.
223 const _specialLibraryPath = 'pkg/front_end/testcases/shaker/lib/lib.dart'; 227 const _specialLibraryPath = 'pkg/front_end/testcases/shaker/lib/lib.dart';
224 228
225 /// Tree-shake dart:* libraries and the library under [_specialLibraryPath]. 229 /// Tree-shake dart:* libraries and the library under [_specialLibraryPath].
226 bool _isTreeShaken(Uri uri) => 230 bool _isTreeShaken(Uri uri) =>
227 uri.isScheme('dart') || 231 uri.isScheme('dart') ||
228 Uri.base.resolveUri(uri).path.endsWith(_specialLibraryPath); 232 Uri.base.resolveUri(uri).path.endsWith(_specialLibraryPath);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698