-
Notifications
You must be signed in to change notification settings - Fork 1
/
tfilt.go
56 lines (51 loc) · 1.22 KB
/
tfilt.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
// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package main
// tfilt is a scrappy little program to make the copious test_logger
// output on test failures a little easier to read.
//
// It removes the " test_logger.go:48:" prefix when it
// appears. It also marks the failures with bars of asterisks and
// collects the list of failing tests to display later.
//
// To install:
//
// // install it to $GOPATH/bin
// go install
//
// To use:
//
// go test | tfilt
//
import (
"bufio"
"fmt"
"os"
"regexp"
"strings"
)
func main() {
var failures []string
bar := strings.Repeat("*", 80)
re := regexp.MustCompile(`^\ttest_logger\.go:\d+:`)
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
line := scanner.Text()
if strings.HasPrefix(line, "--- FAIL") {
failures = append(failures, line)
line = bar + "\n" + line + "\n" + bar
} else {
line = re.ReplaceAllString(line, "\t")
}
fmt.Println(line)
}
if err := scanner.Err(); err != nil {
fmt.Fprintln(os.Stderr, "reading standard input:", err)
}
if len(failures) > 0 {
fmt.Println("failures:")
for _, f := range failures {
fmt.Println(f)
}
}
}