@@ -2,6 +2,7 @@ package trellis
22
33import (
44 "bytes"
5+ "flag"
56 "io"
67 "os"
78 "reflect"
@@ -29,24 +30,43 @@ func TestCompletionFunctions(t *testing.T) {
2930 t .Fatalf (err .Error ())
3031 }
3132
33+ flags := flag .NewFlagSet ("" , flag .ContinueOnError )
34+ flags .SetOutput (io .Discard )
35+
36+ flagsPredictor := complete.Flags {
37+ "--branch" : complete .PredictNothing ,
38+ }
39+
3240 cases := []struct {
3341 Predictor complete.Predictor
3442 Completed []string
3543 Last string
3644 Expected []string
3745 }{
38- {trellis .AutocompleteEnvironment (), []string {"deploy" }, "" , []string {"development" , "valet-link" , "production" }},
39- {trellis .AutocompleteEnvironment (), []string {"deploy" }, "d" , []string {"development" }},
40- {trellis .AutocompleteEnvironment (), []string {"deploy" , "production" }, "" , nil },
41- {trellis .AutocompleteSite (), []string {"deploy" }, "" , []string {"development" , "valet-link" , "production" }},
42- {trellis .AutocompleteSite (), []string {"deploy" }, "d" , []string {"development" }},
43- {trellis .AutocompleteSite (), []string {"deploy" , "production" }, "" , []string {"example.com" }},
46+ {trellis .AutocompleteEnvironment (flags ), []string {"deploy" }, "" , []string {"development" , "valet-link" , "production" }},
47+ {trellis .AutocompleteEnvironment (flags ), []string {"deploy" }, "d" , []string {"development" }},
48+ {trellis .AutocompleteEnvironment (flags ), []string {"deploy" , "production" }, "" , nil },
49+ {trellis .AutocompleteEnvironment (flags ), []string {"deploy" }, "--b" , []string {"--branch" }},
50+ {trellis .AutocompleteEnvironment (flags ), []string {"deploy" , "--branch=foo" }, "" , []string {"development" , "valet-link" , "production" }},
51+ {trellis .AutocompleteEnvironment (flags ), []string {"deploy" , "--branch=foo" }, "pro" , []string {"production" }},
52+ {trellis .AutocompleteSite (flags ), []string {"deploy" }, "" , []string {"development" , "valet-link" , "production" }},
53+ {trellis .AutocompleteSite (flags ), []string {"deploy" }, "d" , []string {"development" }},
54+ {trellis .AutocompleteSite (flags ), []string {"deploy" , "production" }, "" , []string {"example.com" }},
55+ {trellis .AutocompleteSite (flags ), []string {"deploy" , "--branch=foo" }, "dev" , []string {"development" }},
56+ {trellis .AutocompleteSite (flags ), []string {"deploy" , "--branch=foo" , "production" }, "" , []string {"example.com" }},
57+ {trellis .AutocompleteSite (flags ), []string {"deploy" , "--branch=foo" , "production" }, "example" , []string {"example.com" }},
4458 }
4559
4660 for _ , tc := range cases {
4761 t .Run (tc .Last , func (t * testing.T ) {
62+ var flagValue string
63+
64+ flags = flag .NewFlagSet ("" , flag .ContinueOnError )
65+ flags .StringVar (& flagValue , "branch" , "" , "Branch name" )
66+
4867 command := new (cli.MockCommandAutocomplete )
4968 command .AutocompleteArgsValue = tc .Predictor
69+ command .AutocompleteFlagsValue = flagsPredictor
5070
5171 cli := & cli.CLI {
5272 Commands : map [string ]cli.CommandFactory {
@@ -104,7 +124,7 @@ func TestCompletionFunctions(t *testing.T) {
104124 sort .Strings (tc .Expected )
105125
106126 if ! reflect .DeepEqual (actual , tc .Expected ) {
107- t .Fatalf ("bad: \n \n %#v\n \n %#v" , actual , tc .Expected )
127+ t .Fatalf ("\n \n Expected: \ n %#v\n \n Actual: \ n %#v" , tc .Expected , actual )
108128 }
109129 })
110130 }
0 commit comments