Skip to content

Commit 9b44fee

Browse files
authored
Improve API tests #170
- Get expected runtime paths by evaluating a VimL expression. - Use equality operator to compare strings instead of reflect.DeepEqual. - Fix typo in event name.
1 parent 2be2dfb commit 9b44fee

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

nvim/api_test.go

+6-17
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"fmt"
88
"log"
99
"os"
10-
"os/exec"
1110
"path"
1211
"path/filepath"
1312
"reflect"
@@ -4459,20 +4458,10 @@ func testRuntime(v *Nvim) func(*testing.T) {
44594458
vimDiff := filepath.Join(runtimePath, "doc", "vim_diff.txt")
44604459
want := fmt.Sprintf("%s,%s", viDiff, vimDiff)
44614460

4462-
binName := BinaryName
4463-
if nvimCmd := *flagNvimPath; nvimCmd != "" {
4464-
binName = nvimCmd
4465-
}
4466-
binaryPath, err := exec.LookPath(binName)
4467-
if err != nil {
4461+
var wantPaths []string
4462+
if err := v.Eval("nvim_list_runtime_paths()", &wantPaths); err != nil {
44684463
t.Fatal(err)
44694464
}
4470-
nvimPrefix := filepath.Dir(filepath.Dir(binaryPath))
4471-
4472-
wantPaths := []string{
4473-
filepath.Join(nvimPrefix, "lib", "nvim"),
4474-
filepath.Join(nvimPrefix, "share", "nvim", "runtime"),
4475-
}
44764465
sort.Strings(wantPaths)
44774466

44784467
argName := filepath.Join("doc", "*_diff.txt")
@@ -4504,7 +4493,7 @@ func testRuntime(v *Nvim) func(*testing.T) {
45044493
got := strings.Join(paths, ",")
45054494
want := strings.Join(wantPaths, ",")
45064495
t.Logf("%s\n got: %v\nwant: %s", t.Name(), got, want)
4507-
if !reflect.DeepEqual(got, want) {
4496+
if got != want {
45084497
t.Fatalf("RuntimePaths():\n got %v\nwant %v", got, want)
45094498
}
45104499
})
@@ -4541,7 +4530,7 @@ func testRuntime(v *Nvim) func(*testing.T) {
45414530

45424531
got := strings.Join(paths, ",")
45434532
want := strings.Join(wantPaths, ",")
4544-
if !reflect.DeepEqual(got, want) {
4533+
if got != want {
45454534
t.Fatalf("RuntimePaths():\n got %v\nwant %v", paths, wantPaths)
45464535
}
45474536
})
@@ -5824,7 +5813,7 @@ func testAutocmd(v *Nvim) func(*testing.T) {
58245813
t.Fatal(err)
58255814
}
58265815

5827-
if err := v.ExecAutocmds(`User Test`, map[string]interface{}{"group": augID}); err != nil {
5816+
if err := v.ExecAutocmds(`User`, map[string]interface{}{"group": augID}); err != nil {
58285817
t.Fatal(err)
58295818
}
58305819

@@ -5933,7 +5922,7 @@ func testAutocmd(v *Nvim) func(*testing.T) {
59335922
t.Fatal(err)
59345923
}
59355924

5936-
b.ExecAutocmds(`User Test`, map[string]interface{}{"group": augID})
5925+
b.ExecAutocmds(`User`, map[string]interface{}{"group": augID})
59375926
if err := b.Execute(); err != nil {
59385927
t.Fatal(err)
59395928
}

nvim/nvim_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func newChildProcess(tb testing.TB, opts ...ChildProcessOption) (v *Nvim) {
3131
"-n",
3232
"-i", "NONE",
3333
"--headless",
34+
"--embed",
3435
),
3536
ChildProcessContext(ctx),
3637
ChildProcessLogf(tb.Logf),

0 commit comments

Comments
 (0)