| OLD | NEW |
| 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 library test.kernel.closures.suite; | 5 library test.kernel.closures.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 'package:front_end/physical_file_system.dart' show PhysicalFileSystem; |
| 12 |
| 11 import 'package:testing/testing.dart' | 13 import 'package:testing/testing.dart' |
| 12 show Chain, ChainContext, Result, Step, runMe; | 14 show Chain, ChainContext, Result, Step, TestDescription, runMe; |
| 15 |
| 16 import 'package:front_end/src/fasta/testing/patched_sdk_location.dart' |
| 17 show computePatchedSdk; |
| 13 | 18 |
| 14 import 'package:kernel/ast.dart' show Program, Library; | 19 import 'package:kernel/ast.dart' show Program, Library; |
| 15 | 20 |
| 16 import 'package:front_end/src/fasta/testing/kernel_chain.dart' | 21 import 'package:front_end/src/fasta/testing/kernel_chain.dart' show runDiff; |
| 17 show runDiff, Compile, CompileContext; | 22 |
| 23 import 'package:front_end/src/fasta/ticker.dart' show Ticker; |
| 24 |
| 25 import 'package:front_end/src/fasta/dill/dill_target.dart' show DillTarget; |
| 26 |
| 27 import 'package:front_end/src/fasta/kernel/kernel_target.dart' |
| 28 show KernelTarget; |
| 29 |
| 30 import 'package:front_end/src/fasta/translate_uri.dart' show TranslateUri; |
| 31 |
| 32 import 'package:front_end/src/fasta/errors.dart' show InputError; |
| 33 |
| 34 import 'package:front_end/src/fasta/testing/patched_sdk_location.dart'; |
| 35 |
| 36 import 'package:kernel/kernel.dart' show loadProgramFromBinary; |
| 37 |
| 38 import 'package:kernel/target/targets.dart' show TargetFlags; |
| 39 |
| 40 import 'package:kernel/target/vm_fasta.dart' show VmFastaTarget; |
| 18 | 41 |
| 19 import 'package:kernel/interpreter/interpreter.dart'; | 42 import 'package:kernel/interpreter/interpreter.dart'; |
| 20 | 43 |
| 21 const String STRONG_MODE = " strong mode "; | 44 const String STRONG_MODE = " strong mode "; |
| 22 | 45 |
| 23 class InterpreterContext extends ChainContext implements CompileContext { | 46 class InterpreterContext extends ChainContext { |
| 24 final bool strongMode; | 47 final bool strongMode; |
| 25 | 48 |
| 49 final TranslateUri uriTranslator; |
| 50 |
| 26 final List<Step> steps; | 51 final List<Step> steps; |
| 27 | 52 |
| 28 InterpreterContext(this.strongMode) | 53 Future<Program> platform; |
| 54 |
| 55 InterpreterContext(this.strongMode, this.uriTranslator) |
| 29 : steps = <Step>[ | 56 : steps = <Step>[ |
| 30 const Compile(), | 57 const FastaCompile(), |
| 31 const Interpret(), | 58 const Interpret(), |
| 32 const MatchLogExpectation(".expect"), | 59 const MatchLogExpectation(".expect"), |
| 33 ]; | 60 ]; |
| 34 | 61 |
| 62 Future<Program> loadPlatform() async { |
| 63 Uri sdk = await computePatchedSdk(); |
| 64 return loadProgramFromBinary(sdk.resolve('platform.dill').toFilePath()); |
| 65 } |
| 66 |
| 35 static Future<InterpreterContext> create( | 67 static Future<InterpreterContext> create( |
| 36 Chain suite, Map<String, String> environment) async { | 68 Chain suite, Map<String, String> environment) async { |
| 69 Uri sdk = await computePatchedSdk(); |
| 70 Uri packages = Uri.base.resolve(".packages"); |
| 37 bool strongMode = environment.containsKey(STRONG_MODE); | 71 bool strongMode = environment.containsKey(STRONG_MODE); |
| 38 return new InterpreterContext(strongMode); | 72 TranslateUri uriTranslator = await TranslateUri |
| 73 .parse(PhysicalFileSystem.instance, sdk, packages: packages); |
| 74 return new InterpreterContext(strongMode, uriTranslator); |
| 39 } | 75 } |
| 40 } | 76 } |
| 41 | 77 |
| 78 class FastaCompile extends Step<TestDescription, Program, InterpreterContext> { |
| 79 const FastaCompile(); |
| 80 |
| 81 String get name => "fasta compile"; |
| 82 |
| 83 Future<Result<Program>> run( |
| 84 TestDescription description, InterpreterContext context) async { |
| 85 Program platform = await context.loadPlatform(); |
| 86 Ticker ticker = new Ticker(); |
| 87 DillTarget dillTarget = new DillTarget(ticker, context.uriTranslator, |
| 88 new VmFastaTarget(new TargetFlags(strongMode: context.strongMode))); |
| 89 platform.unbindCanonicalNames(); |
| 90 dillTarget.loader.appendLibraries(platform); |
| 91 KernelTarget sourceTarget = new KernelTarget( |
| 92 PhysicalFileSystem.instance, dillTarget, context.uriTranslator); |
| 93 |
| 94 Program p; |
| 95 try { |
| 96 sourceTarget.read(description.uri); |
| 97 await dillTarget.buildOutlines(); |
| 98 await sourceTarget.buildOutlines(); |
| 99 p = await sourceTarget.buildProgram(); |
| 100 } on InputError catch (e, s) { |
| 101 return fail(null, e.error, s); |
| 102 } |
| 103 return pass(p); |
| 104 } |
| 105 } |
| 106 |
| 42 class Interpret extends Step<Program, EvaluationLog, InterpreterContext> { | 107 class Interpret extends Step<Program, EvaluationLog, InterpreterContext> { |
| 43 const Interpret(); | 108 const Interpret(); |
| 44 | 109 |
| 45 String get name => "interpret"; | 110 String get name => "interpret"; |
| 46 | 111 |
| 47 Future<Result<EvaluationLog>> run(Program program, _) async { | 112 Future<Result<EvaluationLog>> run(Program program, _) async { |
| 48 Library library = program.libraries | 113 Library library = program.libraries |
| 49 .firstWhere((Library library) => library.importUri.scheme != "dart"); | 114 .firstWhere((Library library) => library.importUri.scheme != "dart"); |
| 50 Uri uri = library.importUri; | 115 Uri uri = library.importUri; |
| 51 | 116 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 final Uri uri; | 158 final Uri uri; |
| 94 | 159 |
| 95 /// Evaluated program log. | 160 /// Evaluated program log. |
| 96 final String log; | 161 final String log; |
| 97 | 162 |
| 98 EvaluationLog(this.uri, this.log); | 163 EvaluationLog(this.uri, this.log); |
| 99 } | 164 } |
| 100 | 165 |
| 101 main(List<String> arguments) => | 166 main(List<String> arguments) => |
| 102 runMe(arguments, InterpreterContext.create, "testing.json"); | 167 runMe(arguments, InterpreterContext.create, "testing.json"); |
| OLD | NEW |