| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | |
| 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 file. | |
| 4 // VMOptions=-DUSE_CPS_IR=true | |
| 5 | |
| 6 // Test that the CPS IR code generator compiles programs and produces the | |
| 7 // the expected output. | |
| 8 | |
| 9 import 'package:async_helper/async_helper.dart'; | |
| 10 import 'package:expect/expect.dart'; | |
| 11 import 'package:compiler/src/apiimpl.dart' | |
| 12 show Compiler; | |
| 13 import 'memory_compiler.dart'; | |
| 14 import 'package:compiler/src/js/js.dart' as js; | |
| 15 import 'package:compiler/src/common.dart' show Element; | |
| 16 | |
| 17 import 'js_backend_cps_ir_basic.dart' as basic; | |
| 18 import 'js_backend_cps_ir_literals.dart' as literals; | |
| 19 import 'js_backend_cps_ir_operators.dart' as operators; | |
| 20 import 'js_backend_cps_ir_control_flow.dart' as control_flow; | |
| 21 import 'js_backend_cps_ir_interceptors.dart' as interceptors; | |
| 22 import 'js_backend_cps_ir_closures.dart' as closures; | |
| 23 | |
| 24 const String TEST_MAIN_FILE = 'test.dart'; | |
| 25 | |
| 26 List<TestEntry> tests = <TestEntry>[] | |
| 27 ..addAll(basic.tests) | |
| 28 ..addAll(literals.tests) | |
| 29 ..addAll(control_flow.tests) | |
| 30 ..addAll(operators.tests) | |
| 31 ..addAll(interceptors.tests) | |
| 32 ..addAll(closures.tests); | |
| 33 | |
| 34 class TestEntry { | |
| 35 final String source; | |
| 36 final String expectation; | |
| 37 const TestEntry(this.source, [this.expectation]); | |
| 38 } | |
| 39 | |
| 40 String formatTest(Map test) { | |
| 41 return test[TEST_MAIN_FILE]; | |
| 42 } | |
| 43 | |
| 44 String getCodeForMain(Compiler compiler) { | |
| 45 Element mainFunction = compiler.mainFunction; | |
| 46 js.Node ast = compiler.enqueuer.codegen.generatedCode[mainFunction]; | |
| 47 return js.prettyPrint(ast, compiler).getText(); | |
| 48 } | |
| 49 | |
| 50 main() { | |
| 51 Expect.isTrue(const bool.fromEnvironment("USE_CPS_IR")); | |
| 52 | |
| 53 for (TestEntry test in tests) { | |
| 54 Map files = {TEST_MAIN_FILE: test.source}; | |
| 55 asyncTest(() { | |
| 56 Compiler compiler = compilerFor(files); | |
| 57 Uri uri = Uri.parse('memory:$TEST_MAIN_FILE'); | |
| 58 return compiler.run(uri).then((bool success) { | |
| 59 Expect.isTrue(success); | |
| 60 String expectation = test.expectation; | |
| 61 if (expectation != null) { | |
| 62 String expected = test.expectation; | |
| 63 String found = getCodeForMain(compiler); | |
| 64 if (expected != found) { | |
| 65 Expect.fail('Expected:\n$expected\nbut found\n$found'); | |
| 66 } | |
| 67 } | |
| 68 }).catchError((e) { | |
| 69 print(e); | |
| 70 Expect.fail('The following test failed to compile:\n' | |
| 71 '${formatTest(files)}'); | |
| 72 }); | |
| 73 }); | |
| 74 } | |
| 75 } | |
| OLD | NEW |