MCPcopy
hub / github.com/pterm/pterm / TestSpinnerPrinter_OutputToWriters

Function TestSpinnerPrinter_OutputToWriters

spinner_printer_test.go:234–271  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

232}
233
234func 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{}

Callers

nothing calls this directly

Calls 6

WarningMethod · 0.80
FailMethod · 0.80
UpdateTextMethod · 0.80
StartMethod · 0.45
WithWriterMethod · 0.45
WithTextMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…