2014-07-13 05:21:46 +02:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMetaColorize(t *testing.T) {
|
|
|
|
var m *Meta
|
|
|
|
var args, args2 []string
|
|
|
|
|
2014-07-17 18:34:32 +02:00
|
|
|
// Test basic, color
|
2014-07-13 05:21:46 +02:00
|
|
|
m = new(Meta)
|
2014-07-17 18:34:32 +02:00
|
|
|
m.Color = true
|
2014-07-13 05:21:46 +02:00
|
|
|
args = []string{"foo", "bar"}
|
|
|
|
args2 = []string{"foo", "bar"}
|
2014-08-05 18:32:01 +02:00
|
|
|
args = m.process(args, false)
|
2014-07-13 05:21:46 +02:00
|
|
|
if !reflect.DeepEqual(args, args2) {
|
|
|
|
t.Fatalf("bad: %#v", args)
|
|
|
|
}
|
|
|
|
if m.Colorize().Disable {
|
|
|
|
t.Fatal("should not be disabled")
|
|
|
|
}
|
|
|
|
|
2014-07-17 18:34:32 +02:00
|
|
|
// Test basic, no change
|
|
|
|
m = new(Meta)
|
|
|
|
args = []string{"foo", "bar"}
|
|
|
|
args2 = []string{"foo", "bar"}
|
2014-08-05 18:32:01 +02:00
|
|
|
args = m.process(args, false)
|
2014-07-17 18:34:32 +02:00
|
|
|
if !reflect.DeepEqual(args, args2) {
|
|
|
|
t.Fatalf("bad: %#v", args)
|
|
|
|
}
|
|
|
|
if !m.Colorize().Disable {
|
|
|
|
t.Fatal("should be disabled")
|
|
|
|
}
|
|
|
|
|
2014-07-13 05:21:46 +02:00
|
|
|
// Test disable #1
|
|
|
|
m = new(Meta)
|
2014-09-09 05:41:10 +02:00
|
|
|
m.Color = true
|
2014-07-13 05:21:46 +02:00
|
|
|
args = []string{"foo", "-no-color", "bar"}
|
|
|
|
args2 = []string{"foo", "bar"}
|
2014-08-05 18:32:01 +02:00
|
|
|
args = m.process(args, false)
|
2014-07-13 05:21:46 +02:00
|
|
|
if !reflect.DeepEqual(args, args2) {
|
|
|
|
t.Fatalf("bad: %#v", args)
|
|
|
|
}
|
|
|
|
if !m.Colorize().Disable {
|
|
|
|
t.Fatal("should be disabled")
|
|
|
|
}
|
|
|
|
}
|
2014-09-29 20:11:35 +02:00
|
|
|
|
|
|
|
func TestMetaInput(t *testing.T) {
|
|
|
|
m := new(Meta)
|
|
|
|
args := []string{}
|
|
|
|
|
|
|
|
fs := m.flagSet("foo")
|
|
|
|
if err := fs.Parse(args); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !m.Input() {
|
|
|
|
t.Fatal("should input")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMetaInput_disable(t *testing.T) {
|
|
|
|
m := new(Meta)
|
|
|
|
args := []string{"-input=false"}
|
|
|
|
|
|
|
|
fs := m.flagSet("foo")
|
|
|
|
if err := fs.Parse(args); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if m.Input() {
|
|
|
|
t.Fatal("should not input")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMetaInput_vars(t *testing.T) {
|
|
|
|
m := new(Meta)
|
|
|
|
args := []string{"-var", "foo=bar"}
|
|
|
|
|
|
|
|
fs := m.flagSet("foo")
|
|
|
|
if err := fs.Parse(args); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if m.Input() {
|
|
|
|
t.Fatal("should not input")
|
|
|
|
}
|
|
|
|
}
|