main.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // tnse stands for Test aNd Show Error
  2. package main
  3. import (
  4. "bytes"
  5. "flag"
  6. "fmt"
  7. "io"
  8. "os"
  9. "os/exec"
  10. "time"
  11. "github.com/cryptix/go/logging"
  12. kitlog "github.com/go-kit/kit/log"
  13. )
  14. var log *kitlog.Context
  15. // flags
  16. var (
  17. timeout = flag.Duration("timeout", 3*time.Second, "how long to show the notifications")
  18. )
  19. func main() {
  20. logging.SetupLogging(nil)
  21. log = logging.Logger("tnse")
  22. flag.Parse()
  23. if len(os.Args) < 2 {
  24. logging.CheckFatal(fmt.Errorf("usage error"))
  25. }
  26. goTest := exec.Command("go", "test", os.Args[1])
  27. wd, err := os.Getwd()
  28. logging.CheckFatal(err)
  29. goTest.Dir = wd
  30. buf := new(bytes.Buffer)
  31. out := io.MultiWriter(buf, os.Stdout)
  32. goTest.Stderr = out
  33. goTest.Stdout = out
  34. start := time.Now()
  35. var passed bool
  36. err = goTest.Run()
  37. done := time.Now()
  38. if err != nil {
  39. log = log.With("err", err)
  40. log.Log("event", "run failed")
  41. } else {
  42. passed = true
  43. }
  44. err = notify(passed, buf.String())
  45. logging.CheckFatal(err)
  46. log = log.With("took", done.Sub(start))
  47. log = log.With("passed", passed)
  48. log.Log("event", "'go test' finished")
  49. }