-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmain.go
97 lines (89 loc) · 2.16 KB
/
main.go
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
_ "embed"
"encoding/xml"
"fmt"
"os"
"strconv"
"strings"
"time"
"github.com/jstemmer/go-junit-report/formatter"
)
//go:embed style.css
var styles string
func printTest(s formatter.JUnitTestSuite, c formatter.JUnitTestCase) {
id := fmt.Sprintf("%s.%s.%s", s.Name, c.Classname, c.Name)
class, text := "passed", "Pass"
f := c.Failure
if f != nil {
class, text = "failed", "Fail"
}
k := c.SkipMessage
if k != nil {
class, text = "skipped", "Skip"
}
fmt.Printf("<div class='%s' id='%s'>\n", class, id)
fmt.Printf("<a href='#%s'>%s <span class='badge'>%s</span></a>\n", id, c.Name, text)
fmt.Printf("<div class='expando'>\n")
if f != nil {
fmt.Printf("<div class='content'>%s</div>\n", f.Contents)
} else if k != nil {
fmt.Printf("<div class='content'>%s</div>\n", k.Message)
}
d, _ := time.ParseDuration(c.Time)
fmt.Printf("<p class='duration' title='Test duration'>%v</p>\n", d)
fmt.Printf("</div>\n")
fmt.Printf("</div>\n")
}
func main() {
suites := &formatter.JUnitTestSuites{}
err := xml.NewDecoder(os.Stdin).Decode(suites)
if err != nil {
panic(err)
}
fmt.Println("<html>")
fmt.Println("<head>")
fmt.Println("<meta charset=\"UTF-8\">")
fmt.Println("<style>")
fmt.Println(styles)
fmt.Println("</style>")
fmt.Println("</head>")
fmt.Println("<body>")
failures, total := 0, 0
for _, s := range suites.Suites {
failures += s.Failures
total += len(s.TestCases)
}
fmt.Printf("<p>%d of %d tests failed</p>\n", failures, total)
for _, s := range suites.Suites {
if s.Failures > 0 {
printSuiteHeader(s)
for _, c := range s.TestCases {
if f := c.Failure; f != nil {
printTest(s, c)
}
}
}
}
for _, s := range suites.Suites {
printSuiteHeader(s)
for _, c := range s.TestCases {
if c.Failure == nil {
printTest(s, c)
}
}
}
fmt.Println("</body>")
fmt.Println("</html>")
}
func printSuiteHeader(s formatter.JUnitTestSuite) {
fmt.Println("<h4>")
fmt.Println(s.Name)
for _, p := range s.Properties {
if strings.HasPrefix(p.Name, "coverage.") {
v, _ := strconv.ParseFloat(p.Value, 10)
fmt.Printf("<span class='coverage' title='%s'>%.0f%%</span>\n", p.Name, v)
}
}
fmt.Println("</h4>")
}