| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- package main
- import (
- "strings"
- "testing"
- )
- // The --device flag accepts the 1-based number that `keyboard info` prints.
- // Its help text is the only place a user learns that, so it must not
- // describe the HID path the flag rejects.
- func TestDeviceFlagUsageDescribesANumberNotAPath(t *testing.T) {
- flag := newRootCommand().PersistentFlags().Lookup("device")
- if flag == nil {
- t.Fatal("--device flag not found")
- }
- if strings.Contains(flag.Usage, "path") {
- t.Errorf("--device usage = %q, must not mention a path; the flag rejects HID paths", flag.Usage)
- }
- if !strings.Contains(flag.Usage, "number") {
- t.Errorf("--device usage = %q, want it to say the argument is a number", flag.Usage)
- }
- }
- // Cobra reads a back-quoted word in a flag's usage as the value placeholder
- // and renders it where the type name would go, turning `--device into
- // `--device keyboard info`. The help must therefore contain no backticks.
- func TestFlagUsageHasNoValuePlaceholder(t *testing.T) {
- for _, name := range []string{"device", "zone"} {
- flag := newRootCommand().PersistentFlags().Lookup(name)
- if flag == nil {
- t.Fatalf("--%s flag not found", name)
- }
- if strings.Contains(flag.Usage, "`") {
- t.Errorf("--%s usage = %q, backticks make cobra render a bogus value placeholder", name, flag.Usage)
- }
- }
- }
- func TestZoneFlagUsageListsEveryZone(t *testing.T) {
- flag := newRootCommand().PersistentFlags().Lookup("zone")
- if flag == nil {
- t.Fatal("--zone flag not found")
- }
- for _, zone := range []string{"logo", "backlight", "side"} {
- if !strings.Contains(flag.Usage, zone) {
- t.Errorf("--zone usage = %q, want it to list %q", flag.Usage, zone)
- }
- }
- }
|