github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/tools/tfilt/tfilt.go (about) 1 // Copyright 2015 Keybase, Inc. All rights reserved. Use of 2 // this source code is governed by the included BSD license. 3 4 package main 5 6 // tfilt is a scrappy little program to make the copious test_logger 7 // output on test failures a little easier to read. 8 // 9 // It removes the " test_logger.go:48:" prefix when it 10 // appears. It also marks the failures with bars of asterisks and 11 // collects the list of failing tests to display later. 12 // 13 // To install: 14 // 15 // // install it to $GOPATH/bin 16 // go install 17 // 18 // To use: 19 // 20 // go test | tfilt 21 // 22 23 import ( 24 "bufio" 25 "fmt" 26 "os" 27 "regexp" 28 "strings" 29 ) 30 31 func main() { 32 var failures []string 33 bar := strings.Repeat("*", 80) 34 re := regexp.MustCompile(`^\ttest_logger\.go:\d+:`) 35 scanner := bufio.NewScanner(os.Stdin) 36 for scanner.Scan() { 37 line := scanner.Text() 38 if strings.HasPrefix(line, "--- FAIL") { 39 failures = append(failures, line) 40 line = bar + "\n" + line + "\n" + bar 41 } else { 42 line = re.ReplaceAllString(line, "\t") 43 } 44 fmt.Println(line) 45 } 46 if err := scanner.Err(); err != nil { 47 fmt.Fprintln(os.Stderr, "reading standard input:", err) 48 } 49 50 if len(failures) > 0 { 51 fmt.Println("failures:") 52 for _, f := range failures { 53 fmt.Println(f) 54 } 55 } 56 }