| 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 | 4 |
| 5 // Test that the CPS IR code generator compiles programs and produces the | 5 // Test that the CPS IR code generator compiles programs and produces the |
| 6 // the expected output. | 6 // the expected output. |
| 7 | 7 |
| 8 import 'package:async_helper/async_helper.dart'; | 8 import 'package:async_helper/async_helper.dart'; |
| 9 import 'package:expect/expect.dart'; | 9 import 'package:expect/expect.dart'; |
| 10 import 'package:compiler/src/apiimpl.dart' show | 10 import 'package:compiler/src/apiimpl.dart' show |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 57 |
| 58 js.Node ast = compiler.enqueuer.codegen.generatedCode[foundElement]; | 58 js.Node ast = compiler.enqueuer.codegen.generatedCode[foundElement]; |
| 59 return js.prettyPrint(ast, compiler).getText(); | 59 return js.prettyPrint(ast, compiler).getText(); |
| 60 } | 60 } |
| 61 | 61 |
| 62 runTests(List<TestEntry> tests) { | 62 runTests(List<TestEntry> tests) { |
| 63 for (TestEntry test in tests) { | 63 for (TestEntry test in tests) { |
| 64 Map files = {TEST_MAIN_FILE: test.source}; | 64 Map files = {TEST_MAIN_FILE: test.source}; |
| 65 asyncTest(() async { | 65 asyncTest(() async { |
| 66 Uri uri = Uri.parse('memory:$TEST_MAIN_FILE'); | 66 Uri uri = Uri.parse('memory:$TEST_MAIN_FILE'); |
| 67 String expected = test.expectation; |
| 68 String found = null; |
| 67 try { | 69 try { |
| 68 CompilationResult result = await runCompiler( | 70 CompilationResult result = await runCompiler( |
| 69 entryPoint: uri, | 71 entryPoint: uri, |
| 70 memorySourceFiles: files, | 72 memorySourceFiles: files, |
| 71 options: <String>['--use-cps-ir']); | 73 options: <String>['--use-cps-ir']); |
| 72 Expect.isTrue(result.isSuccess); | 74 Expect.isTrue(result.isSuccess); |
| 73 CompilerImpl compiler = result.compiler; | 75 CompilerImpl compiler = result.compiler; |
| 74 String expectation = test.expectation; | 76 if (expected != null) { |
| 75 if (expectation != null) { | 77 found = test.elementName == null |
| 76 String expected = test.expectation; | |
| 77 String found = test.elementName == null | |
| 78 ? getCodeForMain(compiler) | 78 ? getCodeForMain(compiler) |
| 79 : getCodeForMethod(compiler, test.elementName); | 79 : getCodeForMethod(compiler, test.elementName); |
| 80 if (expected != found) { | |
| 81 Expect.fail('Expected:\n$expected\nbut found\n$found'); | |
| 82 } | |
| 83 } | 80 } |
| 84 } catch (e, st) { | 81 } catch (e, st) { |
| 85 print(e); | 82 print(e); |
| 86 print(st); | 83 print(st); |
| 87 Expect.fail('The following test failed to compile:\n' | 84 Expect.fail('The following test failed to compile:\n' |
| 88 '${formatTest(files)}'); | 85 '${formatTest(files)}'); |
| 89 } | 86 } |
| 87 if (expected != found) { |
| 88 Expect.fail('Unexpected output for test:\n ' |
| 89 '${formatTest(files).replaceAll('\n', '\n ')}\n' |
| 90 'Expected:\n ${expected.replaceAll('\n', '\n ')}\n' |
| 91 'but found:\n ${found?.replaceAll('\n', '\n ')}'); |
| 92 } |
| 90 }); | 93 }); |
| 91 } | 94 } |
| 92 } | 95 } |
| OLD | NEW |