Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(294)

Side by Side Diff: lib/unittest/html_print.dart

Issue 10836241: Move unittest from lib to pkg. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « lib/unittest/html_enhanced_config.dart ('k') | lib/unittest/interactive_html_config.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012, 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
5 /** This file is sourced by both dom_config.dart and html_config.dart. */
6
7 /** Creates a table showing tests results in HTML. */
8 void _showResultsInPage(int passed, int failed, int errors,
9 List<TestCase> results, bool isLayoutTest, String uncaughtError) {
10 if (isLayoutTest && (passed == results.length) && uncaughtError == null) {
11 document.body.innerHTML = "PASS";
12 } else {
13 var newBody = new StringBuffer();
14 newBody.add("<table class='unittest-table'><tbody>");
15 newBody.add(passed == results.length && uncaughtError == null
16 ? "<tr><td colspan='3' class='unittest-pass'>PASS</td></tr>"
17 : "<tr><td colspan='3' class='unittest-fail'>FAIL</td></tr>");
18
19 for (final test_ in results) {
20 newBody.add(_toHtml(test_));
21 }
22
23 if (uncaughtError != null) {
24 newBody.add('''<tr>
25 <td>--</td>
26 <td class="unittest-error">ERROR</td>
27 <td>Uncaught error: $uncaughtError</td>
28 </tr>''');
29 }
30
31 if (passed == results.length && uncaughtError == null) {
32 newBody.add("""
33 <tr><td colspan='3' class='unittest-pass'>
34 All ${passed} tests passed
35 </td></tr>""");
36 } else {
37 newBody.add("""
38 <tr><td colspan='3'>Total
39 <span class='unittest-pass'>${passed} passed</span>,
40 <span class='unittest-fail'>${failed} failed</span>
41 <span class='unittest-error'>
42 ${errors + (uncaughtError == null ? 0 : 1)} errors</span>
43 </td></tr>""");
44 }
45 newBody.add("</tbody></table>");
46 document.body.innerHTML = newBody.toString();
47 }
48 }
49
50 String _toHtml(TestCase test_) {
51 if (!test_.isComplete) {
52 return '''
53 <tr>
54 <td>${test_.id}</td>
55 <td class="unittest-error">NO STATUS</td>
56 <td>Test did not complete</td>
57 </tr>''';
58 }
59
60 var html = '''
61 <tr>
62 <td>${test_.id}</td>
63 <td class="unittest-${test_.result}">${test_.result.toUpperCase()}</td>
64 <td>Expectation: ${test_.description}. ${_htmlEscape(test_.message)}</td >
65 </tr>''';
66
67 if (test_.stackTrace != null) {
68 html = '$html<tr><td></td><td colspan="2"><pre>${_htmlEscape(test_.stackTrac e)}</pre></td></tr>';
69 }
70
71 return html;
72 }
73
74 //TODO(pquitslund): Move to a common lib
75 String _htmlEscape(String string) {
76 return string.replaceAll('&', '&amp;')
77 .replaceAll('<','&lt;')
78 .replaceAll('>','&gt;');
79 }
OLDNEW
« no previous file with comments | « lib/unittest/html_enhanced_config.dart ('k') | lib/unittest/interactive_html_config.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698