Files
commandkit/internal/commandmeta/metadata_test.go

36 lines
1.2 KiB
Go
Raw Normal View History

2026-10-26 02:50:54 +00:00
package commandmeta
import "testing"
func TestReportingFlagsAreBooleanAndReturnedIndependently(t *testing.T) {
flags := ReportingFlags()
want := []string{"quiet", "verbose", "debug", "progress"}
2026-11-07 03:45:12 +00:00
if len(flags) != len(want)+1 {
2026-10-26 02:50:54 +00:00
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)
}
}
2026-11-07 03:45:12 +00:00
if flags[4].Name != "format" || flags[4].Boolean || !IsReportingFlag("format") {
t.Fatalf("format metadata = %#v", flags[4])
}
flags[4].Completion.Choices[0].Value = "changed"
if ReportingFlags()[4].Completion.Choices[0].Value != "text" {
t.Fatal("caller mutation changed format choices")
}
2026-10-26 02:50:54 +00:00
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)
}
}
}