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 // TODO(ahe): Copied from closure_conversion branch of kernel, remove this file | 5 // TODO(ahe): Copied from closure_conversion branch of kernel, remove this file |
6 // when closure_conversion is merged with master. | 6 // when closure_conversion is merged with master. |
7 | 7 |
8 library kernel.testing.kernel_chain; | 8 library kernel.testing.kernel_chain; |
9 | 9 |
10 import 'dart:async' show | 10 import 'dart:async' show |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 } | 185 } |
186 target.transformProgram(program); | 186 target.transformProgram(program); |
187 return pass(program); | 187 return pass(program); |
188 } catch (e, s) { | 188 } catch (e, s) { |
189 return crash(e, s); | 189 return crash(e, s); |
190 } | 190 } |
191 } | 191 } |
192 } | 192 } |
193 | 193 |
194 | 194 |
195 class Print extends Step<Program, Program, dynamic> { | 195 class Print extends Step<Program, Program, TestContext> { |
196 const Print(); | 196 const Print(); |
197 | 197 |
198 String get name => "print"; | 198 String get name => "print"; |
199 | 199 |
200 Future<Result<Program>> run(Program program, _) async { | 200 Future<Result<Program>> run(Program program, _) async { |
201 StringBuffer sb = new StringBuffer(); | 201 StringBuffer sb = new StringBuffer(); |
202 for (Library library in program.libraries) { | 202 for (Library library in program.libraries) { |
203 Printer printer = new Printer(sb); | 203 Printer printer = new Printer(sb); |
204 if (library.importUri.scheme != "dart" && | 204 if (library.importUri.scheme != "dart" && |
205 library.importUri.scheme != "package") { | 205 library.importUri.scheme != "package") { |
206 printer.writeLibraryFile(library); | 206 printer.writeLibraryFile(library); |
207 } | 207 } |
208 } | 208 } |
209 print("$sb"); | 209 print("$sb"); |
210 return pass(program); | 210 return pass(program); |
211 } | 211 } |
212 } | 212 } |
213 | 213 |
214 class Verify extends Step<Program, Program, dynamic> { | 214 class Verify extends Step<Program, Program, TestContext> { |
215 final bool fullCompile; | 215 final bool fullCompile; |
216 | 216 |
217 const Verify(this.fullCompile); | 217 const Verify(this.fullCompile); |
218 | 218 |
219 String get name => "verify"; | 219 String get name => "verify"; |
220 | 220 |
221 Future<Result<Program>> run(Program program, TestContext testContext) async { | 221 Future<Result<Program>> run(Program program, TestContext testContext) async { |
222 try { | 222 try { |
223 program.accept(new VerifyingVisitor()..isOutline = !fullCompile); | 223 program.accept(new VerifyingVisitor()..isOutline = !fullCompile); |
224 return pass(program); | 224 return pass(program); |
225 } catch (e, s) { | 225 } catch (e, s) { |
226 return new Result<Program>( | 226 return new Result<Program>( |
227 null, testContext.expectationSet["VerificationError"], e, s); | 227 null, testContext.expectationSet["VerificationError"], e, s); |
228 } | 228 } |
229 } | 229 } |
230 } | 230 } |
231 | 231 |
232 class MatchExpectation extends Step<Program, Program, dynamic> { | 232 class MatchExpectation extends Step<Program, Program, TestContext> { |
233 final String suffix; | 233 final String suffix; |
234 | 234 |
235 // TODO(ahe): This is true by default which doesn't match well with the class | 235 // TODO(ahe): This is true by default which doesn't match well with the class |
236 // name. | 236 // name. |
237 final bool updateExpectations; | 237 final bool updateExpectations; |
238 | 238 |
239 const MatchExpectation(this.suffix, {this.updateExpectations: true}); | 239 const MatchExpectation(this.suffix, {this.updateExpectations: true}); |
240 | 240 |
241 String get name => "match expectations"; | 241 String get name => "match expectations"; |
242 | 242 |
(...skipping 28 matching lines...) Expand all Loading... |
271 }); | 271 }); |
272 return pass(program); | 272 return pass(program); |
273 } else { | 273 } else { |
274 return fail(program, """ | 274 return fail(program, """ |
275 Please create file ${expectedFile.path} with this content: | 275 Please create file ${expectedFile.path} with this content: |
276 $buffer"""); | 276 $buffer"""); |
277 } | 277 } |
278 } | 278 } |
279 } | 279 } |
280 | 280 |
281 class WriteDill extends Step<Program, Uri, dynamic> { | 281 class WriteDill extends Step<Program, Uri, TestContext> { |
282 const WriteDill(); | 282 const WriteDill(); |
283 | 283 |
284 String get name => "write .dill"; | 284 String get name => "write .dill"; |
285 | 285 |
286 Future<Result<Uri>> run(Program program, _) async { | 286 Future<Result<Uri>> run(Program program, _) async { |
287 Directory tmp = await Directory.systemTemp.createTemp(); | 287 Directory tmp = await Directory.systemTemp.createTemp(); |
288 Uri uri = tmp.uri.resolve("generated.dill"); | 288 Uri uri = tmp.uri.resolve("generated.dill"); |
289 File generated = new File.fromUri(uri); | 289 File generated = new File.fromUri(uri); |
290 IOSink sink = generated.openWrite(); | 290 IOSink sink = generated.openWrite(); |
291 try { | 291 try { |
292 new BinaryPrinter(sink).writeProgramFile(program); | 292 new BinaryPrinter(sink).writeProgramFile(program); |
293 } catch (e, s) { | 293 } catch (e, s) { |
294 return fail(uri, e, s); | 294 return fail(uri, e, s); |
295 } finally { | 295 } finally { |
296 print("Wrote `${generated.path}`"); | 296 print("Wrote `${generated.path}`"); |
297 await sink.close(); | 297 await sink.close(); |
298 } | 298 } |
299 return pass(uri); | 299 return pass(uri); |
300 } | 300 } |
301 } | 301 } |
302 | 302 |
303 class ReadDill extends Step<Uri, Uri, dynamic> { | 303 class ReadDill extends Step<Uri, Uri, TestContext> { |
304 const ReadDill(); | 304 const ReadDill(); |
305 | 305 |
306 String get name => "read .dill"; | 306 String get name => "read .dill"; |
307 | 307 |
308 Future<Result<Uri>> run(Uri uri, _) async { | 308 Future<Result<Uri>> run(Uri uri, _) async { |
309 try { | 309 try { |
310 loadProgramFromBinary(uri.toFilePath()); | 310 loadProgramFromBinary(uri.toFilePath()); |
311 } catch (e, s) { | 311 } catch (e, s) { |
312 return fail(uri, e, s); | 312 return fail(uri, e, s); |
313 } | 313 } |
314 return pass(uri); | 314 return pass(uri); |
315 } | 315 } |
316 } | 316 } |
317 | 317 |
318 class Copy extends Step<Program, Program, dynamic> { | 318 class Copy extends Step<Program, Program, TestContext> { |
319 const Copy(); | 319 const Copy(); |
320 | 320 |
321 String get name => "copy program"; | 321 String get name => "copy program"; |
322 | 322 |
323 Future<Result<Program>> run(Program program, _) async { | 323 Future<Result<Program>> run(Program program, _) async { |
324 BytesCollector sink = new BytesCollector(); | 324 BytesCollector sink = new BytesCollector(); |
325 new BinaryPrinter(sink).writeProgramFile(program); | 325 new BinaryPrinter(sink).writeProgramFile(program); |
326 Uint8List bytes = sink.collect(); | 326 Uint8List bytes = sink.collect(); |
327 BinaryLoader loader = new BinaryLoader(new Repository()); | 327 BinaryLoader loader = new BinaryLoader(new Repository()); |
328 return pass(new BinaryBuilder(loader, bytes).readProgramFile()); | 328 return pass(new BinaryBuilder(loader, bytes).readProgramFile()); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 | 385 |
386 Future openWrite(Uri uri, f(IOSink sink)) async { | 386 Future openWrite(Uri uri, f(IOSink sink)) async { |
387 IOSink sink = new File.fromUri(uri).openWrite(); | 387 IOSink sink = new File.fromUri(uri).openWrite(); |
388 try { | 388 try { |
389 await f(sink); | 389 await f(sink); |
390 } finally { | 390 } finally { |
391 await sink.close(); | 391 await sink.close(); |
392 } | 392 } |
393 print("Wrote $uri"); | 393 print("Wrote $uri"); |
394 } | 394 } |
OLD | NEW |