MCPcopy
hub / github.com/pterm/pterm / TestProgressbarPrinter_OutputToWriters

Function TestProgressbarPrinter_OutputToWriters

progressbar_printer_test.go:231–260  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

229}
230
231func TestProgressbarPrinter_OutputToWriters(t *testing.T) {
232 testCases := map[string]struct {
233 action func(*pterm.ProgressbarPrinter)
234 expectOutputToContain string
235 }{
236 "ExpectUpdatedTitleToBeWrittenToStderr": {
237 action: func(pb *pterm.ProgressbarPrinter) {
238 pb.UpdateTitle("Updated text")
239 },
240 expectOutputToContain: "Updated text",
241 },
242 }
243
244 for testTitle, testCase := range testCases {
245 t.Run(testTitle, func(t *testing.T) {
246 stderr, err := testza.CaptureStderr(func(w io.Writer) error {
247 pb, err := pterm.DefaultProgressbar.WithTitle("Hello world").WithWriter(os.Stderr).Start()
248 time.Sleep(time.Second) // Required otherwise the goroutine doesn't run and the text isn't outputted
249 testza.AssertNoError(t, err)
250 testCase.action(pb)
251 time.Sleep(time.Second) // Required otherwise the goroutine doesn't run and the text isn't updated
252 return nil
253 })
254
255 testza.AssertNoError(t, err)
256 testza.AssertContains(t, stderr, "Hello world")
257 testza.AssertContains(t, stderr, testCase.expectOutputToContain)
258 })
259 }
260}

Callers

nothing calls this directly

Calls 4

UpdateTitleMethod · 0.80
StartMethod · 0.45
WithWriterMethod · 0.45
WithTitleMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…