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