diff options
| author | Grégoire Duchêne <gduchene@awhk.org> | 2022-12-03 12:19:17 +0000 |
|---|---|---|
| committer | Grégoire Duchêne <gduchene@awhk.org> | 2022-12-03 12:19:17 +0000 |
| commit | 6f81c7e746a3c7917f9d0efc1a6b34d905135866 (patch) | |
| tree | b49e97a4031736f7959cbb854b5eca60cca948eb /flag_test.go | |
| parent | a3ef784a3b5af5dd98ab8d9a44404f2ef240a626 (diff) | |
Prevent flags from being set again by defaultv0.3.0
Flag values that are safe to be set again should implement the new
MutableFlagValue interface.
Diffstat (limited to 'flag_test.go')
| -rw-r--r-- | flag_test.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/flag_test.go b/flag_test.go index 26568d6..1f36b63 100644 --- a/flag_test.go +++ b/flag_test.go @@ -110,4 +110,13 @@ func TestInitFlagSet(s *testing.T) { t.AssertEqual(tc.expStr, *fm) }) } + + t.Run("NoMutableFlagValue", func(t *core.T) { + fs := flag.NewFlagSet("", flag.PanicOnError) + fi := fs.Int("int", 0, "") + t.AssertErrorIs(nil, core.InitFlagSet(fs, nil, nil, []string{"-int=42"})) + t.AssertEqual(42, *fi) + t.AssertErrorIs(nil, core.InitFlagSet(fs, nil, nil, []string{"-int=21"})) + t.AssertEqual(42, *fi) + }) } |
