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

Side by Side Diff: pkg/front_end/test/fasta/testing/suite.dart

Issue 2939533002: Apply transformations after comparing to golden files. (Closed)
Patch Set: Created 3 years, 6 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 library fasta.testing.suite; 5 library fasta.testing.suite;
6 6
7 import 'dart:async' show Future; 7 import 'dart:async' show Future;
8 8
9 import 'dart:io' show File; 9 import 'dart:io' show File;
10 10
11 import 'dart:convert' show JSON; 11 import 'dart:convert' show JSON;
12 12
13 import 'package:front_end/physical_file_system.dart' show PhysicalFileSystem; 13 import 'package:front_end/physical_file_system.dart' show PhysicalFileSystem;
14 14
15 import 'package:front_end/src/fasta/testing/validating_instrumentation.dart' 15 import 'package:front_end/src/fasta/testing/validating_instrumentation.dart'
16 show ValidatingInstrumentation; 16 show ValidatingInstrumentation;
17 17
18 import 'package:front_end/src/fasta/testing/patched_sdk_location.dart' 18 import 'package:front_end/src/fasta/testing/patched_sdk_location.dart'
19 show computeDartVm, computePatchedSdk; 19 show computeDartVm, computePatchedSdk;
20 20
21 import 'package:kernel/ast.dart' show Program; 21 import 'package:kernel/ast.dart' show Library, Program;
22 22
23 import 'package:testing/testing.dart' 23 import 'package:testing/testing.dart'
24 show 24 show
25 Chain, 25 Chain,
26 ChainContext, 26 ChainContext,
27 ExpectationSet, 27 ExpectationSet,
28 Result, 28 Result,
29 Step, 29 Step,
30 TestDescription, 30 TestDescription,
31 StdioProcess; 31 StdioProcess;
(...skipping 15 matching lines...) Expand all
47 show KernelTarget; 47 show KernelTarget;
48 48
49 import 'package:front_end/src/fasta/dill/dill_target.dart' show DillTarget; 49 import 'package:front_end/src/fasta/dill/dill_target.dart' show DillTarget;
50 50
51 import 'package:kernel/kernel.dart' show loadProgramFromBytes; 51 import 'package:kernel/kernel.dart' show loadProgramFromBytes;
52 52
53 import 'package:kernel/target/targets.dart' show TargetFlags; 53 import 'package:kernel/target/targets.dart' show TargetFlags;
54 54
55 import 'package:kernel/target/vm_fasta.dart' show VmFastaTarget; 55 import 'package:kernel/target/vm_fasta.dart' show VmFastaTarget;
56 56
57 import 'package:kernel/class_hierarchy.dart' show ClassHierarchy;
58
59 import 'package:kernel/core_types.dart' show CoreTypes;
60
57 export 'package:testing/testing.dart' show Chain, runMe; 61 export 'package:testing/testing.dart' show Chain, runMe;
58 62
59 const String STRONG_MODE = " strong mode "; 63 const String STRONG_MODE = " strong mode ";
60 64
61 const String ENABLE_FULL_COMPILE = " full compile "; 65 const String ENABLE_FULL_COMPILE = " full compile ";
62 66
63 const String AST_KIND_INDEX = " AST kind index "; 67 const String AST_KIND_INDEX = " AST kind index ";
64 68
65 const String EXPECTATIONS = ''' 69 const String EXPECTATIONS = '''
66 [ 70 [
(...skipping 16 matching lines...) Expand all
83 87
84 enum AstKind { 88 enum AstKind {
85 Analyzer, 89 Analyzer,
86 Kernel, 90 Kernel,
87 } 91 }
88 92
89 class FastaContext extends ChainContext { 93 class FastaContext extends ChainContext {
90 final TranslateUri uriTranslator; 94 final TranslateUri uriTranslator;
91 final List<Step> steps; 95 final List<Step> steps;
92 final Uri vm; 96 final Uri vm;
97 final Map<Program, KernelTarget> programToTarget = <Program, KernelTarget>{};
93 Uri sdk; 98 Uri sdk;
94 Uri platformUri; 99 Uri platformUri;
95 Uri outlineUri; 100 Uri outlineUri;
96 List<int> outlineBytes; 101 List<int> outlineBytes;
97 102
98 final ExpectationSet expectationSet = 103 final ExpectationSet expectationSet =
99 new ExpectationSet.fromJsonList(JSON.decode(EXPECTATIONS)); 104 new ExpectationSet.fromJsonList(JSON.decode(EXPECTATIONS));
100 105
101 FastaContext( 106 FastaContext(
102 this.vm, 107 this.vm,
103 bool strongMode, 108 bool strongMode,
104 bool updateExpectations, 109 bool updateExpectations,
105 bool updateComments, 110 bool updateComments,
106 bool skipVm, 111 bool skipVm,
107 this.uriTranslator, 112 this.uriTranslator,
108 bool fullCompile, 113 bool fullCompile,
109 AstKind astKind) 114 AstKind astKind)
110 : steps = <Step>[ 115 : steps = <Step>[
111 new Outline(fullCompile, astKind, strongMode, 116 new Outline(fullCompile, astKind, strongMode,
112 updateComments: updateComments), 117 updateComments: updateComments),
113 const Print(), 118 const Print(),
114 new Verify(fullCompile), 119 new Verify(fullCompile),
115 new MatchExpectation( 120 new MatchExpectation(
116 fullCompile 121 fullCompile
117 ? ".${shortenAstKindName(astKind, strongMode)}.expect" 122 ? ".${shortenAstKindName(astKind, strongMode)}.expect"
118 : ".outline.expect", 123 : ".outline.expect",
119 updateExpectations: updateExpectations) 124 updateExpectations: updateExpectations)
120 ] { 125 ] {
121 if (fullCompile && !skipVm) { 126 if (fullCompile && !skipVm) {
127 steps.add(const Transform());
122 steps.add(const WriteDill()); 128 steps.add(const WriteDill());
123 steps.add(const Run()); 129 steps.add(const Run());
124 } 130 }
125 } 131 }
126 132
127 Future ensurePlatformUris() async { 133 Future ensurePlatformUris() async {
128 if (sdk == null) { 134 if (sdk == null) {
129 sdk = await computePatchedSdk(); 135 sdk = await computePatchedSdk();
130 platformUri = sdk.resolve('platform.dill'); 136 platformUri = sdk.resolve('platform.dill');
131 outlineUri = sdk.resolve('outline.dill'); 137 outlineUri = sdk.resolve('outline.dill');
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 bool get isCompiler => fullCompile; 222 bool get isCompiler => fullCompile;
217 223
218 Future<Result<Program>> run( 224 Future<Result<Program>> run(
219 TestDescription description, FastaContext context) async { 225 TestDescription description, FastaContext context) async {
220 // Disable colors to ensure that expectation files are the same across 226 // Disable colors to ensure that expectation files are the same across
221 // platforms and independent of stdin/stderr. 227 // platforms and independent of stdin/stderr.
222 CompilerContext.current.disableColors(); 228 CompilerContext.current.disableColors();
223 Program platformOutline = await context.loadPlatformOutline(); 229 Program platformOutline = await context.loadPlatformOutline();
224 Ticker ticker = new Ticker(); 230 Ticker ticker = new Ticker();
225 DillTarget dillTarget = new DillTarget(ticker, context.uriTranslator, 231 DillTarget dillTarget = new DillTarget(ticker, context.uriTranslator,
226 new VmFastaTarget(new TargetFlags(strongMode: strongMode))); 232 new TestVmFastaTarget(new TargetFlags(strongMode: strongMode)));
227 platformOutline.unbindCanonicalNames(); 233 platformOutline.unbindCanonicalNames();
228 dillTarget.loader.appendLibraries(platformOutline); 234 dillTarget.loader.appendLibraries(platformOutline);
229 // We create a new URI translator to avoid reading plaform libraries from 235 // We create a new URI translator to avoid reading plaform libraries from
230 // file system. 236 // file system.
231 TranslateUri uriTranslator = new TranslateUri( 237 TranslateUri uriTranslator = new TranslateUri(
232 context.uriTranslator.packages, 238 context.uriTranslator.packages,
233 const <String, Uri>{}, 239 const <String, Uri>{},
234 const <String, List<Uri>>{}); 240 const <String, List<Uri>>{});
235 KernelTarget sourceTarget = astKind == AstKind.Analyzer 241 KernelTarget sourceTarget = astKind == AstKind.Analyzer
236 ? new AnalyzerTarget(dillTarget, uriTranslator, strongMode) 242 ? new AnalyzerTarget(dillTarget, uriTranslator, strongMode)
(...skipping 18 matching lines...) Expand all
255 if (updateComments) { 261 if (updateComments) {
256 await instrumentation.fixSource(description.uri, false); 262 await instrumentation.fixSource(description.uri, false);
257 } else { 263 } else {
258 return fail(null, instrumentation.problemsAsString); 264 return fail(null, instrumentation.problemsAsString);
259 } 265 }
260 } 266 }
261 } 267 }
262 } on InputError catch (e, s) { 268 } on InputError catch (e, s) {
263 return fail(null, e.error, s); 269 return fail(null, e.error, s);
264 } 270 }
271 context.programToTarget[p] = sourceTarget;
265 return pass(p); 272 return pass(p);
266 } 273 }
267 } 274 }
275
276 class Transform extends Step<Program, Program, FastaContext> {
277 const Transform();
278
279 String get name => "transform program";
280
281 Future<Result<Program>> run(Program program, FastaContext context) async {
282 KernelTarget sourceTarget = context.programToTarget[program];
283 TestVmFastaTarget backendTarget = sourceTarget.backendTarget;
284 backendTarget.enabled = true;
285 try {
286 if (sourceTarget.loader.coreTypes != null) {
287 sourceTarget.runBuildTransformations();
288 }
289 } finally {
290 backendTarget.enabled = false;
291 }
292 return pass(program);
293 }
294 }
295
296 class TestVmFastaTarget extends VmFastaTarget {
297 bool enabled = false;
298
299 TestVmFastaTarget(TargetFlags flags) : super(flags);
300
301 String get name => "vm_fasta";
302
303 void performModularTransformationsOnLibraries(
304 CoreTypes coreTypes, ClassHierarchy hierarchy, List<Library> libraries,
305 {void logger(String msg)}) {
306 if (enabled) {
307 super.performModularTransformationsOnLibraries(
308 coreTypes, hierarchy, libraries,
309 logger: logger);
310 }
311 }
312
313 void performGlobalTransformations(CoreTypes coreTypes, Program program,
314 {void logger(String msg)}) {
315 if (enabled) {
316 super.performGlobalTransformations(coreTypes, program, logger: logger);
317 }
318 }
319 }
OLDNEW
« no previous file with comments | « pkg/front_end/test/fasta/compile.status ('k') | pkg/front_end/testcases/classes.dart.direct.expect » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698