| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 /** | 5 /** |
| 6 * A simple unit test library for running tests in a browser. | 6 * A simple unit test library for running tests in a browser. |
| 7 */ | 7 */ |
| 8 #library("unittest"); | 8 #library("unittest"); |
| 9 | 9 |
| 10 #import("dart:dom"); | 10 #import("dart:dom"); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 if (_isLayoutTest && testsPassed == _tests.length) { | 50 if (_isLayoutTest && testsPassed == _tests.length) { |
| 51 document.body.innerHTML = "PASS"; | 51 document.body.innerHTML = "PASS"; |
| 52 } else { | 52 } else { |
| 53 var newBody = new StringBuffer(); | 53 var newBody = new StringBuffer(); |
| 54 newBody.add("<table class='unittest-table'><tbody>"); | 54 newBody.add("<table class='unittest-table'><tbody>"); |
| 55 newBody.add(testsPassed == _tests.length | 55 newBody.add(testsPassed == _tests.length |
| 56 ? "<tr><td colspan='3' class='unittest-pass'>PASS</td></tr>" | 56 ? "<tr><td colspan='3' class='unittest-pass'>PASS</td></tr>" |
| 57 : "<tr><td colspan='3' class='unittest-fail'>FAIL</td></tr>"); | 57 : "<tr><td colspan='3' class='unittest-fail'>FAIL</td></tr>"); |
| 58 | 58 |
| 59 for (final test in _tests) { | 59 for (final test_ in _tests) { |
| 60 newBody.add(_toHtml(test)); | 60 newBody.add(_toHtml(test_)); |
| 61 } | 61 } |
| 62 | 62 |
| 63 if (testsPassed == _tests.length) { | 63 if (testsPassed == _tests.length) { |
| 64 newBody.add("<tr><td colspan='3' class='unittest-pass'>All " | 64 newBody.add("<tr><td colspan='3' class='unittest-pass'>All " |
| 65 + testsPassed + " tests passed</td></tr>"); | 65 + testsPassed + " tests passed</td></tr>"); |
| 66 } else { | 66 } else { |
| 67 newBody.add(""" | 67 newBody.add(""" |
| 68 <tr><td colspan='3'>Total | 68 <tr><td colspan='3'>Total |
| 69 <span class='unittest-pass'>${testsPassed} passed</span>, | 69 <span class='unittest-pass'>${testsPassed} passed</span>, |
| 70 <span class='unittest-fail'>${testsFailed} failed</span> | 70 <span class='unittest-fail'>${testsFailed} failed</span> |
| 71 <span class='unittest-error'>${testsErrors} errors</span> | 71 <span class='unittest-error'>${testsErrors} errors</span> |
| 72 </td></tr>"""); | 72 </td></tr>"""); |
| 73 } | 73 } |
| 74 newBody.add("</tbody></table>"); | 74 newBody.add("</tbody></table>"); |
| 75 document.body.innerHTML = newBody.toString(); | 75 document.body.innerHTML = newBody.toString(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 window.postMessage('unittest-suite-done', '*'); | 78 window.postMessage('unittest-suite-done', '*'); |
| 79 } | 79 } |
| 80 | 80 |
| 81 String _toHtml(TestCase test) { | 81 String _toHtml(TestCase test_) { |
| 82 if (!test.isComplete) { | 82 if (!test_.isComplete) { |
| 83 return ''' | 83 return ''' |
| 84 <tr> | 84 <tr> |
| 85 <td>${test.id}</td> | 85 <td>${test_.id}</td> |
| 86 <td class="unittest-error">NO STATUS</td> | 86 <td class="unittest-error">NO STATUS</td> |
| 87 <td>Test did not complete</td> | 87 <td>Test did not complete</td> |
| 88 </tr>'''; | 88 </tr>'''; |
| 89 } | 89 } |
| 90 | 90 |
| 91 var html = ''' | 91 var html = ''' |
| 92 <tr> | 92 <tr> |
| 93 <td>${test.id}</td> | 93 <td>${test_.id}</td> |
| 94 <td class="unittest-${test.result}">${test.result.toUpperCase()}</td> | 94 <td class="unittest-${test_.result}">${test_.result.toUpperCase()}</td> |
| 95 <td>Expectation: ${test.description}. ${test.message}</td> | 95 <td>Expectation: ${test_.description}. ${test_.message}</td> |
| 96 </tr>'''; | 96 </tr>'''; |
| 97 | 97 |
| 98 if (test.stackTrace != null) { | 98 if (test_.stackTrace != null) { |
| 99 html += | 99 html += |
| 100 '<tr><td></td><td colspan="2"><pre>${test.stackTrace}</pre></td></tr>'; | 100 '<tr><td></td><td colspan="2"><pre>${test_.stackTrace}</pre></td></tr>'; |
| 101 } | 101 } |
| 102 | 102 |
| 103 return html; | 103 return html; |
| 104 } | 104 } |
| OLD | NEW |