29 lines
892 B
Go
29 lines
892 B
Go
package commandmeta
|
|
|
|
import "testing"
|
|
|
|
func TestReportingFlagsAreBooleanAndReturnedIndependently(t *testing.T) {
|
|
flags := ReportingFlags()
|
|
want := []string{"quiet", "verbose", "debug", "progress"}
|
|
if len(flags) != len(want) {
|
|
t.Fatalf("reporting flags = %#v", flags)
|
|
}
|
|
for index, name := range want {
|
|
if flags[index].Name != name || !flags[index].Boolean || flags[index].Short != "" || flags[index].Default != "false" {
|
|
t.Errorf("reporting flag %d = %#v", index, flags[index])
|
|
}
|
|
if !IsReportingFlag(name) {
|
|
t.Errorf("%q is not recognized as a reporting flag", name)
|
|
}
|
|
}
|
|
flags[0].Name = "changed"
|
|
if ReportingFlags()[0].Name != "quiet" {
|
|
t.Fatal("caller mutation changed shared reporting metadata")
|
|
}
|
|
for _, name := range []string{"help", "quietly", ""} {
|
|
if IsReportingFlag(name) {
|
|
t.Errorf("%q was incorrectly recognized as a reporting flag", name)
|
|
}
|
|
}
|
|
}
|