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 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 | 75 |
76 enum AstKind { | 76 enum AstKind { |
77 Analyzer, | 77 Analyzer, |
78 Kernel, | 78 Kernel, |
79 } | 79 } |
80 | 80 |
81 class FastaContext extends ChainContext { | 81 class FastaContext extends ChainContext { |
82 final TranslateUri uriTranslator; | 82 final TranslateUri uriTranslator; |
83 final List<Step> steps; | 83 final List<Step> steps; |
84 final Uri vm; | 84 final Uri vm; |
85 Uri sdk; | |
86 Uri platformUri; | |
87 Uri outlineUri; | |
85 | 88 |
86 final ExpectationSet expectationSet = | 89 final ExpectationSet expectationSet = |
87 new ExpectationSet.fromJsonList(JSON.decode(EXPECTATIONS)); | 90 new ExpectationSet.fromJsonList(JSON.decode(EXPECTATIONS)); |
88 | 91 |
89 Future<Program> platform; | 92 Future<Program> outline; |
90 | 93 |
91 FastaContext( | 94 FastaContext( |
92 this.vm, | 95 this.vm, |
93 bool strongMode, | 96 bool strongMode, |
94 bool updateExpectations, | 97 bool updateExpectations, |
95 bool updateComments, | 98 bool updateComments, |
96 bool skipVm, | 99 bool skipVm, |
97 this.uriTranslator, | 100 this.uriTranslator, |
98 bool fullCompile, | 101 bool fullCompile, |
99 AstKind astKind) | 102 AstKind astKind) |
100 : steps = <Step>[ | 103 : steps = <Step>[ |
101 new Outline(fullCompile, astKind, strongMode, | 104 new Outline(fullCompile, astKind, strongMode, |
102 updateComments: updateComments), | 105 updateComments: updateComments), |
103 const Print(), | 106 const Print(), |
104 new Verify(fullCompile), | 107 new Verify(fullCompile), |
105 new MatchExpectation( | 108 new MatchExpectation( |
106 fullCompile | 109 fullCompile |
107 ? ".${shortenAstKindName(astKind, strongMode)}.expect" | 110 ? ".${shortenAstKindName(astKind, strongMode)}.expect" |
108 : ".outline.expect", | 111 : ".outline.expect", |
109 updateExpectations: updateExpectations) | 112 updateExpectations: updateExpectations) |
110 ] { | 113 ] { |
111 if (fullCompile && !skipVm) { | 114 if (fullCompile && !skipVm) { |
112 steps.add(const WriteDill()); | 115 steps.add(const WriteDill()); |
113 steps.add(const Run()); | 116 steps.add(const Run()); |
114 } | 117 } |
115 } | 118 } |
116 | 119 |
117 Future<Program> loadPlatform() { | 120 Future ensurePlatformUris() async { |
118 return platform ??= new Future<Program>(() async { | 121 if (sdk == null) { |
119 Uri sdk = await computePatchedSdk(); | 122 sdk = await computePatchedSdk(); |
120 return loadProgramFromBinary(sdk.resolve('platform.dill').toFilePath()); | 123 platformUri = sdk.resolve('platform.dill'); |
124 outlineUri = sdk.resolve('outline.dill'); | |
125 } | |
126 } | |
127 | |
128 Future<Program> loadPlatformOutline() { | |
129 return outline ??= new Future<Program>(() async { | |
130 await ensurePlatformUris(); | |
131 return loadProgramFromBinary(outlineUri.toFilePath()); | |
121 }); | 132 }); |
122 } | 133 } |
123 | 134 |
124 static Future<FastaContext> create( | 135 static Future<FastaContext> create( |
125 Chain suite, Map<String, String> environment) async { | 136 Chain suite, Map<String, String> environment) async { |
126 Uri sdk = await computePatchedSdk(); | 137 Uri sdk = await computePatchedSdk(); |
127 Uri vm = computeDartVm(sdk); | 138 Uri vm = computeDartVm(sdk); |
128 Uri packages = Uri.base.resolve(".packages"); | 139 Uri packages = Uri.base.resolve(".packages"); |
129 TranslateUri uriTranslator = | 140 TranslateUri uriTranslator = |
130 await TranslateUri.parse(PhysicalFileSystem.instance, packages); | 141 await TranslateUri.parse(PhysicalFileSystem.instance, packages); |
(...skipping 22 matching lines...) Expand all Loading... | |
153 String get name => "run"; | 164 String get name => "run"; |
154 | 165 |
155 bool get isAsync => true; | 166 bool get isAsync => true; |
156 | 167 |
157 bool get isRuntime => true; | 168 bool get isRuntime => true; |
158 | 169 |
159 Future<Result<int>> run(Uri uri, FastaContext context) async { | 170 Future<Result<int>> run(Uri uri, FastaContext context) async { |
160 File generated = new File.fromUri(uri); | 171 File generated = new File.fromUri(uri); |
161 StdioProcess process; | 172 StdioProcess process; |
162 try { | 173 try { |
163 process = await StdioProcess | 174 await context.ensurePlatformUris(); |
ahe
2017/05/31 14:04:40
You can't do this here because this step is "async
Siggi Cherem (dart-lang)
2017/05/31 15:44:04
Should this just assert that context.patformUri is
ahe
2017/05/31 16:40:18
I wasn't able to provide you a general solution fo
| |
164 .run(context.vm.toFilePath(), [generated.path, "Hello, World!"]); | 175 var platformDill = context.platformUri.toFilePath(); |
176 var args = ['--platform=$platformDill', generated.path, "Hello, World!"]; | |
177 process = await StdioProcess.run(context.vm.toFilePath(), args); | |
165 print(process.output); | 178 print(process.output); |
166 } finally { | 179 } finally { |
167 generated.parent.delete(recursive: true); | 180 generated.parent.delete(recursive: true); |
168 } | 181 } |
169 return process.toResult(); | 182 return process.toResult(); |
170 } | 183 } |
171 } | 184 } |
172 | 185 |
173 class Outline extends Step<TestDescription, Program, FastaContext> { | 186 class Outline extends Step<TestDescription, Program, FastaContext> { |
174 final bool fullCompile; | 187 final bool fullCompile; |
175 | 188 |
176 final AstKind astKind; | 189 final AstKind astKind; |
177 | 190 |
178 final bool strongMode; | 191 final bool strongMode; |
179 | 192 |
180 const Outline(this.fullCompile, this.astKind, this.strongMode, | 193 const Outline(this.fullCompile, this.astKind, this.strongMode, |
181 {this.updateComments: false}); | 194 {this.updateComments: false}); |
182 | 195 |
183 final bool updateComments; | 196 final bool updateComments; |
184 | 197 |
185 String get name { | 198 String get name { |
186 return fullCompile ? "${astKind} compile" : "outline"; | 199 return fullCompile ? "${astKind} compile" : "outline"; |
187 } | 200 } |
188 | 201 |
189 bool get isCompiler => fullCompile; | 202 bool get isCompiler => fullCompile; |
190 | 203 |
191 Future<Result<Program>> run( | 204 Future<Result<Program>> run( |
192 TestDescription description, FastaContext context) async { | 205 TestDescription description, FastaContext context) async { |
193 Program platform = await context.loadPlatform(); | 206 Program platformOutline = await context.loadPlatformOutline(); |
194 Ticker ticker = new Ticker(); | 207 Ticker ticker = new Ticker(); |
195 DillTarget dillTarget = new DillTarget(ticker, context.uriTranslator); | 208 DillTarget dillTarget = new DillTarget(ticker, context.uriTranslator); |
196 dillTarget.loader.appendLibraries(platform); | 209 dillTarget.loader.appendLibraries(platformOutline); |
197 KernelTarget sourceTarget = astKind == AstKind.Analyzer | 210 KernelTarget sourceTarget = astKind == AstKind.Analyzer |
198 ? new AnalyzerTarget(dillTarget, context.uriTranslator, strongMode) | 211 ? new AnalyzerTarget(dillTarget, context.uriTranslator, strongMode) |
199 : new KernelTarget(PhysicalFileSystem.instance, dillTarget, | 212 : new KernelTarget(PhysicalFileSystem.instance, dillTarget, |
200 context.uriTranslator, strongMode); | 213 context.uriTranslator, strongMode); |
201 | 214 |
202 Program p; | 215 Program p; |
203 try { | 216 try { |
204 sourceTarget.read(description.uri); | 217 sourceTarget.read(description.uri); |
205 await dillTarget.writeOutline(null); | 218 await dillTarget.writeOutline(null); |
206 ValidatingInstrumentation instrumentation; | 219 ValidatingInstrumentation instrumentation; |
(...skipping 13 matching lines...) Expand all Loading... | |
220 return fail(null, instrumentation.problemsAsString); | 233 return fail(null, instrumentation.problemsAsString); |
221 } | 234 } |
222 } | 235 } |
223 } | 236 } |
224 } on InputError catch (e, s) { | 237 } on InputError catch (e, s) { |
225 return fail(null, e.error, s); | 238 return fail(null, e.error, s); |
226 } | 239 } |
227 return pass(p); | 240 return pass(p); |
228 } | 241 } |
229 } | 242 } |
OLD | NEW |