...

Text file src/cmd/go/testdata/script/test_fail_newline.txt

Documentation: cmd/go/testdata/script

     1[short] skip
     2
     3# In package list mode, output is buffered.
     4# Check that a newline is printed after the buffer's contents.
     5cd fail
     6! go test .
     7! stderr .
     8stdout '^exitcode=1\n'
     9stdout '^FAIL\s+example/fail'
    10
    11# In local directory mode output is streamed, so we don't know
    12# whether the test printed anything at all, so we print the exit code
    13# (just in case it failed without emitting any output at all),
    14# and that happens to add the needed newline as well.
    15! go test
    16! stderr .
    17stdout '^exitcode=1exit status 1\n'
    18stdout '^FAIL\s+example/fail'
    19
    20# In package list mode, if the test passes the 'ok' message appears
    21# on its own line.
    22cd ../skip
    23go test -v .
    24! stderr .
    25stdout '^skipping\n'
    26stdout '^ok\s+example/skip'
    27
    28# If the output is streamed and the test passes, we can't tell whether it ended
    29# in a partial line, and don't want to emit any extra output in the
    30# overwhelmingly common case that it did not.
    31# (In theory we could hook the 'os' package to report whether output
    32# was emitted and whether it ended in a newline, but that seems too invasive.)
    33go test
    34! stderr .
    35stdout '^skippingok\s+example/skip'
    36
    37
    38-- go.mod --
    39module example
    40
    41go 1.18
    42-- fail/fail_test.go --
    43package fail
    44
    45import (
    46	"os"
    47	"testing"
    48)
    49
    50func TestMain(m *testing.M) {
    51	os.Stderr.WriteString("exitcode=1")
    52	os.Exit(1)
    53}
    54-- skip/skip_test.go --
    55package skip
    56
    57import (
    58	"os"
    59	"testing"
    60)
    61
    62func TestMain(m *testing.M) {
    63	os.Stderr.WriteString("skipping")
    64	os.Exit(0)
    65}

View as plain text