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:io' show File; |
| 8 |
7 import 'dart:async' show Future; | 9 import 'dart:async' show Future; |
8 | 10 |
9 import 'package:front_end/physical_file_system.dart' show PhysicalFileSystem; | 11 import 'package:front_end/physical_file_system.dart' show PhysicalFileSystem; |
10 | 12 |
11 import 'package:kernel/core_types.dart' show CoreTypes; | 13 import 'package:kernel/core_types.dart' show CoreTypes; |
12 | 14 |
13 import 'package:testing/testing.dart' | 15 import 'package:testing/testing.dart' |
14 show Chain, ChainContext, Result, Step, TestDescription, runMe; | 16 show |
| 17 Chain, |
| 18 ChainContext, |
| 19 Result, |
| 20 Step, |
| 21 TestDescription, |
| 22 runMe, |
| 23 StdioProcess; |
15 | 24 |
16 import 'package:front_end/src/fasta/testing/patched_sdk_location.dart' | 25 import 'package:front_end/src/fasta/testing/patched_sdk_location.dart' |
17 show computePatchedSdk; | 26 show computePatchedSdk; |
18 | 27 |
19 import 'package:kernel/ast.dart' show Program, Library; | 28 import 'package:kernel/ast.dart' show Program, Library; |
20 | 29 |
21 import 'package:kernel/transformations/closure_conversion.dart' | |
22 as closure_conversion; | |
23 | |
24 import 'package:front_end/src/fasta/testing/kernel_chain.dart' | 30 import 'package:front_end/src/fasta/testing/kernel_chain.dart' |
25 show Print, MatchExpectation, WriteDill, ReadDill, Verify; | 31 show Print, MatchExpectation, WriteDill, ReadDill, Verify; |
26 | 32 |
27 import 'package:front_end/src/fasta/ticker.dart' show Ticker; | 33 import 'package:front_end/src/fasta/ticker.dart' show Ticker; |
28 | 34 |
29 import 'package:front_end/src/fasta/dill/dill_target.dart' show DillTarget; | 35 import 'package:front_end/src/fasta/dill/dill_target.dart' show DillTarget; |
30 | 36 |
31 import 'package:front_end/src/fasta/kernel/kernel_target.dart' | 37 import 'package:front_end/src/fasta/kernel/kernel_target.dart' |
32 show KernelTarget; | 38 show KernelTarget; |
33 | 39 |
34 import 'package:front_end/src/fasta/translate_uri.dart' show TranslateUri; | 40 import 'package:front_end/src/fasta/translate_uri.dart' show TranslateUri; |
35 | 41 |
36 import 'package:front_end/src/fasta/errors.dart' show InputError; | 42 import 'package:front_end/src/fasta/errors.dart' show InputError; |
37 | 43 |
38 import 'package:front_end/src/fasta/testing/patched_sdk_location.dart'; | 44 import 'package:front_end/src/fasta/testing/patched_sdk_location.dart'; |
39 | 45 |
40 import 'package:kernel/kernel.dart' show loadProgramFromBinary; | 46 import 'package:kernel/kernel.dart' show loadProgramFromBinary; |
41 | 47 |
| 48 import 'package:kernel/transformations/closure_conversion.dart' |
| 49 as closure_conversion; |
| 50 |
42 import 'package:kernel/target/targets.dart' show TargetFlags; | 51 import 'package:kernel/target/targets.dart' show TargetFlags; |
43 | 52 |
44 import 'package:kernel/target/vm_fasta.dart' show VmFastaTarget; | 53 import 'package:kernel/target/vm_fasta.dart' show VmFastaTarget; |
45 | 54 |
46 const String STRONG_MODE = " strong mode "; | 55 const String STRONG_MODE = " strong mode "; |
47 | 56 |
48 class ClosureConversionContext extends ChainContext { | 57 class ClosureConversionContext extends ChainContext { |
49 final bool strongMode; | 58 final bool strongMode; |
50 | 59 |
51 final TranslateUri uriTranslator; | 60 final TranslateUri uriTranslator; |
52 | 61 |
53 final List<Step> steps; | 62 final List<Step> steps; |
| 63 final Uri vm; |
| 64 |
| 65 Program platform; |
54 | 66 |
55 ClosureConversionContext( | 67 ClosureConversionContext( |
56 this.strongMode, bool updateExpectations, this.uriTranslator) | 68 this.vm, this.strongMode, bool updateExpectations, this.uriTranslator) |
57 : steps = <Step>[ | 69 : steps = <Step>[ |
58 const FastaCompile(), | 70 const FastaCompile(), |
59 const Print(), | 71 const Print(), |
60 const Verify(true), | 72 const Verify(true), |
61 const ClosureConversion(), | 73 const ClosureConversion(), |
62 const Print(), | 74 const Print(), |
63 const Verify(true), | 75 const Verify(true), |
64 new MatchExpectation(".expect", | 76 new MatchExpectation(".expect", |
65 updateExpectations: updateExpectations), | 77 updateExpectations: updateExpectations), |
66 const WriteDill(), | 78 const WriteDill(), |
67 const ReadDill(), | 79 const ReadDill(), |
68 // TODO(29143): add `Run` step when Vectors are added to VM. | 80 const Run(), |
69 ]; | 81 ]; |
70 | 82 |
71 Future<Program> loadPlatform() async { | 83 Future<Program> loadPlatform() async { |
72 Uri sdk = await computePatchedSdk(); | 84 return platform ??= loadProgramFromBinary( |
73 return loadProgramFromBinary(sdk.resolve('platform.dill').toFilePath()); | 85 (await computePatchedSdk()).resolve('platform.dill').toFilePath()); |
74 } | 86 } |
75 | 87 |
76 static Future<ClosureConversionContext> create( | 88 static Future<ClosureConversionContext> create( |
77 Chain suite, Map<String, String> environment) async { | 89 Chain suite, Map<String, String> environment) async { |
78 Uri sdk = await computePatchedSdk(); | 90 Uri sdk = await computePatchedSdk(); |
| 91 Uri vm = computeDartVm(sdk); |
79 Uri packages = Uri.base.resolve(".packages"); | 92 Uri packages = Uri.base.resolve(".packages"); |
80 bool strongMode = environment.containsKey(STRONG_MODE); | 93 bool strongMode = environment.containsKey(STRONG_MODE); |
81 bool updateExpectations = environment["updateExpectations"] == "true"; | 94 bool updateExpectations = environment["updateExpectations"] == "true"; |
82 TranslateUri uriTranslator = await TranslateUri | 95 TranslateUri uriTranslator = await TranslateUri |
83 .parse(PhysicalFileSystem.instance, sdk, packages: packages); | 96 .parse(PhysicalFileSystem.instance, sdk, packages: packages); |
84 return new ClosureConversionContext( | 97 return new ClosureConversionContext( |
85 strongMode, updateExpectations, uriTranslator); | 98 vm, strongMode, updateExpectations, uriTranslator); |
86 } | 99 } |
87 } | 100 } |
88 | 101 |
89 Future<ClosureConversionContext> createContext( | 102 Future<ClosureConversionContext> createContext( |
90 Chain suite, Map<String, String> environment) async { | 103 Chain suite, Map<String, String> environment) async { |
91 environment["updateExpectations"] = | 104 environment["updateExpectations"] = |
92 const String.fromEnvironment("updateExpectations"); | 105 const String.fromEnvironment("updateExpectations"); |
93 return ClosureConversionContext.create(suite, environment); | 106 return ClosureConversionContext.create(suite, environment); |
94 } | 107 } |
95 | 108 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 Library library = program.libraries | 149 Library library = program.libraries |
137 .firstWhere((Library library) => library.importUri.scheme != "dart"); | 150 .firstWhere((Library library) => library.importUri.scheme != "dart"); |
138 closure_conversion.transformLibraries(coreTypes, <Library>[library]); | 151 closure_conversion.transformLibraries(coreTypes, <Library>[library]); |
139 return pass(program); | 152 return pass(program); |
140 } catch (e, s) { | 153 } catch (e, s) { |
141 return crash(e, s); | 154 return crash(e, s); |
142 } | 155 } |
143 } | 156 } |
144 } | 157 } |
145 | 158 |
| 159 class Run extends Step<Uri, int, ClosureConversionContext> { |
| 160 const Run(); |
| 161 |
| 162 String get name => "run"; |
| 163 |
| 164 Future<Result<int>> run(Uri uri, ClosureConversionContext context) async { |
| 165 final File generated = new File.fromUri(uri); |
| 166 try { |
| 167 final StdioProcess process = await StdioProcess |
| 168 .run(context.vm.toFilePath(), [generated.path, "Hello, World!"]); |
| 169 print(process.output); |
| 170 return process.toResult(); |
| 171 } finally { |
| 172 generated.parent.delete(recursive: true); |
| 173 } |
| 174 } |
| 175 } |
| 176 |
146 main(List<String> arguments) => runMe(arguments, createContext, "testing.json"); | 177 main(List<String> arguments) => runMe(arguments, createContext, "testing.json"); |
OLD | NEW |