@@ -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
8788func 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) {
168167func 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) {
181179func 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