github.com/urfave/cli@v1.22.14/fish_test.go (about) 1 package cli 2 3 import ( 4 "os" 5 "strings" 6 "testing" 7 8 "github.com/stretchr/testify/require" 9 ) 10 11 func testApp() *App { 12 app := NewApp() 13 app.Name = "greet" 14 app.Flags = []Flag{ 15 StringFlag{ 16 Name: "socket, s", 17 Usage: "some 'usage' text", 18 Value: "value", 19 TakesFile: true, 20 }, 21 StringFlag{Name: "flag, fl, f"}, 22 BoolFlag{ 23 Name: "another-flag, b", 24 Usage: "another usage text", 25 }, 26 } 27 app.Commands = []Command{{ 28 Aliases: []string{"c"}, 29 Flags: []Flag{ 30 StringFlag{ 31 Name: "flag, fl, f", 32 TakesFile: true, 33 }, 34 BoolFlag{ 35 Name: "another-flag, b", 36 Usage: "another usage text", 37 }, 38 }, 39 Name: "config", 40 Usage: "another usage test", 41 Subcommands: []Command{{ 42 Aliases: []string{"s", "ss"}, 43 Flags: []Flag{ 44 StringFlag{Name: "sub-flag, sub-fl, s"}, 45 BoolFlag{ 46 Name: "sub-command-flag, s", 47 Usage: "some usage text", 48 }, 49 }, 50 Name: "sub-config", 51 Usage: "another usage test", 52 }}, 53 }, { 54 Aliases: []string{"i", "in"}, 55 Name: "info", 56 Usage: "retrieve generic information", 57 }, { 58 Name: "some-command", 59 }, { 60 Name: "hidden-command", 61 Hidden: true, 62 }} 63 app.UsageText = "app [first_arg] [second_arg]" 64 app.Usage = "Some app" 65 app.Author = "Harrison" 66 app.Email = "harrison@lolwut.com" 67 app.Authors = []Author{{Name: "Oliver Allen", Email: "oliver@toyshop.com"}} 68 return app 69 } 70 71 func expectFileContent(t *testing.T, file, expected string) { 72 data, err := os.ReadFile(file) 73 require.Nil(t, err) 74 75 require.Equal(t, strings.ReplaceAll(string(data), "\r\n", "\n"), expected) 76 } 77 78 func TestFishCompletion(t *testing.T) { 79 // Given 80 app := testApp() 81 82 // When 83 res, err := app.ToFishCompletion() 84 85 // Then 86 expect(t, err, nil) 87 expectFileContent(t, "testdata/expected-fish-full.fish", res) 88 }