(t *testing.T)
| 232 | } |
| 233 | |
| 234 | func TestSpinnerPrinter_OutputToWriters(t *testing.T) { |
| 235 | testCases := map[string]struct { |
| 236 | action func(*pterm.SpinnerPrinter) |
| 237 | expectOutputToContain string |
| 238 | }{ |
| 239 | "ExpectWarningMessageToBeWrittenToStderr": { |
| 240 | action: func(sp *pterm.SpinnerPrinter) { sp.Warning("A warning") }, |
| 241 | expectOutputToContain: "A warning", |
| 242 | }, |
| 243 | "ExpectFailMessageToBeWrittenToStderr": { |
| 244 | action: func(sp *pterm.SpinnerPrinter) { sp.Fail("An error") }, |
| 245 | expectOutputToContain: "An error", |
| 246 | }, |
| 247 | "ExpectUpdatedTextToBeWrittenToStderr": { |
| 248 | action: func(sp *pterm.SpinnerPrinter) { |
| 249 | sp.UpdateText("Updated text") |
| 250 | }, |
| 251 | expectOutputToContain: "Updated text", |
| 252 | }, |
| 253 | } |
| 254 | |
| 255 | for testTitle, testCase := range testCases { |
| 256 | t.Run(testTitle, func(t *testing.T) { |
| 257 | stderr, err := testza.CaptureStderr(func(w io.Writer) error { |
| 258 | sp, err := pterm.DefaultSpinner.WithText("Hello world").WithWriter(os.Stderr).Start() |
| 259 | time.Sleep(time.Second) // Required otherwise the goroutine doesn't run and the text isn't outputted |
| 260 | testza.AssertNoError(t, err) |
| 261 | testCase.action(sp) |
| 262 | time.Sleep(time.Second) // Required otherwise the goroutine doesn't run and the text isn't updated |
| 263 | return nil |
| 264 | }) |
| 265 | |
| 266 | testza.AssertNoError(t, err) |
| 267 | testza.AssertContains(t, stderr, "Hello world") |
| 268 | testza.AssertContains(t, stderr, testCase.expectOutputToContain) |
| 269 | }) |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | // func TestClearActiveSpinners(t *testing.T) { |
| 274 | // activeSpinnerPrinters = []*pterm.SpinnerPrinter{} |
nothing calls this directly
no test coverage detected
searching dependent graphs…