OLD | NEW |
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 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 import 'package:kernel/core_types.dart' show CoreTypes; | 61 import 'package:kernel/core_types.dart' show CoreTypes; |
62 | 62 |
63 export 'package:testing/testing.dart' show Chain, runMe; | 63 export 'package:testing/testing.dart' show Chain, runMe; |
64 | 64 |
65 const String STRONG_MODE = " strong mode "; | 65 const String STRONG_MODE = " strong mode "; |
66 | 66 |
67 const String ENABLE_FULL_COMPILE = " full compile "; | 67 const String ENABLE_FULL_COMPILE = " full compile "; |
68 | 68 |
69 const String AST_KIND_INDEX = " AST kind index "; | 69 const String AST_KIND_INDEX = " AST kind index "; |
70 | 70 |
71 const String SKIP_KERNEL_GENERATION = " skip kernel generation "; | |
72 | |
73 const String SKIP_RESOLUTION = " skip resolution "; | |
74 | |
75 const String EXPECTATIONS = ''' | 71 const String EXPECTATIONS = ''' |
76 [ | 72 [ |
77 { | 73 { |
78 "name": "VerificationError", | 74 "name": "VerificationError", |
79 "group": "Fail" | 75 "group": "Fail" |
80 } | 76 } |
81 ] | 77 ] |
82 '''; | 78 '''; |
83 | 79 |
84 String shortenAstKindName(AstKind astKind, bool strongMode) { | 80 String generateExpectationName(bool strongMode) { |
85 switch (astKind) { | 81 return strongMode ? "strong" : "direct"; |
86 case AstKind.Analyzer: | |
87 return strongMode ? "dartk-strong" : "dartk"; | |
88 case AstKind.Kernel: | |
89 return strongMode ? "strong" : "direct"; | |
90 } | |
91 throw "Unknown AST kind: $astKind"; | |
92 } | 82 } |
93 | 83 |
94 enum AstKind { | 84 enum AstKind { |
95 Analyzer, | 85 Analyzer, |
96 Kernel, | 86 Kernel, |
97 } | 87 } |
98 | 88 |
99 class FastaContext extends ChainContext { | 89 class FastaContext extends ChainContext { |
100 final UriTranslatorImpl uriTranslator; | 90 final UriTranslatorImpl uriTranslator; |
101 final List<Step> steps; | 91 final List<Step> steps; |
102 final Uri vm; | 92 final Uri vm; |
103 final Map<Program, KernelTarget> programToTarget = <Program, KernelTarget>{}; | 93 final Map<Program, KernelTarget> programToTarget = <Program, KernelTarget>{}; |
104 Uri sdk; | 94 Uri sdk; |
105 Uri platformUri; | 95 Uri platformUri; |
106 Uri outlineUri; | 96 Uri outlineUri; |
107 Program outline; | 97 Program outline; |
108 | 98 |
109 final ExpectationSet expectationSet = | 99 final ExpectationSet expectationSet = |
110 new ExpectationSet.fromJsonList(JSON.decode(EXPECTATIONS)); | 100 new ExpectationSet.fromJsonList(JSON.decode(EXPECTATIONS)); |
111 | 101 |
112 FastaContext( | 102 FastaContext( |
113 this.vm, | 103 this.vm, |
114 bool strongMode, | 104 bool strongMode, |
115 bool updateExpectations, | 105 bool updateExpectations, |
116 bool updateComments, | 106 bool updateComments, |
117 bool skipVm, | 107 bool skipVm, |
118 bool generateKernel, | |
119 bool doResolution, | |
120 this.uriTranslator, | 108 this.uriTranslator, |
121 bool fullCompile, | 109 bool fullCompile, |
122 AstKind astKind) | 110 AstKind astKind) |
123 : steps = <Step>[ | 111 : steps = <Step>[ |
124 new Outline( | 112 new Outline(fullCompile, astKind, strongMode, |
125 fullCompile, astKind, strongMode, generateKernel, doResolution, | |
126 updateComments: updateComments), | 113 updateComments: updateComments), |
127 const Print(), | 114 const Print(), |
128 new Verify(fullCompile) | 115 new Verify(fullCompile) |
129 ] { | 116 ] { |
130 if (generateKernel) { | 117 if (astKind != AstKind.Analyzer) { |
131 steps.add(new MatchExpectation( | 118 steps.add(new MatchExpectation( |
132 fullCompile | 119 fullCompile |
133 ? ".${shortenAstKindName(astKind, strongMode)}.expect" | 120 ? ".${generateExpectationName(strongMode)}.expect" |
134 : ".outline.expect", | 121 : ".outline.expect", |
135 updateExpectations: updateExpectations)); | 122 updateExpectations: updateExpectations)); |
136 if (fullCompile && !skipVm) { | 123 if (fullCompile && !skipVm) { |
137 steps.add(const Transform()); | 124 steps.add(const Transform()); |
138 steps.add(const WriteDill()); | 125 steps.add(const WriteDill()); |
139 steps.add(const Run()); | 126 steps.add(const Run()); |
140 } | 127 } |
141 } | 128 } |
142 } | 129 } |
143 | 130 |
(...skipping 18 matching lines...) Expand all Loading... |
162 Chain suite, Map<String, String> environment) async { | 149 Chain suite, Map<String, String> environment) async { |
163 Uri sdk = await computePatchedSdk(); | 150 Uri sdk = await computePatchedSdk(); |
164 Uri vm = computeDartVm(sdk); | 151 Uri vm = computeDartVm(sdk); |
165 Uri packages = Uri.base.resolve(".packages"); | 152 Uri packages = Uri.base.resolve(".packages"); |
166 UriTranslator uriTranslator = await UriTranslatorImpl | 153 UriTranslator uriTranslator = await UriTranslatorImpl |
167 .parse(PhysicalFileSystem.instance, sdk, packages: packages); | 154 .parse(PhysicalFileSystem.instance, sdk, packages: packages); |
168 bool strongMode = environment.containsKey(STRONG_MODE); | 155 bool strongMode = environment.containsKey(STRONG_MODE); |
169 bool updateExpectations = environment["updateExpectations"] == "true"; | 156 bool updateExpectations = environment["updateExpectations"] == "true"; |
170 bool updateComments = environment["updateComments"] == "true"; | 157 bool updateComments = environment["updateComments"] == "true"; |
171 bool skipVm = environment["skipVm"] == "true"; | 158 bool skipVm = environment["skipVm"] == "true"; |
172 bool generateKernel = !environment.containsKey(SKIP_KERNEL_GENERATION); | |
173 bool doResolution = !environment.containsKey(SKIP_RESOLUTION); | |
174 String astKindString = environment[AST_KIND_INDEX]; | 159 String astKindString = environment[AST_KIND_INDEX]; |
175 AstKind astKind = | 160 AstKind astKind = |
176 astKindString == null ? null : AstKind.values[int.parse(astKindString)]; | 161 astKindString == null ? null : AstKind.values[int.parse(astKindString)]; |
177 return new FastaContext( | 162 return new FastaContext( |
178 vm, | 163 vm, |
179 strongMode, | 164 strongMode, |
180 updateExpectations, | 165 updateExpectations, |
181 updateComments, | 166 updateComments, |
182 skipVm, | 167 skipVm, |
183 generateKernel, | |
184 doResolution, | |
185 uriTranslator, | 168 uriTranslator, |
186 environment.containsKey(ENABLE_FULL_COMPILE), | 169 environment.containsKey(ENABLE_FULL_COMPILE), |
187 astKind); | 170 astKind); |
188 } | 171 } |
189 } | 172 } |
190 | 173 |
191 class Run extends Step<Uri, int, FastaContext> { | 174 class Run extends Step<Uri, int, FastaContext> { |
192 const Run(); | 175 const Run(); |
193 | 176 |
194 String get name => "run"; | 177 String get name => "run"; |
(...skipping 24 matching lines...) Expand all Loading... |
219 } | 202 } |
220 } | 203 } |
221 | 204 |
222 class Outline extends Step<TestDescription, Program, FastaContext> { | 205 class Outline extends Step<TestDescription, Program, FastaContext> { |
223 final bool fullCompile; | 206 final bool fullCompile; |
224 | 207 |
225 final AstKind astKind; | 208 final AstKind astKind; |
226 | 209 |
227 final bool strongMode; | 210 final bool strongMode; |
228 | 211 |
229 final bool generateKernel; | |
230 | |
231 final bool doResolution; | |
232 | |
233 const Outline(this.fullCompile, this.astKind, this.strongMode, | 212 const Outline(this.fullCompile, this.astKind, this.strongMode, |
234 this.generateKernel, this.doResolution, | |
235 {this.updateComments: false}); | 213 {this.updateComments: false}); |
236 | 214 |
237 final bool updateComments; | 215 final bool updateComments; |
238 | 216 |
239 String get name { | 217 String get name { |
240 return fullCompile ? "${astKind} compile" : "outline"; | 218 return fullCompile ? "${astKind} compile" : "outline"; |
241 } | 219 } |
242 | 220 |
243 bool get isCompiler => fullCompile; | 221 bool get isCompiler => fullCompile; |
244 | 222 |
245 Future<Result<Program>> run( | 223 Future<Result<Program>> run( |
246 TestDescription description, FastaContext context) async { | 224 TestDescription description, FastaContext context) async { |
247 // Disable colors to ensure that expectation files are the same across | 225 // Disable colors to ensure that expectation files are the same across |
248 // platforms and independent of stdin/stderr. | 226 // platforms and independent of stdin/stderr. |
249 CompilerContext.current.disableColors(); | 227 CompilerContext.current.disableColors(); |
250 Program platformOutline = await context.loadPlatformOutline(); | 228 Program platformOutline = await context.loadPlatformOutline(); |
251 Ticker ticker = new Ticker(); | 229 Ticker ticker = new Ticker(); |
252 DillTarget dillTarget = new DillTarget(ticker, context.uriTranslator, | 230 DillTarget dillTarget = new DillTarget(ticker, context.uriTranslator, |
253 new TestVmFastaTarget(new TargetFlags(strongMode: strongMode))); | 231 new TestVmFastaTarget(new TargetFlags(strongMode: strongMode))); |
254 platformOutline.unbindCanonicalNames(); | 232 platformOutline.unbindCanonicalNames(); |
255 dillTarget.loader.appendLibraries(platformOutline); | 233 dillTarget.loader.appendLibraries(platformOutline); |
256 // We create a new URI translator to avoid reading platform libraries from | 234 // We create a new URI translator to avoid reading platform libraries from |
257 // file system. | 235 // file system. |
258 UriTranslatorImpl uriTranslator = new UriTranslatorImpl( | 236 UriTranslatorImpl uriTranslator = new UriTranslatorImpl( |
259 const <String, Uri>{}, | 237 const <String, Uri>{}, |
260 const <String, List<Uri>>{}, | 238 const <String, List<Uri>>{}, |
261 context.uriTranslator.packages); | 239 context.uriTranslator.packages); |
262 KernelTarget sourceTarget = astKind == AstKind.Analyzer | 240 KernelTarget sourceTarget = astKind == AstKind.Analyzer |
263 ? new AnalyzerTarget( | 241 ? new AnalyzerTarget(dillTarget, uriTranslator, strongMode) |
264 dillTarget, uriTranslator, strongMode, generateKernel, doResolution) | |
265 : new KernelTarget( | 242 : new KernelTarget( |
266 PhysicalFileSystem.instance, dillTarget, uriTranslator); | 243 PhysicalFileSystem.instance, dillTarget, uriTranslator); |
267 | 244 |
268 Program p; | 245 Program p; |
269 try { | 246 try { |
270 sourceTarget.read(description.uri); | 247 sourceTarget.read(description.uri); |
271 await dillTarget.buildOutlines(); | 248 await dillTarget.buildOutlines(); |
272 ValidatingInstrumentation instrumentation; | 249 ValidatingInstrumentation instrumentation; |
273 if (strongMode) { | 250 if (strongMode) { |
274 instrumentation = new ValidatingInstrumentation(); | 251 instrumentation = new ValidatingInstrumentation(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 } | 311 } |
335 } | 312 } |
336 | 313 |
337 void performGlobalTransformations(CoreTypes coreTypes, Program program, | 314 void performGlobalTransformations(CoreTypes coreTypes, Program program, |
338 {void logger(String msg)}) { | 315 {void logger(String msg)}) { |
339 if (enabled) { | 316 if (enabled) { |
340 super.performGlobalTransformations(coreTypes, program, logger: logger); | 317 super.performGlobalTransformations(coreTypes, program, logger: logger); |
341 } | 318 } |
342 } | 319 } |
343 } | 320 } |
OLD | NEW |