github.com/tcnksm/gcli@v0.2.4-0.20170129033839-7eb950507e5a/skeleton/resource/tmpl/flag/cli_test.go.tmpl (about) 1 package main 2 3 import ( 4 "bytes" 5 "fmt" 6 "strings" 7 "testing" 8 ) 9 10 func TestRun_versionFlag(t *testing.T) { 11 outStream, errStream := new(bytes.Buffer), new(bytes.Buffer) 12 cli := &CLI{outStream: outStream, errStream: errStream} 13 args := strings.Split("./{{ .Name }} -version", " ") 14 15 status := cli.Run(args) 16 if status != ExitCodeOK { 17 t.Errorf("expected %d to eq %d", status, ExitCodeOK) 18 } 19 20 expected := fmt.Sprintf("{{ .Name }} version %s", Version) 21 if !strings.Contains(errStream.String(), expected) { 22 t.Errorf("expected %q to eq %q", errStream.String(), expected) 23 } 24 } 25 26 {{ range .Flags }} 27 func TestRun_{{ .VariableName }}Flag(t *testing.T) { 28 outStream, errStream := new(bytes.Buffer), new(bytes.Buffer) 29 cli := &CLI{outStream: outStream, errStream: errStream} 30 args := strings.Split("./{{ $.Name }} -{{ .LongName }}", " ") 31 32 status := cli.Run(args) 33 _ = status 34 } 35 {{ end }}