|
|
|
|
@ -1,6 +1,9 @@
|
|
|
|
|
package command
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"io/ioutil"
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"reflect"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
@ -48,7 +51,7 @@ func TestMetaColorize(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestMetaInput(t *testing.T) {
|
|
|
|
|
func TestMetaInputEnabled(t *testing.T) {
|
|
|
|
|
test = false
|
|
|
|
|
defer func() { test = true }()
|
|
|
|
|
|
|
|
|
|
@ -60,7 +63,7 @@ func TestMetaInput(t *testing.T) {
|
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !m.Input() {
|
|
|
|
|
if !m.InputEnabled() {
|
|
|
|
|
t.Fatal("should input")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -77,11 +80,51 @@ func TestMetaInput_disable(t *testing.T) {
|
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if m.Input() {
|
|
|
|
|
if m.InputEnabled() {
|
|
|
|
|
t.Fatal("should not input")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestMetaInput_defaultVars(t *testing.T) {
|
|
|
|
|
test = false
|
|
|
|
|
defer func() { test = true }()
|
|
|
|
|
|
|
|
|
|
// Create a temporary directory for our cwd
|
|
|
|
|
d := tempDir(t)
|
|
|
|
|
if err := os.MkdirAll(d, 0755); err != nil {
|
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
}
|
|
|
|
|
cwd, err := os.Getwd()
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
}
|
|
|
|
|
if err := os.Chdir(d); err != nil {
|
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
}
|
|
|
|
|
defer os.Chdir(cwd)
|
|
|
|
|
|
|
|
|
|
// Create the default vars file
|
|
|
|
|
err = ioutil.WriteFile(
|
|
|
|
|
filepath.Join(d, DefaultVarsFilename),
|
|
|
|
|
[]byte(""),
|
|
|
|
|
0644)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m := new(Meta)
|
|
|
|
|
args := []string{}
|
|
|
|
|
args = m.process(args, true)
|
|
|
|
|
|
|
|
|
|
fs := m.flagSet("foo")
|
|
|
|
|
if err := fs.Parse(args); err != nil {
|
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if m.InputEnabled() {
|
|
|
|
|
t.Fatal("should not input")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
func TestMetaInput_vars(t *testing.T) {
|
|
|
|
|
test = false
|
|
|
|
|
defer func() { test = true }()
|
|
|
|
|
@ -94,7 +137,7 @@ func TestMetaInput_vars(t *testing.T) {
|
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if m.Input() {
|
|
|
|
|
if m.InputEnabled() {
|
|
|
|
|
t.Fatal("should not input")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|