MCPcopy Index your code
hub / github.com/gopherdata/gophernotes / TestPrintStderr

Function TestPrintStderr

kernel_test.go:278–324  ·  view source on GitHub ↗

TestPrintStderr tests that data written to stderr publishes the same data in a "stderr" "stream" message.

(t *testing.T)

Source from the content-addressed store, hash-verified

276
277// TestPrintStderr tests that data written to stderr publishes the same data in a "stderr" "stream" message.
278func TestPrintStderr(t *testing.T) {
279 cases := []struct {
280 Input []string
281 Output []string
282 }{
283 {[]string{
284 `import "fmt"`,
285 `import "os"`,
286 "a := 1",
287 "fmt.Fprintln(os.Stderr, a)",
288 }, []string{"1\n"}},
289 {[]string{
290 `os.Stderr.WriteString("2")`,
291 }, []string{"2"}},
292 {[]string{
293 `import "time"`,
294 "for i := 0; i < 3; i++ {",
295 " fmt.Fprintln(os.Stderr, i)",
296 " time.Sleep(500 * time.Millisecond)", // Stall to prevent prints from buffering into single message.
297 "}",
298 }, []string{"0\n", "1\n", "2\n"}},
299 }
300
301 t.Logf("Should produce stderr stream messages when writing to stderr")
302
303cases:
304 for k, tc := range cases {
305 // Give a progress report.
306 t.Logf(" Evaluating code snippet %d/%d.", k+1, len(cases))
307
308 // Get the result.
309 _, stderr := testOutputStream(t, strings.Join(tc.Input, "\n"))
310
311 // Compare the result.
312 if len(stderr) != len(tc.Output) {
313 t.Errorf("\t%s Test case expected %d message(s) on stderr but got %d.", failure, len(tc.Output), len(stderr))
314 continue
315 }
316 for i, expected := range tc.Output {
317 if stderr[i] != expected {
318 t.Errorf("\t%s Test case returned unexpected messages on stderr.", failure)
319 continue cases
320 }
321 }
322 t.Logf("\t%s Returned the expected messages on stderr.", success)
323 }
324}
325
326//==============================================================================
327

Callers

nothing calls this directly

Calls 1

testOutputStreamFunction · 0.85

Tested by

no test coverage detected