forked from go-delve/delve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen-backend_test_health.go
111 lines (108 loc) · 2.47 KB
/
gen-backend_test_health.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package main
import (
"fmt"
"go/ast"
"go/parser"
"go/token"
"io"
"log"
"os"
"sort"
"strconv"
"strings"
)
func main() {
f, err := parser.ParseFile(new(token.FileSet), "pkg/proc/proc_test.go", nil, 0)
if err != nil {
log.Fatalf("could not compile proc_test.go: %v", err)
}
ntests := 0
skipped := make(map[string]map[string]int)
ast.Inspect(f, func(node ast.Node) bool {
switch node := node.(type) {
case *ast.File:
return true
case *ast.FuncDecl:
if !strings.HasPrefix(node.Name.Name, "Test") {
return false
}
ntests++
stmtLoop:
for _, stmt := range node.Body.List {
expr, isexpr := stmt.(*ast.ExprStmt)
if !isexpr {
continue
}
call, ok := expr.X.(*ast.CallExpr)
if !ok {
return false
}
fun, ok := call.Fun.(*ast.Ident)
if !ok {
return false
}
switch fun.Name {
case "skipOn":
reason, conditions := skipOnArgs(call.Args)
if reason == "N/A" {
ntests--
break stmtLoop
}
if skipped[conditions] == nil {
skipped[conditions] = make(map[string]int)
}
skipped[conditions][reason]++
case "skipUnlessOn":
ntests--
break stmtLoop
}
}
}
return false
})
var fh io.WriteCloser
if len(os.Args) > 1 && os.Args[1] == "-" {
fh = os.Stdout
} else {
fh, err = os.Create("./Documentation/backend_test_health.md")
if err != nil {
log.Fatalf("could not create backend_test_health.md: %v", err)
}
}
fmt.Fprintf(fh, "Tests skipped by each supported backend:\n\n")
conds := []string{}
for cond := range skipped {
conds = append(conds, cond)
}
sort.Strings(conds)
for _, cond := range conds {
tot := 0
for _, v := range skipped[cond] {
tot += v
}
perc := float64(tot) / float64(ntests) * 100
fmt.Fprintf(fh, "* %s skipped = %0.02g%% (%d/%d)\n", cond, perc, tot, ntests)
reasons := []string{}
for reason := range skipped[cond] {
reasons = append(reasons, reason)
}
sort.Strings(reasons)
for _, reason := range reasons {
fmt.Fprintf(fh, "\t* %d %s\n", skipped[cond][reason], reason)
}
}
err = fh.Close()
if err != nil {
log.Fatalf("could not close output file: %v", err)
}
}
func skipOnArgs(args []ast.Expr) (reason string, conditions string) {
reason, _ = strconv.Unquote(args[1].(*ast.BasicLit).Value)
conds := []string{}
for _, arg := range args[2:] {
cond, _ := strconv.Unquote(arg.(*ast.BasicLit).Value)
conds = append(conds, cond)
}
conditions = strings.Join(conds, "/")
return reason, conditions
}