-
Notifications
You must be signed in to change notification settings - Fork 0
/
html_print.dart
executable file
·79 lines (69 loc) · 2.6 KB
/
html_print.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/** This file is sourced by both dom_config.dart and html_config.dart. */
/** Creates a table showing tests results in HTML. */
void _showResultsInPage(int passed, int failed, int errors,
List<TestCase> results, bool isLayoutTest, String uncaughtError) {
if (isLayoutTest && (passed == results.length) && uncaughtError == null) {
document.body.innerHTML = "PASS";
} else {
var newBody = new StringBuffer();
newBody.add("<table class='unittest-table'><tbody>");
newBody.add(passed == results.length && uncaughtError == null
? "<tr><td colspan='3' class='unittest-pass'>PASS</td></tr>"
: "<tr><td colspan='3' class='unittest-fail'>FAIL</td></tr>");
for (final test_ in results) {
newBody.add(_toHtml(test_));
}
if (uncaughtError != null) {
newBody.add('''<tr>
<td>--</td>
<td class="unittest-error">ERROR</td>
<td>Uncaught error: $uncaughtError</td>
</tr>''');
}
if (passed == results.length && uncaughtError == null) {
newBody.add("""
<tr><td colspan='3' class='unittest-pass'>
All ${passed} tests passed
</td></tr>""");
} else {
newBody.add("""
<tr><td colspan='3'>Total
<span class='unittest-pass'>${passed} passed</span>,
<span class='unittest-fail'>${failed} failed</span>
<span class='unittest-error'>
${errors + (uncaughtError == null ? 0 : 1)} errors</span>
</td></tr>""");
}
newBody.add("</tbody></table>");
document.body.innerHTML = newBody.toString();
}
}
String _toHtml(TestCase test_) {
if (!test_.isComplete) {
return '''
<tr>
<td>${test_.id}</td>
<td class="unittest-error">NO STATUS</td>
<td>Test did not complete</td>
</tr>''';
}
var html = '''
<tr>
<td>${test_.id}</td>
<td class="unittest-${test_.result}">${test_.result.toUpperCase()}</td>
<td>Expectation: ${test_.description}. ${_htmlEscape(test_.message)}</td>
</tr>''';
if (test_.stackTrace != null) {
html = '$html<tr><td></td><td colspan="2"><pre>${_htmlEscape(test_.stackTrace)}</pre></td></tr>';
}
return html;
}
//TODO(pquitslund): Move to a common lib
String _htmlEscape(String string) {
return string.replaceAll('&', '&')
.replaceAll('<','<')
.replaceAll('>','>');
}