@@ -2,6 +2,7 @@ package nvim
2
2
3
3
import (
4
4
"bytes"
5
+ "context"
5
6
"errors"
6
7
"fmt"
7
8
"log"
@@ -15,31 +16,64 @@ import (
15
16
"time"
16
17
)
17
18
18
- func newChildProcess (tb testing.TB ) (* Nvim , func ()) {
19
+ func newChildProcess (tb testing.TB ) (v * Nvim , cleanup func ()) {
19
20
tb .Helper ()
20
21
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 ),
23
26
ChildProcessLogf (tb .Logf ),
24
27
)
25
28
if err != nil {
26
29
tb .Fatal (err )
27
30
}
31
+ v = n
28
32
29
33
done := make (chan error , 1 )
30
34
go func () {
31
35
done <- v .Serve ()
32
36
}()
33
37
34
- return v , func () {
38
+ cleanup = func () {
35
39
if err := v .Close (); err != nil {
36
40
tb .Fatal (err )
37
41
}
38
42
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 )))
41
73
}
42
74
}
75
+
76
+ return v , cleanup
43
77
}
44
78
45
79
func TestAPI (t * testing.T ) {
0 commit comments