| 182 | } |
| 183 | |
| 184 | func TestStringVar(t *testing.T) { |
| 185 | var result string |
| 186 | StringVar(&result, "nonexistent", "default") |
| 187 | Parse() |
| 188 | |
| 189 | if result != "default" { |
| 190 | t.Fatalf("expected result=default, got result=%s", result) |
| 191 | } |
| 192 | |
| 193 | err := os.Setenv("string-key", "something-new") |
| 194 | if err != nil { |
| 195 | t.Fatal("unexpected error", err) |
| 196 | } |
| 197 | |
| 198 | StringVar(&result, "string-key", "default") |
| 199 | Parse() |
| 200 | |
| 201 | if result != "something-new" { |
| 202 | t.Fatalf("expected result=something-new, got result=%s", result) |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | func TestStringSlice(t *testing.T) { |
| 207 | result := StringSlice("empty", "hi") |