JMS #4: Getting some cli tests going. Testing out flags
parent
04496e4364
commit
3f76896c4f
@ -0,0 +1,30 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_SimpleCLIFlags(t *testing.T) {
|
||||
Flags = []Flag{
|
||||
StringFlag{"foo", "default", "a foo flag"},
|
||||
}
|
||||
Action = func(c *Context) {
|
||||
expect(t, c.String("foo"), "hello world")
|
||||
}
|
||||
Run([]string{ "command", "--foo", "hello world" })
|
||||
}
|
||||
|
||||
/* Helpers */
|
||||
|
||||
func expect(t *testing.T, a interface{}, b interface{}) {
|
||||
if a != b {
|
||||
t.Errorf("Expected %v (type %v) - Got %v (type %v)", b, reflect.TypeOf(b), a, reflect.TypeOf(a))
|
||||
}
|
||||
}
|
||||
|
||||
func refute(t *testing.T, a interface{}, b interface{}) {
|
||||
if a == b {
|
||||
t.Errorf("Did not expect %v (type %v) - Got %v (type %v)", b, reflect.TypeOf(b), a, reflect.TypeOf(a))
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package cli
|
||||
|
||||
type Command struct {
|
||||
Name string
|
||||
ShortName string
|
||||
Usage string
|
||||
Description string
|
||||
Action Handler
|
||||
Flags []Flag
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_True(t *testing.T) {
|
||||
expect(t, true, true)
|
||||
}
|
||||
|
||||
func Test_Run(t *testing.T) {
|
||||
}
|
Loading…
Reference in new issue