Skip to content

Commit fd6e962

Browse files
committed
nvim: cleanup .nvimlog file to use filepath.Walk
1 parent e3ddf88 commit fd6e962

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

nvim/nvim_test.go

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package nvim
22

33
import (
44
"bytes"
5+
"context"
56
"errors"
67
"fmt"
78
"log"
@@ -15,31 +16,64 @@ import (
1516
"time"
1617
)
1718

18-
func newChildProcess(tb testing.TB) (*Nvim, func()) {
19+
func newChildProcess(tb testing.TB) (v *Nvim, cleanup func()) {
1920
tb.Helper()
2021

21-
v, err := NewChildProcess(
22-
ChildProcessArgs("-u", "NONE", "-n", "--embed", "--headless"),
22+
ctx := context.Background()
23+
n, err := NewChildProcess(
24+
ChildProcessArgs("-u", "NONE", "-n", "--embed", "--headless", "--noplugin"),
25+
ChildProcessContext(ctx),
2326
ChildProcessLogf(tb.Logf),
2427
)
2528
if err != nil {
2629
tb.Fatal(err)
2730
}
31+
v = n
2832

2933
done := make(chan error, 1)
3034
go func() {
3135
done <- v.Serve()
3236
}()
3337

34-
return v, func() {
38+
cleanup = func() {
3539
if err := v.Close(); err != nil {
3640
tb.Fatal(err)
3741
}
3842

39-
if _, err := os.Stat(".nvimlog"); err == nil {
40-
os.RemoveAll(".nvimlog")
43+
select {
44+
case err := <-done:
45+
if err != nil {
46+
tb.Fatal(err)
47+
}
48+
}
49+
50+
const nvimlogFile = ".nvimlog"
51+
wd, err := os.Getwd()
52+
if err != nil {
53+
tb.Fatal(err)
54+
}
55+
if walkErr := filepath.Walk(wd, func(path string, info os.FileInfo, err error) error {
56+
if err != nil {
57+
return err
58+
}
59+
60+
if info.IsDir() {
61+
return nil
62+
}
63+
64+
if fname := info.Name(); fname == nvimlogFile {
65+
if err := os.RemoveAll(path); err != nil {
66+
return fmt.Errorf("failed to remove %s file: %w", path, err)
67+
}
68+
}
69+
70+
return nil
71+
}); walkErr != nil {
72+
tb.Fatal(fmt.Errorf("walkErr: %w", errors.Unwrap(walkErr)))
4173
}
4274
}
75+
76+
return v, cleanup
4377
}
4478

4579
func TestAPI(t *testing.T) {

0 commit comments

Comments
 (0)