| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // VMOptions=-DUSE_CPS_IR=true | 4 // VMOptions=-DUSE_CPS_IR=true |
| 5 | 5 |
| 6 // Test that the CPS IR code generator is able to compile the provided | 6 // Test that the CPS IR code generator compiles programs and produces the |
| 7 // example programs. | 7 // the expected output. |
| 8 | 8 |
| 9 import 'package:async_helper/async_helper.dart'; | 9 import 'package:async_helper/async_helper.dart'; |
| 10 import 'package:expect/expect.dart'; | 10 import 'package:expect/expect.dart'; |
| 11 import 'package:compiler/src/apiimpl.dart' | 11 import 'package:compiler/src/apiimpl.dart' |
| 12 show Compiler; | 12 show Compiler; |
| 13 import 'memory_compiler.dart'; | 13 import 'memory_compiler.dart'; |
| 14 import 'package:compiler/src/js/js.dart' as js; | 14 import 'package:compiler/src/js/js.dart' as js; |
| 15 import 'package:compiler/src/common.dart' show Element; | 15 import 'package:compiler/src/common.dart' show Element; |
| 16 | 16 |
| 17 import 'js_backend_cps_ir_basic.dart' as basic; |
| 18 import 'js_backend_cps_ir_literals.dart' as literals; |
| 17 | 19 |
| 18 const String TEST_MAIN_FILE = 'test.dart'; | 20 const String TEST_MAIN_FILE = 'test.dart'; |
| 19 | 21 |
| 22 List<TestEntry> tests = <TestEntry>[] |
| 23 ..addAll(basic.tests) |
| 24 ..addAll(literals.tests); |
| 25 |
| 20 class TestEntry { | 26 class TestEntry { |
| 21 final String source; | 27 final String source; |
| 22 final String expectation; | 28 final String expectation; |
| 23 const TestEntry(this.source, [this.expectation]); | 29 const TestEntry(this.source, [this.expectation]); |
| 24 } | 30 } |
| 25 | 31 |
| 26 /// The list of tests to run. | |
| 27 const List<TestEntry> tests = const [ | |
| 28 const TestEntry( | |
| 29 """ | |
| 30 foo(a) { | |
| 31 return a; | |
| 32 } | |
| 33 main() { | |
| 34 var a = 10; | |
| 35 var b = 1; | |
| 36 var t; | |
| 37 t = a; | |
| 38 a = b; | |
| 39 b = t; | |
| 40 print(a); | |
| 41 print(b); | |
| 42 print(b); | |
| 43 print(foo(a)); | |
| 44 } | |
| 45 """, | |
| 46 """ | |
| 47 function() { | |
| 48 var a, b; | |
| 49 a = 10; | |
| 50 b = 1; | |
| 51 P.print(b); | |
| 52 P.print(a); | |
| 53 P.print(a); | |
| 54 P.print(V.foo(b)); | |
| 55 return null; | |
| 56 }"""), | |
| 57 const TestEntry( | |
| 58 """ | |
| 59 foo() { return 42; } | |
| 60 main() { return foo(); } | |
| 61 """, | |
| 62 """function() { | |
| 63 return V.foo(); | |
| 64 }"""), | |
| 65 const TestEntry("main() {}"), | |
| 66 const TestEntry("main() { return 42; }"), | |
| 67 const TestEntry("main() { return; }", """ | |
| 68 function() { | |
| 69 return null; | |
| 70 }"""), | |
| 71 ]; | |
| 72 | |
| 73 String formatTest(Map test) { | 32 String formatTest(Map test) { |
| 74 return test[TEST_MAIN_FILE]; | 33 return test[TEST_MAIN_FILE]; |
| 75 } | 34 } |
| 76 | 35 |
| 77 String getCodeForMain(Compiler compiler) { | 36 String getCodeForMain(Compiler compiler) { |
| 78 Element mainFunction = compiler.mainFunction; | 37 Element mainFunction = compiler.mainFunction; |
| 79 js.Node ast = compiler.enqueuer.codegen.generatedCode[mainFunction]; | 38 js.Node ast = compiler.enqueuer.codegen.generatedCode[mainFunction]; |
| 80 return js.prettyPrint(ast, compiler).getText(); | 39 return js.prettyPrint(ast, compiler).getText(); |
| 81 } | 40 } |
| 82 | 41 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 95 Expect.equals(test.expectation, getCodeForMain(compiler)); | 54 Expect.equals(test.expectation, getCodeForMain(compiler)); |
| 96 } | 55 } |
| 97 }).catchError((e) { | 56 }).catchError((e) { |
| 98 print(e); | 57 print(e); |
| 99 Expect.fail('The following test failed to compile:\n' | 58 Expect.fail('The following test failed to compile:\n' |
| 100 '${formatTest(files)}'); | 59 '${formatTest(files)}'); |
| 101 }); | 60 }); |
| 102 }); | 61 }); |
| 103 } | 62 } |
| 104 } | 63 } |
| OLD | NEW |