(t *testing.T)
| 140 | } |
| 141 | |
| 142 | func TestAnnotation(t *testing.T) { |
| 143 | f := NewFlagSet("shorthand", ContinueOnError) |
| 144 | |
| 145 | err := f.SetAnnotation("missing-flag", "key", nil) |
| 146 | expectedErr := "no such flag -missing-flag" |
| 147 | if err == nil { |
| 148 | t.Errorf("Expected error setting annotation on non-existent flag") |
| 149 | } |
| 150 | if err.Error() != expectedErr { |
| 151 | t.Errorf("expected error %q, got %q", expectedErr, err.Error()) |
| 152 | } |
| 153 | |
| 154 | f.StringP("stringa", "a", "", "string value") |
| 155 | if err := f.SetAnnotation("stringa", "key", nil); err != nil { |
| 156 | t.Errorf("Unexpected error setting new nil annotation: %v", err) |
| 157 | } |
| 158 | if annotation := f.Lookup("stringa").Annotations["key"]; annotation != nil { |
| 159 | t.Errorf("Unexpected annotation: %v", annotation) |
| 160 | } |
| 161 | |
| 162 | f.StringP("stringb", "b", "", "string2 value") |
| 163 | if err := f.SetAnnotation("stringb", "key", []string{"value1"}); err != nil { |
| 164 | t.Errorf("Unexpected error setting new annotation: %v", err) |
| 165 | } |
| 166 | if annotation := f.Lookup("stringb").Annotations["key"]; !reflect.DeepEqual(annotation, []string{"value1"}) { |
| 167 | t.Errorf("Unexpected annotation: %v", annotation) |
| 168 | } |
| 169 | |
| 170 | if err := f.SetAnnotation("stringb", "key", []string{"value2"}); err != nil { |
| 171 | t.Errorf("Unexpected error updating annotation: %v", err) |
| 172 | } |
| 173 | if annotation := f.Lookup("stringb").Annotations["key"]; !reflect.DeepEqual(annotation, []string{"value2"}) { |
| 174 | t.Errorf("Unexpected annotation: %v", annotation) |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | func TestName(t *testing.T) { |
| 179 | flagSetName := "bob" |
nothing calls this directly
no test coverage detected