Skip to content

Commit d1a1862

Browse files
authored
iotest.Writer => ioutil.TestLogWriter (#213)
Drop the partial implementation of a testing.T writer (iotest.Writer) in favor of the more complete implementation in go.abhg.dev/io/ioutil.
1 parent 63d9cac commit d1a1862

File tree

11 files changed

+28
-81
lines changed

11 files changed

+28
-81
lines changed

config_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import (
55
"strings"
66
"testing"
77

8-
"github.com/abhinav/tmux-fastcopy/internal/iotest"
98
"github.com/abhinav/tmux-fastcopy/internal/tmux"
109
"github.com/abhinav/tmux-fastcopy/internal/tmux/tmuxopt"
1110
"github.com/abhinav/tmux-fastcopy/internal/tmux/tmuxtest"
1211
"github.com/golang/mock/gomock"
1312
"github.com/stretchr/testify/assert"
1413
"github.com/stretchr/testify/require"
14+
"go.abhg.dev/io/ioutil"
1515
"pgregory.net/rapid"
1616
)
1717

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

273273
var cfg config
274274
fset := flag.NewFlagSet(t.Name(), flag.ContinueOnError)
275-
fset.SetOutput(iotest.Writer(t))
275+
fset.SetOutput(ioutil.TestLogWriter(t, ""))
276276
cfg.RegisterFlags(fset)
277277

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

293293
fset := flag.NewFlagSet(t.Name(), flag.ContinueOnError)
294-
fset.SetOutput(iotest.Writer(t))
294+
fset.SetOutput(ioutil.TestLogWriter(t, ""))
295295
var got config
296296
got.RegisterFlags(fset)
297297

@@ -484,8 +484,10 @@ func TestConfigFlags_rapid(t *testing.T) {
484484
t.Skip()
485485
}
486486

487+
output, done := ioutil.PrintfWriter(t.Logf, "")
488+
defer done()
487489
flag := flag.NewFlagSet(t.Name(), flag.ContinueOnError)
488-
flag.SetOutput(iotest.Writer(t))
490+
flag.SetOutput(output)
489491

490492
var got config
491493
got.RegisterFlags(flag)
@@ -507,7 +509,7 @@ func TestUsageHasAllConfigFlags(t *testing.T) {
507509
// _usage.
508510

509511
fset := flag.NewFlagSet(t.Name(), flag.ContinueOnError)
510-
fset.SetOutput(iotest.Writer(t))
512+
fset.SetOutput(ioutil.TestLogWriter(t, ""))
511513
new(config).RegisterFlags(fset)
512514

513515
fset.VisitAll(func(f *flag.Flag) {

go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module github.com/abhinav/tmux-fastcopy
22

3-
go 1.23.3
3+
go 1.23.4
4+
5+
toolchain go1.23.5
46

57
require (
68
github.com/benbjohnson/clock v1.3.5
@@ -11,6 +13,7 @@ require (
1113
github.com/rivo/uniseg v0.4.7
1214
github.com/stretchr/testify v1.10.0
1315
go.abhg.dev/algorithm/huffman v0.2.0
16+
go.abhg.dev/io/ioutil v0.1.0
1417
go.uber.org/multierr v1.11.0
1518
pgregory.net/rapid v1.1.0
1619
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1
2727
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
2828
go.abhg.dev/algorithm/huffman v0.2.0 h1:ABToWAM+WRXa2jqwzvyN17iNn5MMqxXtFZ7b+RmRrjU=
2929
go.abhg.dev/algorithm/huffman v0.2.0/go.mod h1:FR+G7qqDYLe4hQ+8dFp6a3PjfNkg3MLCW0/oV3h6Py0=
30+
go.abhg.dev/io/ioutil v0.1.0 h1:YGGMzh9HT52JYuVWbnr/E5GkYHbL3yRNDjcxFDaUHNk=
31+
go.abhg.dev/io/ioutil v0.1.0/go.mod h1:79IIyZVWxNZE8hBxMtubM8zJFPs+2NCqHYfWeH3X6hM=
3032
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
3133
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
3234
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=

integration/go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
module github.com/abhinav/tmux-fastcopy/integration
22

3-
go 1.23.3
3+
go 1.23.4
4+
5+
toolchain go1.23.5
46

57
require (
68
github.com/abhinav/tmux-fastcopy v0.14.1
79
github.com/creack/pty v1.1.24
810
github.com/stretchr/testify v1.10.0
11+
go.abhg.dev/io/ioutil v0.1.0
912
go.uber.org/multierr v1.11.0
1013
)
1114

integration/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
88
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
99
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
1010
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
11+
go.abhg.dev/io/ioutil v0.1.0 h1:YGGMzh9HT52JYuVWbnr/E5GkYHbL3yRNDjcxFDaUHNk=
12+
go.abhg.dev/io/ioutil v0.1.0/go.mod h1:79IIyZVWxNZE8hBxMtubM8zJFPs+2NCqHYfWeH3X6hM=
1113
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
1214
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
1315
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=

integration/integration_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import (
1616
"testing"
1717
"time"
1818

19-
"github.com/abhinav/tmux-fastcopy/internal/iotest"
2019
"github.com/creack/pty"
2120
"github.com/stretchr/testify/assert"
2221
"github.com/stretchr/testify/require"
22+
"go.abhg.dev/io/ioutil"
2323
"go.uber.org/multierr"
2424
)
2525

@@ -634,10 +634,10 @@ type virtualTmuxConfig struct {
634634
}
635635

636636
func (cfg *virtualTmuxConfig) Build(t testing.TB) *virtualTmux {
637-
stderr := iotest.Writer(t)
637+
stderr := ioutil.TestLogWriter(t, "")
638638
cmd := exec.Command(cfg.Tmux)
639639
cmd.Env = cfg.Env
640-
cmd.Stderr = iotest.Writer(t)
640+
cmd.Stderr = ioutil.TestLogWriter(t, "")
641641
cmd.Dir = cfg.Dir
642642

643643
t.Logf("Starting tmux with size %dx%d", cfg.Width, cfg.Height)

integration/unquote_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import (
88
"strings"
99
"testing"
1010

11-
"github.com/abhinav/tmux-fastcopy/internal/iotest"
1211
"github.com/abhinav/tmux-fastcopy/internal/tmux/tmuxopt"
1312
"github.com/stretchr/testify/assert"
1413
"github.com/stretchr/testify/require"
14+
"go.abhg.dev/io/ioutil"
1515
)
1616

1717
func TestUnquoteTmuxOptions(t *testing.T) {
@@ -39,7 +39,7 @@ func TestUnquoteTmuxOptions(t *testing.T) {
3939
"SHELL=/bin/sh",
4040
"TMUX_TMPDIR=" + tmpDir,
4141
}
42-
cmdout := iotest.Writer(t)
42+
cmdout := ioutil.TestLogWriter(t, "")
4343

4444
cmd := exec.Command(tmuxExe, "start-server", ";", "new-session", "-d")
4545
cmd.Dir = root

internal/iotest/writer.go

Lines changed: 0 additions & 28 deletions
This file was deleted.

internal/iotest/writer_test.go

Lines changed: 0 additions & 37 deletions
This file was deleted.

internal/log/logtest/logger.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ package logtest
44
import (
55
"testing"
66

7-
"github.com/abhinav/tmux-fastcopy/internal/iotest"
87
"github.com/abhinav/tmux-fastcopy/internal/log"
8+
"go.abhg.dev/io/ioutil"
99
)
1010

1111
// NewLogger builds a logger at debug level that writes to a testing.T.
1212
func NewLogger(t testing.TB) *log.Logger {
13-
return log.New(iotest.Writer(t)).WithLevel(log.Debug)
13+
return log.New(ioutil.TestLogWriter(t, "")).WithLevel(log.Debug)
1414
}

0 commit comments

Comments
 (0)