| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 | |
| 5 | 4 |
| 6 // Test that the CPS IR code generator generates source information. | 5 // Test that the CPS IR code generator generates source information. |
| 7 | 6 |
| 8 library source_information_tests; | 7 library source_information_tests; |
| 9 | 8 |
| 10 import 'package:async_helper/async_helper.dart'; | 9 import 'package:async_helper/async_helper.dart'; |
| 11 import 'package:expect/expect.dart'; | 10 import 'package:expect/expect.dart'; |
| 12 import 'package:compiler/src/apiimpl.dart' | 11 import 'package:compiler/src/apiimpl.dart' |
| 13 show Compiler; | 12 show Compiler; |
| 14 import 'memory_compiler.dart'; | 13 import 'memory_compiler.dart'; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 60 |
| 62 if (foundElement == null) { | 61 if (foundElement == null) { |
| 63 Expect.fail('There is no compiled element called $name'); | 62 Expect.fail('There is no compiled element called $name'); |
| 64 } | 63 } |
| 65 | 64 |
| 66 js.Node ast = compiler.enqueuer.codegen.generatedCode[foundElement]; | 65 js.Node ast = compiler.enqueuer.codegen.generatedCode[foundElement]; |
| 67 return js.prettyPrint(ast, compiler).getText(); | 66 return js.prettyPrint(ast, compiler).getText(); |
| 68 } | 67 } |
| 69 | 68 |
| 70 runTests(List<TestEntry> tests) { | 69 runTests(List<TestEntry> tests) { |
| 71 Expect.isTrue(const bool.fromEnvironment("USE_CPS_IR"), | |
| 72 'Run with USE_CPS_IR=true'); | |
| 73 | |
| 74 for (TestEntry test in tests) { | 70 for (TestEntry test in tests) { |
| 75 Map files = {TEST_MAIN_FILE: test.source}; | 71 Map files = {TEST_MAIN_FILE: test.source}; |
| 76 asyncTest(() { | 72 asyncTest(() { |
| 77 Compiler compiler = compilerFor(files); | 73 Compiler compiler = compilerFor(files, options: <String>['--use-cps-ir']); |
| 78 Uri uri = Uri.parse('memory:$TEST_MAIN_FILE'); | 74 Uri uri = Uri.parse('memory:$TEST_MAIN_FILE'); |
| 79 return compiler.run(uri).then((bool success) { | 75 return compiler.run(uri).then((bool success) { |
| 80 Expect.isTrue(success); | 76 Expect.isTrue(success); |
| 81 | 77 |
| 82 ir.Node irNode = getIrNodeForElement(compiler, compiler.mainFunction); | 78 ir.Node irNode = getIrNodeForElement(compiler, compiler.mainFunction); |
| 83 IrSourceInformationVisitor irVisitor = new IrSourceInformationVisitor(); | 79 IrSourceInformationVisitor irVisitor = new IrSourceInformationVisitor(); |
| 84 irNode.accept(irVisitor); | 80 irNode.accept(irVisitor); |
| 85 | 81 |
| 86 js.Node jsNode = getJsNodeForElement(compiler, compiler.mainFunction); | 82 js.Node jsNode = getJsNodeForElement(compiler, compiler.mainFunction); |
| 87 JsSourceInformationVisitor jsVisitor = new JsSourceInformationVisitor(); | 83 JsSourceInformationVisitor jsVisitor = new JsSourceInformationVisitor(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 processInvokeStatic(ir.InvokeStatic node) { | 122 processInvokeStatic(ir.InvokeStatic node) { |
| 127 sourceInformation.add('${node.sourceInformation}'); | 123 sourceInformation.add('${node.sourceInformation}'); |
| 128 } | 124 } |
| 129 } | 125 } |
| 130 | 126 |
| 131 const List<TestEntry> tests = const [ | 127 const List<TestEntry> tests = const [ |
| 132 const TestEntry(""" | 128 const TestEntry(""" |
| 133 main() { print('Hello World'); } | 129 main() { print('Hello World'); } |
| 134 """, const ['memory:test.dart:[1,10]']), | 130 """, const ['memory:test.dart:[1,10]']), |
| 135 const TestEntry(""" | 131 const TestEntry(""" |
| 136 main() { | 132 main() { |
| 137 print('Hello'); | 133 print('Hello'); |
| 138 print('World'); | 134 print('World'); |
| 139 } | 135 } |
| 140 """, const ['memory:test.dart:[2,3]', | 136 """, const ['memory:test.dart:[2,3]', |
| 141 'memory:test.dart:[3,3]']), | 137 'memory:test.dart:[3,3]']), |
| 142 ]; | 138 ]; |
| 143 | 139 |
| 144 void main() { | 140 void main() { |
| 145 runTests(tests); | 141 runTests(tests); |
| 146 } | 142 } |
| OLD | NEW |