MCPcopy
hub / github.com/go-task/task / TestPrefixed

Function TestPrefixed

internal/output/output_test.go:124–154  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

122}
123
124func TestPrefixed(t *testing.T) { //nolint:paralleltest // cannot run in parallel
125 var b bytes.Buffer
126 l := &logger.Logger{
127 Color: false,
128 }
129
130 var o output.Output = output.NewPrefixed(l)
131 w, _, cleanup := o.WrapWriter(&b, io.Discard, "prefix", nil)
132
133 t.Run("simple use cases", func(t *testing.T) { //nolint:paralleltest // cannot run in parallel
134 b.Reset()
135
136 fmt.Fprintln(w, "foo\nbar")
137 assert.Equal(t, "[prefix] foo\n[prefix] bar\n", b.String())
138 fmt.Fprintln(w, "baz")
139 assert.Equal(t, "[prefix] foo\n[prefix] bar\n[prefix] baz\n", b.String())
140 require.NoError(t, cleanup(nil))
141 })
142
143 t.Run("multiple writes for a single line", func(t *testing.T) { //nolint:paralleltest // cannot run in parallel
144 b.Reset()
145
146 for _, char := range []string{"T", "e", "s", "t", "!"} {
147 fmt.Fprint(w, char)
148 assert.Equal(t, "", b.String())
149 }
150
151 require.NoError(t, cleanup(nil))
152 assert.Equal(t, "[prefix] Test!\n", b.String())
153 })
154}
155
156func TestPrefixedWithColor(t *testing.T) {
157 t.Parallel()

Callers

nothing calls this directly

Calls 4

WrapWriterMethod · 0.95
NewPrefixedFunction · 0.92
RunMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…