Skip to content

Commit 36de879

Browse files
committed
nvim: fix newChildProcess cleanup logic
Signed-off-by: Koichi Shiraishi <[email protected]>
1 parent db8d22d commit 36de879

File tree

3 files changed

+10
-17
lines changed

3 files changed

+10
-17
lines changed

nvim/api_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,7 @@ func clearBuffer(tb testing.TB, v *Nvim, buffer Buffer) {
7575
func TestAPI(t *testing.T) {
7676
t.Parallel()
7777

78-
v, cleanup := newChildProcess(t)
79-
t.Cleanup(func() {
80-
cleanup()
81-
})
78+
v := newChildProcess(t)
8279

8380
apiInfo, err := v.APIInfo()
8481
if err != nil {

nvim/helpers_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ var readerData = []string{
1616
}
1717

1818
func TestBufferReader(t *testing.T) {
19-
v, cleanup := newChildProcess(t)
20-
defer cleanup()
19+
v := newChildProcess(t)
2120
b, err := v.CurrentBuffer()
2221
if err != nil {
2322
t.Fatal(err)

nvim/nvim_test.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import (
1313
"time"
1414
)
1515

16-
func newChildProcess(tb testing.TB) (v *Nvim, cleanup func()) {
16+
// newChildProcess returns the new *Nvim, and registers cleanup to tb.Cleanup.
17+
func newChildProcess(tb testing.TB) (v *Nvim) {
1718
tb.Helper()
1819

1920
envs := os.Environ()
@@ -41,7 +42,7 @@ func newChildProcess(tb testing.TB) (v *Nvim, cleanup func()) {
4142
done <- v.Serve()
4243
}()
4344

44-
cleanup = func() {
45+
tb.Cleanup(func() {
4546
if err := v.Close(); err != nil {
4647
tb.Fatal(err)
4748
}
@@ -75,13 +76,13 @@ func newChildProcess(tb testing.TB) (v *Nvim, cleanup func()) {
7576
}); walkErr != nil && !os.IsNotExist(err) {
7677
tb.Fatal(fmt.Errorf("walkErr: %w", errors.Unwrap(walkErr)))
7778
}
78-
}
79+
})
7980

8081
if err := v.Command("set packpath="); err != nil {
8182
tb.Fatal(err)
8283
}
8384

84-
return v, cleanup
85+
return v
8586
}
8687

8788
func TestDial(t *testing.T) {
@@ -91,9 +92,7 @@ func TestDial(t *testing.T) {
9192

9293
t.Parallel()
9394

94-
v1, cleanup := newChildProcess(t)
95-
defer cleanup()
96-
95+
v1 := newChildProcess(t)
9796
var addr string
9897
if err := v1.Eval("$NVIM_LISTEN_ADDRESS", &addr); err != nil {
9998
t.Fatal(err)
@@ -168,8 +167,7 @@ func TestEmbedded(t *testing.T) {
168167
func TestCallWithNoArgs(t *testing.T) {
169168
t.Parallel()
170169

171-
v, cleanup := newChildProcess(t)
172-
defer cleanup()
170+
v := newChildProcess(t)
173171

174172
var wd string
175173
err := v.Call("getcwd", &wd)
@@ -181,8 +179,7 @@ func TestCallWithNoArgs(t *testing.T) {
181179
func TestStructValue(t *testing.T) {
182180
t.Parallel()
183181

184-
v, cleanup := newChildProcess(t)
185-
defer cleanup()
182+
v := newChildProcess(t)
186183

187184
t.Run("Nvim", func(t *testing.T) {
188185
var expected, actual struct {

0 commit comments

Comments
 (0)