(t *testing.T)
| 99 | } |
| 100 | |
| 101 | func TestBoolFlagCountFromCommand(t *testing.T) { |
| 102 | boolCountTests := []struct { |
| 103 | name string |
| 104 | input []string |
| 105 | expectedVal bool |
| 106 | expectedCount int |
| 107 | }{ |
| 108 | { |
| 109 | name: "3 count", |
| 110 | input: []string{"main", "-tf", "-w", "-huh"}, |
| 111 | expectedVal: true, |
| 112 | expectedCount: 3, |
| 113 | }, |
| 114 | { |
| 115 | name: "single count", |
| 116 | input: []string{"main", "-huh"}, |
| 117 | expectedVal: true, |
| 118 | expectedCount: 1, |
| 119 | }, |
| 120 | { |
| 121 | name: "zero count", |
| 122 | input: []string{"main"}, |
| 123 | expectedVal: false, |
| 124 | expectedCount: 0, |
| 125 | }, |
| 126 | } |
| 127 | |
| 128 | flags := func() []Flag { |
| 129 | return []Flag{ |
| 130 | &BoolFlag{Name: "tf", Aliases: []string{"w", "huh"}}, |
| 131 | &BoolWithInverseFlag{Name: "tf", Aliases: []string{"w", "huh"}}, |
| 132 | } |
| 133 | } |
| 134 | for index := range flags() { |
| 135 | for _, bct := range boolCountTests { |
| 136 | t.Run(bct.name, func(t *testing.T) { |
| 137 | bf := flags()[index] |
| 138 | cmd := &Command{ |
| 139 | Flags: []Flag{ |
| 140 | bf, |
| 141 | }, |
| 142 | } |
| 143 | r := require.New(t) |
| 144 | |
| 145 | r.NoError(cmd.Run(buildTestContext(t), bct.input)) |
| 146 | |
| 147 | for _, alias := range bf.Names() { |
| 148 | r.Equal(bct.expectedCount, cmd.Count(alias)) |
| 149 | r.Equal(bct.expectedVal, cmd.Value(alias)) |
| 150 | } |
| 151 | }) |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | func TestFlagsFromEnv(t *testing.T) { |
| 157 | testCases := []struct { |
nothing calls this directly
no test coverage detected