Skip to content

Commit

Permalink
Enable std.test colors for terminals only
Browse files Browse the repository at this point in the history
With the introduction of Stdout.terminal?, we can now automatically
disable the use of colors for test output if the test suite isn't
connected to a terminal.

In addition, the use of colors can be forcefully disabled by setting the
NO_COLOR environment variable to a non-empty value.

Changelog: changed
  • Loading branch information
yorickpeterse committed Sep 2, 2024
1 parent fc50814 commit 47907c4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions std/src/std/test.inko
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,9 @@ class pub Tests {

# The reporter to use for producing test output.
#
# This defaults to the `Plain` reporter that writes to STDOUT.
# This defaults to the `Plain` reporter that writes to STDOUT. The use of
# colors is enabled if STDOUT is connected to a terminal, unless the
# `NO_COLOR` environment variable is set to a non-empty value.
let pub @reporter: Reporter

# The filter to apply to decide which tests to run.
Expand Down Expand Up @@ -488,11 +490,17 @@ class pub Tests {

# Returns a new test tests with its default settings.
fn pub static new -> Tests {
let out = Stdout.new
let colors = match env.opt('NO_COLOR') {
case Some(v) if v.size > 0 -> false
case _ -> out.terminal?
}

Tests(
tests: [],
children: [],
concurrency: cpu_cores,
reporter: Plain.new(out: Stdout.new, colors: true) as Reporter,
reporter: Plain.new(out, colors) as Reporter,
filter: Filter.None,
seed: Option.None,
)
Expand Down

0 comments on commit 47907c4

Please sign in to comment.