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; |
54 | 64 |
55 ClosureConversionContext( | 65 ClosureConversionContext( |
56 this.strongMode, bool updateExpectations, this.uriTranslator) | 66 this.vm, this.strongMode, bool updateExpectations, this.uriTranslator) |
57 : steps = <Step>[ | 67 : steps = <Step>[ |
58 const FastaCompile(), | 68 const FastaCompile(), |
59 const Print(), | 69 const Print(), |
60 const Verify(true), | 70 const Verify(true), |
61 const ClosureConversion(), | 71 const ClosureConversion(), |
62 const Print(), | 72 const Print(), |
63 const Verify(true), | 73 const Verify(true), |
64 new MatchExpectation(".expect", | 74 new MatchExpectation(".expect", |
65 updateExpectations: updateExpectations), | 75 updateExpectations: updateExpectations), |
66 const WriteDill(), | 76 const WriteDill(), |
67 const ReadDill(), | 77 const ReadDill(), |
68 // TODO(29143): add `Run` step when Vectors are added to VM. | 78 const Run(), |
69 ]; | 79 ]; |
70 | 80 |
71 Future<Program> loadPlatform() async { | 81 // The platform in these tests are reloaded for each testscase, because the |
72 Uri sdk = await computePatchedSdk(); | 82 // closure conversion transformation is performed during the load, and it's |
73 return loadProgramFromBinary(sdk.resolve('platform.dill').toFilePath()); | 83 // not an idempotent transformation yet. |
| 84 Future<Program> loadPlatform() { |
| 85 return new Future<Program>(() async { |
| 86 Uri sdk = await computePatchedSdk(); |
| 87 return loadProgramFromBinary(sdk.resolve('platform.dill').toFilePath()); |
| 88 }); |
74 } | 89 } |
75 | 90 |
76 static Future<ClosureConversionContext> create( | 91 static Future<ClosureConversionContext> create( |
77 Chain suite, Map<String, String> environment) async { | 92 Chain suite, Map<String, String> environment) async { |
78 Uri sdk = await computePatchedSdk(); | 93 Uri sdk = await computePatchedSdk(); |
| 94 Uri vm = computeDartVm(sdk); |
79 Uri packages = Uri.base.resolve(".packages"); | 95 Uri packages = Uri.base.resolve(".packages"); |
80 bool strongMode = environment.containsKey(STRONG_MODE); | 96 bool strongMode = environment.containsKey(STRONG_MODE); |
81 bool updateExpectations = environment["updateExpectations"] == "true"; | 97 bool updateExpectations = environment["updateExpectations"] == "true"; |
82 TranslateUri uriTranslator = await TranslateUri | 98 TranslateUri uriTranslator = await TranslateUri |
83 .parse(PhysicalFileSystem.instance, sdk, packages: packages); | 99 .parse(PhysicalFileSystem.instance, sdk, packages: packages); |
84 return new ClosureConversionContext( | 100 return new ClosureConversionContext( |
85 strongMode, updateExpectations, uriTranslator); | 101 vm, strongMode, updateExpectations, uriTranslator); |
86 } | 102 } |
87 } | 103 } |
88 | 104 |
89 Future<ClosureConversionContext> createContext( | 105 Future<ClosureConversionContext> createContext( |
90 Chain suite, Map<String, String> environment) async { | 106 Chain suite, Map<String, String> environment) async { |
91 environment["updateExpectations"] = | 107 environment["updateExpectations"] = |
92 const String.fromEnvironment("updateExpectations"); | 108 const String.fromEnvironment("updateExpectations"); |
93 return ClosureConversionContext.create(suite, environment); | 109 return ClosureConversionContext.create(suite, environment); |
94 } | 110 } |
95 | 111 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 Library library = program.libraries | 152 Library library = program.libraries |
137 .firstWhere((Library library) => library.importUri.scheme != "dart"); | 153 .firstWhere((Library library) => library.importUri.scheme != "dart"); |
138 closure_conversion.transformLibraries(coreTypes, <Library>[library]); | 154 closure_conversion.transformLibraries(coreTypes, <Library>[library]); |
139 return pass(program); | 155 return pass(program); |
140 } catch (e, s) { | 156 } catch (e, s) { |
141 return crash(e, s); | 157 return crash(e, s); |
142 } | 158 } |
143 } | 159 } |
144 } | 160 } |
145 | 161 |
| 162 class Run extends Step<Uri, int, ClosureConversionContext> { |
| 163 const Run(); |
| 164 |
| 165 String get name => "run"; |
| 166 |
| 167 Future<Result<int>> run(Uri uri, ClosureConversionContext context) async { |
| 168 File generated = new File.fromUri(uri); |
| 169 StdioProcess process; |
| 170 try { |
| 171 process = await StdioProcess |
| 172 .run(context.vm.toFilePath(), [generated.path, "Hello, World!"]); |
| 173 print(process.output); |
| 174 } finally { |
| 175 generated.parent.delete(recursive: true); |
| 176 } |
| 177 return process.toResult(); |
| 178 } |
| 179 } |
| 180 |
146 main(List<String> arguments) => runMe(arguments, createContext, "testing.json"); | 181 main(List<String> arguments) => runMe(arguments, createContext, "testing.json"); |
OLD | NEW |