init.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. )
  56. var (
  57. greenColor = "\033[32m"
  58. yellowColor = "\033[33m"
  59. redColor = "\033[31m"
  60. resetColor = "\033[0m"
  61. )
  62. var consoleStatistics = NewStatisticsReporter(NewPrinter(NewConsole()))
  63. func SuppressConsoleStatistics() { consoleStatistics.Suppress() }
  64. func PrintConsoleStatistics() { consoleStatistics.PrintSummary() }
  65. // QuiteMode disables all console output symbols. This is only meant to be used
  66. // for tests that are internal to goconvey where the output is distracting or
  67. // otherwise not needed in the test output.
  68. func QuietMode() {
  69. success, failure, error_, skip, dotSuccess, dotFailure, dotError, dotSkip = "", "", "", "", "", "", "", ""
  70. }
  71. func monochrome() {
  72. greenColor, yellowColor, redColor, resetColor = "", "", "", ""
  73. }
  74. func isColorableTerminal() bool {
  75. return strings.Contains(os.Getenv("TERM"), "color")
  76. }
  77. // This interface allows us to pass the *testing.T struct
  78. // throughout the internals of this tool without ever
  79. // having to import the "testing" package.
  80. type T interface {
  81. Fail()
  82. }