Skip to content
Myr

Add unit test for fish completion (#1515)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by kida · committed by GitHub · parent f464d6c · Browse files · 1 file+56 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+56 added−0 removed

  • other:+56 added−0 removed

1 file+56 added−0 removed

modified:fish_completions_test.go+56 added
1 unmodified line
23import (4 "bytes"5 "fmt"6 "log"7 "os"8 "testing"9)1011func TestCompleteNoDesCmdInFishScript(t *testing.T) {
69 unmodified lines
81 // check that active help is being disabled82 activeHelpVar := activeHelpEnvVar(c.Name())83 check(t, output, fmt.Sprintf("%s=0", activeHelpVar))84}8586func TestGenFishCompletionFile(t *testing.T) {87 err := os.Mkdir("./tmp", 0755)88 if err != nil {89 log.Fatal(err.Error())90 }9192 defer os.RemoveAll("./tmp")9394 rootCmd := &Command{Use: "root", Args: NoArgs, Run: emptyRun}95 child := &Command{96 Use: "child",97 ValidArgsFunction: validArgsFunc,98 Run: emptyRun,99 }100 rootCmd.AddCommand(child)101102 assertNoErr(t, rootCmd.GenFishCompletionFile("./tmp/test", false))103}104105func TestFailGenFishCompletionFile(t *testing.T) {106 err := os.Mkdir("./tmp", 0755)107 if err != nil {108 log.Fatal(err.Error())109 }110111 defer os.RemoveAll("./tmp")112113 f, _ := os.OpenFile("./tmp/test", os.O_CREATE, 0400)114 defer f.Close()115116 rootCmd := &Command{Use: "root", Args: NoArgs, Run: emptyRun}117 child := &Command{118 Use: "child",119 ValidArgsFunction: validArgsFunc,120 Run: emptyRun,121 }122 rootCmd.AddCommand(child)123124 got := rootCmd.GenFishCompletionFile("./tmp/test", false)125 if got == nil {126 t.Error("should raise permission denied error")127 }128129 if os.Getenv("MSYSTEM") == "MINGW64" {130 if got.Error() != "open ./tmp/test: Access is denied." {131 t.Errorf("got: %s, want: %s", got.Error(), "open ./tmp/test: Access is denied.")132 }133 } else {134 if got.Error() != "open ./tmp/test: permission denied" {135 t.Errorf("got: %s, want: %s", got.Error(), "open ./tmp/test: permission denied")136 }137 }138}