Skip to content

Commit

Permalink
Use hue for colouring (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
FollowTheProcess authored Jan 13, 2025
1 parent 4356a08 commit 7b611e3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 22 deletions.
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ module github.com/FollowTheProcess/test
go 1.23

require (
github.com/FollowTheProcess/snapshot v0.3.0
github.com/fatih/color v1.18.0
github.com/FollowTheProcess/hue v0.1.1
github.com/FollowTheProcess/snapshot v0.4.0
golang.org/x/tools v0.29.0
)

require (
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/term v0.28.0 // indirect
)
13 changes: 8 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
github.com/FollowTheProcess/snapshot v0.3.0 h1:LpTQCtuT0dTeWi2HhmHgHu17TtZlRPMBGtOzlQfh9HY=
github.com/FollowTheProcess/snapshot v0.3.0/go.mod h1:ADH1yxxSZgDhTH5hUe+g0gB+ZQ/TGELfPHTw853qJjw=
github.com/FollowTheProcess/hue v0.1.1 h1:7lbqq2pwIsB5qvir1RvIvNQLXWOdTl/IOqHHxI1vJu8=
github.com/FollowTheProcess/hue v0.1.1/go.mod h1:T9IMtR7WyOoEKreUHsnEZnmn86su94g9Y/Hb4WszBUo=
github.com/FollowTheProcess/snapshot v0.4.0 h1:/fbFtmDG4wO0rp1X2uSlkdlbx09oSDZbjut0AwaO5V0=
github.com/FollowTheProcess/snapshot v0.4.0/go.mod h1:F1o4iTqDixcDJjKOVIAIKdjCbVyVgKEehkmpZbNtxlQ=
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.28.0 h1:/Ts8HFuMR2E6IP/jlo7QVLZHggjKQbhu/7H0LJFr3Gg=
golang.org/x/term v0.28.0/go.mod h1:Sw/lC2IAUZ92udQNf3WodGtn4k/XoLyZoh8v/8uiwek=
golang.org/x/tools v0.29.0 h1:Xx0h3TtM9rzQpQuR4dKLrdglAmCEN5Oi+P74JdhdzXE=
golang.org/x/tools v0.29.0/go.mod h1:KMQVMRsVxU6nHCFXrBPhDB8XncLNLM0lIy/F14RP588=
16 changes: 5 additions & 11 deletions test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import (
"sync"
"testing"

"github.com/FollowTheProcess/hue"
"github.com/FollowTheProcess/test/internal/diff"
"github.com/fatih/color"
)

var (
header = color.New(color.FgCyan, color.Bold)
green = color.New(color.FgGreen)
red = color.New(color.FgRed)
const (
header = hue.Cyan | hue.Bold
green = hue.Green
red = hue.Red
)

// Equal fails if got != want.
Expand Down Expand Up @@ -441,12 +441,6 @@ func CaptureOutput(tb testing.TB, fn func() error) (stdout, stderr string) {

// prettyDiff takes a string diff in unified diff format and colourises it for easier viewing.
func prettyDiff(diff string) string {
// color by default will look at whether stdout is a tty and the value of the
// $NO_COLOR env var, we need to override this because go test buffers output
// so it will appear as if it's not a tty, even though the end result is to show
// the output in a terminal. It still respects the value of $NO_COLOR.
color.NoColor = false || os.Getenv("NO_COLOR") != ""

lines := strings.Split(diff, "\n")
for i := 0; i < len(lines); i++ {
trimmed := strings.TrimSpace(lines[i])
Expand Down
3 changes: 1 addition & 2 deletions test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,7 @@ func TestTest(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
buf := &bytes.Buffer{}
tb := &TB{out: buf}
t.Setenv("NO_COLOR", "true")
snap := snapshot.New(t, snapshot.Update(*update))
snap := snapshot.New(t, snapshot.Update(*update), snapshot.Color(false))

if tb.failed {
t.Fatalf("%s initial failed state should be false", tt.name)
Expand Down

0 comments on commit 7b611e3

Please sign in to comment.