init.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package reporting
  2. import (
  3. "os"
  4. "runtime"
  5. "strings"
  6. )
  7. func init() {
  8. if !isColorableTerminal() {
  9. monochrome()
  10. }
  11. if runtime.GOOS == "windows" {
  12. success, failure, error_ = dotSuccess, dotFailure, dotError
  13. }
  14. }
  15. func BuildJsonReporter() Reporter {
  16. out := NewPrinter(NewConsole())
  17. return NewReporters(
  18. NewGoTestReporter(),
  19. NewJsonReporter(out))
  20. }
  21. func BuildDotReporter() Reporter {
  22. out := NewPrinter(NewConsole())
  23. return NewReporters(
  24. NewGoTestReporter(),
  25. NewDotReporter(out),
  26. NewProblemReporter(out),
  27. consoleStatistics)
  28. }
  29. func BuildStoryReporter() Reporter {
  30. out := NewPrinter(NewConsole())
  31. return NewReporters(
  32. NewGoTestReporter(),
  33. NewStoryReporter(out),
  34. NewProblemReporter(out),
  35. consoleStatistics)
  36. }
  37. func BuildSilentReporter() Reporter {
  38. out := NewPrinter(NewConsole())
  39. return NewReporters(
  40. NewGoTestReporter(),
  41. NewSilentProblemReporter(out))
  42. }
  43. var (
  44. newline = "\n"
  45. success = "✔"
  46. failure = "✘"
  47. error_ = "🔥"
  48. skip = "⚠"
  49. dotSuccess = "."
  50. dotFailure = "x"
  51. dotError = "E"
  52. dotSkip = "S"
  53. errorTemplate = "* %s \nLine %d: - %v \n%s\n"
  54. failureTemplate = "* %s \nLine %d:\n%s\n"
  55. stackTemplate = "%s\n"
  56. )
  57. var (
  58. greenColor = "\033[32m"
  59. yellowColor = "\033[33m"
  60. redColor = "\033[31m"
  61. resetColor = "\033[0m"
  62. )
  63. var consoleStatistics = NewStatisticsReporter(NewPrinter(NewConsole()))
  64. func SuppressConsoleStatistics() { consoleStatistics.Suppress() }
  65. func PrintConsoleStatistics() { consoleStatistics.PrintSummary() }
  66. // QuietMode disables all console output symbols. This is only meant to be used
  67. // for tests that are internal to goconvey where the output is distracting or
  68. // otherwise not needed in the test output.
  69. func QuietMode() {
  70. success, failure, error_, skip, dotSuccess, dotFailure, dotError, dotSkip = "", "", "", "", "", "", "", ""
  71. }
  72. func monochrome() {
  73. greenColor, yellowColor, redColor, resetColor = "", "", "", ""
  74. }
  75. func isColorableTerminal() bool {
  76. return strings.Contains(os.Getenv("TERM"), "color")
  77. }
  78. // This interface allows us to pass the *testing.T struct
  79. // throughout the internals of this tool without ever
  80. // having to import the "testing" package.
  81. type T interface {
  82. Fail()
  83. }