Skip to content

Commit

Permalink
Allow disabling color with flag GINGKO_COLOR
Browse files Browse the repository at this point in the history
When integrating golang packages using ginkgo, such as CI/CD
systems or Linux distributions, there are situations where the
test output is tracked in text files and presented without ANSI
color decoding.  For those situations, in particular when the tests
are invoked directly by `go test`,  and thus without the `gingko`
CLI driver, controller color output via an environment variable
can be much more convenient

Signed-off-by: Reinhard Tartler <[email protected]>
  • Loading branch information
siretart committed Oct 7, 2024
1 parent 104752f commit 41c9116
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
9 changes: 9 additions & 0 deletions core_dsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"io"
"os"
"path/filepath"
"strconv"
"strings"

"github.com/go-logr/logr"
Expand Down Expand Up @@ -257,6 +258,14 @@ func RunSpecs(t GinkgoTestingT, description string, args ...interface{}) bool {
suiteLabels := extractSuiteConfiguration(args)

var reporter reporters.Reporter
reporterConfig := reporterConfig
if value, present := os.LookupEnv("GINGKO_COLOR"); present {
b, err := strconv.ParseBool(value)
if err == nil {
reporterConfig.NoColor = !b
}
}

if suiteConfig.ParallelTotal == 1 {
reporter = reporters.NewDefaultReporter(reporterConfig, formatter.ColorableStdOut)
outputInterceptor = internal.NoopOutputInterceptor{}
Expand Down
11 changes: 10 additions & 1 deletion types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,16 @@ func (rc ReporterConfig) WillGenerateReport() bool {
}

func NewDefaultReporterConfig() ReporterConfig {
return ReporterConfig{}
c := ReporterConfig{}

if value, present := os.LookupEnv("GINGKO_COLOR"); present {
b, err := strconv.ParseBool(value)
if err == nil {
c.NoColor = !b
}
}

return c
}

// Configuration for the Ginkgo CLI
Expand Down

0 comments on commit 41c9116

Please sign in to comment.