Skip to content

Commit

Permalink
Improve API tests #170
Browse files Browse the repository at this point in the history
- Get expected runtime paths by evaluating a VimL expression.
- Use equality operator to compare strings instead of reflect.DeepEqual.
- Fix typo in event name.
  • Loading branch information
garyburd authored May 13, 2024
1 parent 2be2dfb commit 9b44fee
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
23 changes: 6 additions & 17 deletions nvim/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"
"log"
"os"
"os/exec"
"path"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -4459,20 +4458,10 @@ func testRuntime(v *Nvim) func(*testing.T) {
vimDiff := filepath.Join(runtimePath, "doc", "vim_diff.txt")
want := fmt.Sprintf("%s,%s", viDiff, vimDiff)

binName := BinaryName
if nvimCmd := *flagNvimPath; nvimCmd != "" {
binName = nvimCmd
}
binaryPath, err := exec.LookPath(binName)
if err != nil {
var wantPaths []string
if err := v.Eval("nvim_list_runtime_paths()", &wantPaths); err != nil {
t.Fatal(err)
}
nvimPrefix := filepath.Dir(filepath.Dir(binaryPath))

wantPaths := []string{
filepath.Join(nvimPrefix, "lib", "nvim"),
filepath.Join(nvimPrefix, "share", "nvim", "runtime"),
}
sort.Strings(wantPaths)

argName := filepath.Join("doc", "*_diff.txt")
Expand Down Expand Up @@ -4504,7 +4493,7 @@ func testRuntime(v *Nvim) func(*testing.T) {
got := strings.Join(paths, ",")
want := strings.Join(wantPaths, ",")
t.Logf("%s\n got: %v\nwant: %s", t.Name(), got, want)
if !reflect.DeepEqual(got, want) {
if got != want {
t.Fatalf("RuntimePaths():\n got %v\nwant %v", got, want)
}
})
Expand Down Expand Up @@ -4541,7 +4530,7 @@ func testRuntime(v *Nvim) func(*testing.T) {

got := strings.Join(paths, ",")
want := strings.Join(wantPaths, ",")
if !reflect.DeepEqual(got, want) {
if got != want {
t.Fatalf("RuntimePaths():\n got %v\nwant %v", paths, wantPaths)
}
})
Expand Down Expand Up @@ -5824,7 +5813,7 @@ func testAutocmd(v *Nvim) func(*testing.T) {
t.Fatal(err)
}

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

Expand Down Expand Up @@ -5933,7 +5922,7 @@ func testAutocmd(v *Nvim) func(*testing.T) {
t.Fatal(err)
}

b.ExecAutocmds(`User Test`, map[string]interface{}{"group": augID})
b.ExecAutocmds(`User`, map[string]interface{}{"group": augID})
if err := b.Execute(); err != nil {
t.Fatal(err)
}
Expand Down
1 change: 1 addition & 0 deletions nvim/nvim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func newChildProcess(tb testing.TB, opts ...ChildProcessOption) (v *Nvim) {
"-n",
"-i", "NONE",
"--headless",
"--embed",
),
ChildProcessContext(ctx),
ChildProcessLogf(tb.Logf),
Expand Down

0 comments on commit 9b44fee

Please sign in to comment.