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