55 "testing"
66)
77
8- func TestUsage (t * testing.T ) {
8+ func TestUsagePlain (t * testing.T ) {
99 env , err := makeDefaultEnv (t )
1010 if err != nil {
1111 t .Fatalf ("%v" , err .Error ())
@@ -23,13 +23,31 @@ func TestUsage(t *testing.T) {
2323 }
2424}
2525
26- func TestUsageWithCommand (t * testing.T ) {
26+ func TestUsageHelp (t * testing.T ) {
2727 env , err := makeDefaultEnv (t )
2828 if err != nil {
2929 t .Fatalf ("%v" , err .Error ())
3030 }
3131
32- c , out , err := cliCommand (env , "help" ) // or any other unknown command
32+ c , out , err := cliCommand (env , "help" )
33+ if err != nil {
34+ t .Fatalf ("failed to run CLI command: %v" , err )
35+ }
36+ if c != 0 {
37+ t .Fatalf ("exit code %d: %v" , c , err )
38+ }
39+ if ! strings .Contains (out , "Usage:" ) {
40+ t .Errorf ("output did not contain usage information: %s" , out )
41+ }
42+ }
43+
44+ func TestUsageUnknownCommand (t * testing.T ) {
45+ env , err := makeDefaultEnv (t )
46+ if err != nil {
47+ t .Fatalf ("%v" , err .Error ())
48+ }
49+
50+ c , out , err := cliCommand (env , "foo" ) // or any other unknown command
3351 if err != nil {
3452 t .Fatalf ("failed to run CLI command: %v" , err )
3553 }
@@ -39,7 +57,8 @@ func TestUsageWithCommand(t *testing.T) {
3957 if ! strings .Contains (out , "Usage:" ) {
4058 t .Errorf ("output did not contain usage information: %s" , out )
4159 }
42- if ! strings .Contains (out , "Unknown command: help " ) {
60+ if ! strings .Contains (out , "Unknown command: foo " ) {
4361 t .Errorf ("output did not contain unknown command warning: %s" , out )
4462 }
4563}
64+
0 commit comments