Skip to content

Commit 271990f

Browse files
committed
test: cover empty bool source validation in TestFlagsFromEmptyEnv
Only the empty env and empty file cases of TestBoolFlagEmptySourceRunsValidator fail without the fix. The other ten already pass on main, and a file source goes through the same PostParse loop as an env var. Replace the file with one case in TestFlagsFromEmptyEnv, next to the existing "an empty bool still reads as false" case. Assisted-by: claude:claude-opus-5-5 Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
1 parent 9f82248 commit 271990f

2 files changed

Lines changed: 11 additions & 95 deletions

File tree

‎flag_empty_bool_validator_test.go‎

Lines changed: 0 additions & 95 deletions
This file was deleted.

‎flag_test.go‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,17 @@ func TestFlagsFromEmptyEnv(t *testing.T) {
734734
wantValue: false,
735735
wantIsSet: true,
736736
},
737+
{
738+
name: "an empty bool still runs the validator",
739+
env: map[string]string{"DEBUG": ""},
740+
fl: &BoolFlag{Name: "debug", Value: true, Sources: EnvVars("DEBUG"), Validator: func(b bool) error {
741+
if !b {
742+
return errors.New("debug must be true")
743+
}
744+
return nil
745+
}},
746+
errContains: "debug must be true",
747+
},
737748
}
738749

739750
for _, tc := range testCases {

0 commit comments

Comments
 (0)