| 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 |
| 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/compiler_command_line.dart'; |
| 16 |
| 15 import 'package:front_end/src/fasta/testing/validating_instrumentation.dart' | 17 import 'package:front_end/src/fasta/testing/validating_instrumentation.dart' |
| 16 show ValidatingInstrumentation; | 18 show ValidatingInstrumentation; |
| 17 | 19 |
| 18 import 'package:front_end/src/fasta/testing/patched_sdk_location.dart' | 20 import 'package:front_end/src/fasta/testing/patched_sdk_location.dart' |
| 19 show computeDartVm, computePatchedSdk; | 21 show computeDartVm, computePatchedSdk; |
| 20 import 'package:front_end/src/fasta/uri_translator_impl.dart'; | 22 import 'package:front_end/src/fasta/uri_translator_impl.dart'; |
| 21 | 23 |
| 22 import 'package:kernel/ast.dart' show Library, Program; | 24 import 'package:kernel/ast.dart' show Library, Program; |
| 23 | 25 |
| 24 import 'package:testing/testing.dart' | 26 import 'package:testing/testing.dart' |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 final bool updateComments; | 217 final bool updateComments; |
| 216 | 218 |
| 217 String get name { | 219 String get name { |
| 218 return fullCompile ? "${astKind} compile" : "outline"; | 220 return fullCompile ? "${astKind} compile" : "outline"; |
| 219 } | 221 } |
| 220 | 222 |
| 221 bool get isCompiler => fullCompile; | 223 bool get isCompiler => fullCompile; |
| 222 | 224 |
| 223 Future<Result<Program>> run( | 225 Future<Result<Program>> run( |
| 224 TestDescription description, FastaContext context) async { | 226 TestDescription description, FastaContext context) async { |
| 225 // Disable colors to ensure that expectation files are the same across | 227 return await CompilerCommandLine.withGlobalOptions("", [""], (_) async { |
| 226 // platforms and independent of stdin/stderr. | 228 // Disable colors to ensure that expectation files are the same across |
| 227 CompilerContext.current.disableColors(); | 229 // platforms and independent of stdin/stderr. |
| 228 Program platformOutline = await context.loadPlatformOutline(); | 230 CompilerContext.current.disableColors(); |
| 229 Ticker ticker = new Ticker(); | 231 Program platformOutline = await context.loadPlatformOutline(); |
| 230 DillTarget dillTarget = new DillTarget(ticker, context.uriTranslator, | 232 Ticker ticker = new Ticker(); |
| 231 new TestVmFastaTarget(new TargetFlags(strongMode: strongMode))); | 233 DillTarget dillTarget = new DillTarget(ticker, context.uriTranslator, |
| 232 platformOutline.unbindCanonicalNames(); | 234 new TestVmFastaTarget(new TargetFlags(strongMode: strongMode))); |
| 233 dillTarget.loader.appendLibraries(platformOutline); | 235 platformOutline.unbindCanonicalNames(); |
| 234 // We create a new URI translator to avoid reading platform libraries from | 236 dillTarget.loader.appendLibraries(platformOutline); |
| 235 // file system. | 237 // We create a new URI translator to avoid reading platform libraries from |
| 236 UriTranslatorImpl uriTranslator = new UriTranslatorImpl( | 238 // file system. |
| 237 const <String, Uri>{}, | 239 UriTranslatorImpl uriTranslator = new UriTranslatorImpl( |
| 238 const <String, List<Uri>>{}, | 240 const <String, Uri>{}, |
| 239 context.uriTranslator.packages); | 241 const <String, List<Uri>>{}, |
| 240 KernelTarget sourceTarget = astKind == AstKind.Analyzer | 242 context.uriTranslator.packages); |
| 241 ? new AnalyzerTarget(dillTarget, uriTranslator, strongMode) | 243 KernelTarget sourceTarget = astKind == AstKind.Analyzer |
| 242 : new KernelTarget( | 244 ? new AnalyzerTarget(dillTarget, uriTranslator, strongMode) |
| 243 PhysicalFileSystem.instance, false, dillTarget, uriTranslator); | 245 : new KernelTarget( |
| 246 PhysicalFileSystem.instance, false, dillTarget, uriTranslator); |
| 244 | 247 |
| 245 Program p; | 248 Program p; |
| 246 try { | 249 try { |
| 247 sourceTarget.read(description.uri); | 250 sourceTarget.read(description.uri); |
| 248 await dillTarget.buildOutlines(); | 251 await dillTarget.buildOutlines(); |
| 249 ValidatingInstrumentation instrumentation; | 252 ValidatingInstrumentation instrumentation; |
| 250 if (strongMode) { | 253 if (strongMode) { |
| 251 instrumentation = new ValidatingInstrumentation(); | 254 instrumentation = new ValidatingInstrumentation(); |
| 252 await instrumentation.loadExpectations(description.uri); | 255 await instrumentation.loadExpectations(description.uri); |
| 253 sourceTarget.loader.instrumentation = instrumentation; | 256 sourceTarget.loader.instrumentation = instrumentation; |
| 254 } | 257 } |
| 255 p = await sourceTarget.buildOutlines(); | 258 p = await sourceTarget.buildOutlines(); |
| 256 if (fullCompile) { | 259 if (fullCompile) { |
| 257 p = await sourceTarget.buildProgram(); | 260 p = await sourceTarget.buildProgram(); |
| 258 instrumentation?.finish(); | 261 instrumentation?.finish(); |
| 259 if (instrumentation != null && instrumentation.hasProblems) { | 262 if (instrumentation != null && instrumentation.hasProblems) { |
| 260 if (updateComments) { | 263 if (updateComments) { |
| 261 await instrumentation.fixSource(description.uri, false); | 264 await instrumentation.fixSource(description.uri, false); |
| 262 } else { | 265 } else { |
| 263 return fail(null, instrumentation.problemsAsString); | 266 return fail(null, instrumentation.problemsAsString); |
| 267 } |
| 264 } | 268 } |
| 265 } | 269 } |
| 270 } on deprecated_InputError catch (e, s) { |
| 271 return fail(null, e.error, s); |
| 266 } | 272 } |
| 267 } on deprecated_InputError catch (e, s) { | 273 context.programToTarget.clear(); |
| 268 return fail(null, e.error, s); | 274 context.programToTarget[p] = sourceTarget; |
| 269 } | 275 return pass(p); |
| 270 context.programToTarget.clear(); | 276 }); |
| 271 context.programToTarget[p] = sourceTarget; | |
| 272 return pass(p); | |
| 273 } | 277 } |
| 274 } | 278 } |
| 275 | 279 |
| 276 class Transform extends Step<Program, Program, FastaContext> { | 280 class Transform extends Step<Program, Program, FastaContext> { |
| 277 const Transform(); | 281 const Transform(); |
| 278 | 282 |
| 279 String get name => "transform program"; | 283 String get name => "transform program"; |
| 280 | 284 |
| 281 Future<Result<Program>> run(Program program, FastaContext context) async { | 285 Future<Result<Program>> run(Program program, FastaContext context) async { |
| 282 KernelTarget sourceTarget = context.programToTarget[program]; | 286 KernelTarget sourceTarget = context.programToTarget[program]; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 311 } | 315 } |
| 312 } | 316 } |
| 313 | 317 |
| 314 void performGlobalTransformations(CoreTypes coreTypes, Program program, | 318 void performGlobalTransformations(CoreTypes coreTypes, Program program, |
| 315 {void logger(String msg)}) { | 319 {void logger(String msg)}) { |
| 316 if (enabled) { | 320 if (enabled) { |
| 317 super.performGlobalTransformations(coreTypes, program, logger: logger); | 321 super.performGlobalTransformations(coreTypes, program, logger: logger); |
| 318 } | 322 } |
| 319 } | 323 } |
| 320 } | 324 } |
| OLD | NEW |