Skip to content

Commit

Permalink
iotest.Writer => ioutil.TestLogWriter
Browse files Browse the repository at this point in the history
Drop the partial implementation of a testing.T writer (iotest.Writer)
in favor of the more complete implementation in go.abhg.dev/io/ioutil.
  • Loading branch information
abhinav committed Jan 21, 2025
1 parent 63d9cac commit d26638d
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 80 deletions.
10 changes: 5 additions & 5 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
"strings"
"testing"

"github.com/abhinav/tmux-fastcopy/internal/iotest"
"github.com/abhinav/tmux-fastcopy/internal/tmux"
"github.com/abhinav/tmux-fastcopy/internal/tmux/tmuxopt"
"github.com/abhinav/tmux-fastcopy/internal/tmux/tmuxtest"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.abhg.dev/io/ioutil"
"pgregory.net/rapid"
)

Expand Down Expand Up @@ -272,7 +272,7 @@ func TestConfigFlags(t *testing.T) {

var cfg config
fset := flag.NewFlagSet(t.Name(), flag.ContinueOnError)
fset.SetOutput(iotest.Writer(t))
fset.SetOutput(ioutil.TestLogWriter(t, ""))
cfg.RegisterFlags(fset)

err := fset.Parse(tt.give)
Expand All @@ -291,7 +291,7 @@ func TestConfigFlags(t *testing.T) {
args := cfg.Flags()

fset := flag.NewFlagSet(t.Name(), flag.ContinueOnError)
fset.SetOutput(iotest.Writer(t))
fset.SetOutput(ioutil.TestLogWriter(t, ""))
var got config
got.RegisterFlags(fset)

Expand Down Expand Up @@ -485,7 +485,7 @@ func TestConfigFlags_rapid(t *testing.T) {
}

flag := flag.NewFlagSet(t.Name(), flag.ContinueOnError)
flag.SetOutput(iotest.Writer(t))
flag.SetOutput(ioutil.TestLogWriter(t, ""))

Check failure on line 488 in config_test.go

View workflow job for this annotation

GitHub Actions / Lint

cannot use t (variable of type *rapid.T) as ioutil.TestLogger value in argument to ioutil.TestLogWriter: *rapid.T does not implement ioutil.TestLogger (missing method Cleanup) (typecheck)

Check failure on line 488 in config_test.go

View workflow job for this annotation

GitHub Actions / Unit Test

cannot use t (variable of type *rapid.T) as ioutil.TestLogger value in argument to ioutil.TestLogWriter: *rapid.T does not implement ioutil.TestLogger (missing method Cleanup)

var got config
got.RegisterFlags(flag)
Expand All @@ -507,7 +507,7 @@ func TestUsageHasAllConfigFlags(t *testing.T) {
// _usage.

fset := flag.NewFlagSet(t.Name(), flag.ContinueOnError)
fset.SetOutput(iotest.Writer(t))
fset.SetOutput(ioutil.TestLogWriter(t, ""))
new(config).RegisterFlags(fset)

fset.VisitAll(func(f *flag.Flag) {
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/abhinav/tmux-fastcopy

go 1.23.3
go 1.23.4

toolchain go1.23.5

require (
github.com/benbjohnson/clock v1.3.5
Expand All @@ -11,6 +13,7 @@ require (
github.com/rivo/uniseg v0.4.7
github.com/stretchr/testify v1.10.0
go.abhg.dev/algorithm/huffman v0.2.0
go.abhg.dev/io/ioutil v0.1.0
go.uber.org/multierr v1.11.0
pgregory.net/rapid v1.1.0
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.abhg.dev/algorithm/huffman v0.2.0 h1:ABToWAM+WRXa2jqwzvyN17iNn5MMqxXtFZ7b+RmRrjU=
go.abhg.dev/algorithm/huffman v0.2.0/go.mod h1:FR+G7qqDYLe4hQ+8dFp6a3PjfNkg3MLCW0/oV3h6Py0=
go.abhg.dev/io/ioutil v0.1.0 h1:YGGMzh9HT52JYuVWbnr/E5GkYHbL3yRNDjcxFDaUHNk=
go.abhg.dev/io/ioutil v0.1.0/go.mod h1:79IIyZVWxNZE8hBxMtubM8zJFPs+2NCqHYfWeH3X6hM=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down
6 changes: 3 additions & 3 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import (
"testing"
"time"

"github.com/abhinav/tmux-fastcopy/internal/iotest"
"github.com/creack/pty"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.abhg.dev/io/ioutil"
"go.uber.org/multierr"
)

Expand Down Expand Up @@ -634,10 +634,10 @@ type virtualTmuxConfig struct {
}

func (cfg *virtualTmuxConfig) Build(t testing.TB) *virtualTmux {
stderr := iotest.Writer(t)
stderr := ioutil.TestLogWriter(t, "")
cmd := exec.Command(cfg.Tmux)
cmd.Env = cfg.Env
cmd.Stderr = iotest.Writer(t)
cmd.Stderr = ioutil.TestLogWriter(t, "")
cmd.Dir = cfg.Dir

t.Logf("Starting tmux with size %dx%d", cfg.Width, cfg.Height)
Expand Down
4 changes: 2 additions & 2 deletions integration/unquote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"strings"
"testing"

"github.com/abhinav/tmux-fastcopy/internal/iotest"
"github.com/abhinav/tmux-fastcopy/internal/tmux/tmuxopt"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.abhg.dev/io/ioutil"
)

func TestUnquoteTmuxOptions(t *testing.T) {
Expand Down Expand Up @@ -39,7 +39,7 @@ func TestUnquoteTmuxOptions(t *testing.T) {
"SHELL=/bin/sh",
"TMUX_TMPDIR=" + tmpDir,
}
cmdout := iotest.Writer(t)
cmdout := ioutil.TestLogWriter(t, "")

cmd := exec.Command(tmuxExe, "start-server", ";", "new-session", "-d")
cmd.Dir = root
Expand Down
28 changes: 0 additions & 28 deletions internal/iotest/writer.go

This file was deleted.

37 changes: 0 additions & 37 deletions internal/iotest/writer_test.go

This file was deleted.

4 changes: 2 additions & 2 deletions internal/log/logtest/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ package logtest
import (
"testing"

"github.com/abhinav/tmux-fastcopy/internal/iotest"
"github.com/abhinav/tmux-fastcopy/internal/log"
"go.abhg.dev/io/ioutil"
)

// NewLogger builds a logger at debug level that writes to a testing.T.
func NewLogger(t testing.TB) *log.Logger {
return log.New(iotest.Writer(t)).WithLevel(log.Debug)
return log.New(ioutil.TestLogWriter(t, "")).WithLevel(log.Debug)
}
4 changes: 2 additions & 2 deletions wrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"testing"

"github.com/abhinav/tmux-fastcopy/internal/envtest"
"github.com/abhinav/tmux-fastcopy/internal/iotest"
"github.com/abhinav/tmux-fastcopy/internal/log/logtest"
"github.com/abhinav/tmux-fastcopy/internal/tmux"
"github.com/abhinav/tmux-fastcopy/internal/tmux/tmuxtest"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.abhg.dev/io/ioutil"
)

func TestWrapper(t *testing.T) {
Expand Down Expand Up @@ -69,7 +69,7 @@ func TestWrapper(t *testing.T) {
mockTmux.EXPECT().NewSession(gomock.Any()).
Do(func(req tmux.NewSessionRequest) {
fset := flag.NewFlagSet(_name, flag.ContinueOnError)
fset.SetOutput(iotest.Writer(t))
fset.SetOutput(ioutil.TestLogWriter(t, ""))

var gotConfig config
gotConfig.RegisterFlags(fset)
Expand Down

0 comments on commit d26638d

Please sign in to comment.