(t *testing.T)
| 2175 | } |
| 2176 | |
| 2177 | func TestCommandPrintRedirection(t *testing.T) { |
| 2178 | errBuff, outBuff := bytes.NewBuffer(nil), bytes.NewBuffer(nil) |
| 2179 | root := &Command{ |
| 2180 | Run: func(cmd *Command, args []string) { |
| 2181 | |
| 2182 | cmd.PrintErr("PrintErr") |
| 2183 | cmd.PrintErrln("PrintErr", "line") |
| 2184 | cmd.PrintErrf("PrintEr%s", "r") |
| 2185 | |
| 2186 | cmd.Print("Print") |
| 2187 | cmd.Println("Print", "line") |
| 2188 | cmd.Printf("Prin%s", "t") |
| 2189 | }, |
| 2190 | } |
| 2191 | |
| 2192 | root.SetErr(errBuff) |
| 2193 | root.SetOut(outBuff) |
| 2194 | |
| 2195 | if err := root.Execute(); err != nil { |
| 2196 | t.Error(err) |
| 2197 | } |
| 2198 | |
| 2199 | gotErrBytes, err := io.ReadAll(errBuff) |
| 2200 | if err != nil { |
| 2201 | t.Error(err) |
| 2202 | } |
| 2203 | |
| 2204 | gotOutBytes, err := io.ReadAll(outBuff) |
| 2205 | if err != nil { |
| 2206 | t.Error(err) |
| 2207 | } |
| 2208 | |
| 2209 | if wantErr := []byte("PrintErrPrintErr line\nPrintErr"); !bytes.Equal(gotErrBytes, wantErr) { |
| 2210 | t.Errorf("got: '%s' want: '%s'", gotErrBytes, wantErr) |
| 2211 | } |
| 2212 | |
| 2213 | if wantOut := []byte("PrintPrint line\nPrint"); !bytes.Equal(gotOutBytes, wantOut) { |
| 2214 | t.Errorf("got: '%s' want: '%s'", gotOutBytes, wantOut) |
| 2215 | } |
| 2216 | } |
| 2217 | |
| 2218 | func TestFlagErrorFunc(t *testing.T) { |
| 2219 | c := &Command{Use: "c", Run: emptyRun} |
nothing calls this directly
no test coverage detected
searching dependent graphs…