| 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 | |
| 13 import 'package:testing/testing.dart' | 11 import 'package:testing/testing.dart' |
| 14 show Chain, ChainContext, Result, Step, TestDescription, runMe; | 12 show Chain, ChainContext, Result, Step, runMe; |
| 15 | |
| 16 import 'package:front_end/src/fasta/testing/patched_sdk_location.dart' | |
| 17 show computePatchedSdk; | |
| 18 | 13 |
| 19 import 'package:kernel/ast.dart' show Program, Library; | 14 import 'package:kernel/ast.dart' show Program, Library; |
| 20 | 15 |
| 21 import 'package:front_end/src/fasta/testing/kernel_chain.dart' show runDiff; | 16 import 'package:front_end/src/fasta/testing/kernel_chain.dart' |
| 22 | 17 show runDiff, Compile, CompileContext; |
| 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; | |
| 41 | 18 |
| 42 import 'package:kernel/interpreter/interpreter.dart'; | 19 import 'package:kernel/interpreter/interpreter.dart'; |
| 43 | 20 |
| 44 const String STRONG_MODE = " strong mode "; | 21 const String STRONG_MODE = " strong mode "; |
| 45 | 22 |
| 46 class InterpreterContext extends ChainContext { | 23 class InterpreterContext extends ChainContext implements CompileContext { |
| 47 final bool strongMode; | 24 final bool strongMode; |
| 48 | 25 |
| 49 final TranslateUri uriTranslator; | |
| 50 | |
| 51 final List<Step> steps; | 26 final List<Step> steps; |
| 52 | 27 |
| 53 Future<Program> platform; | 28 InterpreterContext(this.strongMode) |
| 54 | |
| 55 InterpreterContext(this.strongMode, this.uriTranslator) | |
| 56 : steps = <Step>[ | 29 : steps = <Step>[ |
| 57 const FastaCompile(), | 30 const Compile(), |
| 58 const Interpret(), | 31 const Interpret(), |
| 59 const MatchLogExpectation(".expect"), | 32 const MatchLogExpectation(".expect"), |
| 60 ]; | 33 ]; |
| 61 | 34 |
| 62 Future<Program> loadPlatform() async { | |
| 63 Uri sdk = await computePatchedSdk(); | |
| 64 return loadProgramFromBinary(sdk.resolve('platform.dill').toFilePath()); | |
| 65 } | |
| 66 | |
| 67 static Future<InterpreterContext> create( | 35 static Future<InterpreterContext> create( |
| 68 Chain suite, Map<String, String> environment) async { | 36 Chain suite, Map<String, String> environment) async { |
| 69 Uri sdk = await computePatchedSdk(); | |
| 70 Uri packages = Uri.base.resolve(".packages"); | |
| 71 bool strongMode = environment.containsKey(STRONG_MODE); | 37 bool strongMode = environment.containsKey(STRONG_MODE); |
| 72 TranslateUri uriTranslator = await TranslateUri | 38 return new InterpreterContext(strongMode); |
| 73 .parse(PhysicalFileSystem.instance, sdk, packages: packages); | |
| 74 return new InterpreterContext(strongMode, uriTranslator); | |
| 75 } | 39 } |
| 76 } | 40 } |
| 77 | 41 |
| 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 | |
| 107 class Interpret extends Step<Program, EvaluationLog, InterpreterContext> { | 42 class Interpret extends Step<Program, EvaluationLog, InterpreterContext> { |
| 108 const Interpret(); | 43 const Interpret(); |
| 109 | 44 |
| 110 String get name => "interpret"; | 45 String get name => "interpret"; |
| 111 | 46 |
| 112 Future<Result<EvaluationLog>> run(Program program, _) async { | 47 Future<Result<EvaluationLog>> run(Program program, _) async { |
| 113 Library library = program.libraries | 48 Library library = program.libraries |
| 114 .firstWhere((Library library) => library.importUri.scheme != "dart"); | 49 .firstWhere((Library library) => library.importUri.scheme != "dart"); |
| 115 Uri uri = library.importUri; | 50 Uri uri = library.importUri; |
| 116 | 51 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 final Uri uri; | 93 final Uri uri; |
| 159 | 94 |
| 160 /// Evaluated program log. | 95 /// Evaluated program log. |
| 161 final String log; | 96 final String log; |
| 162 | 97 |
| 163 EvaluationLog(this.uri, this.log); | 98 EvaluationLog(this.uri, this.log); |
| 164 } | 99 } |
| 165 | 100 |
| 166 main(List<String> arguments) => | 101 main(List<String> arguments) => |
| 167 runMe(arguments, InterpreterContext.create, "testing.json"); | 102 runMe(arguments, InterpreterContext.create, "testing.json"); |
| OLD | NEW |