Skip to content

testing: Example fails with correct output. #5196

@gopherbot

Description

@gopherbot

by soniakeys:

What steps will reproduce the problem?

1. bug.go:

package bug

import "fmt"

func Table() {
    fmt.Println("   1")
    fmt.Println("  10")
    fmt.Println(" 100")
    fmt.Println("1000")
}

2. bug_test.go:

package bug

func ExampleTable() {
    Table()
    //Output:
    //   1
    //  10
    // 100
    //1000
}

3. go test

What is the expected output?

PASS

What do you see instead?

--- FAIL: ExampleTable (11.138us)
got:
1
  10
 100
1000
want:
1
 10
100
1000
FAIL
exit status 1
FAIL    bug     0.008s

Which compiler are you using (5g, 6g, 8g, gccgo)?

6g

Which operating system are you using?

linux_amd64

Which version are you using?  (run 'go version')

go version devel +8153882a36e8 Wed Apr 03 11:13:40 2013 -0700 linux/amd64

Please provide any additional information below.

The problem seems to require at least one line of example output without leading space,
and then at least one line other than the first line with leading space.

While example examples in the testing package doc show leading spaces, the doc does not
say this is required and in fact says that the comparison ignores leading and trailing
space.

Further, the failure report shows a confusing mix of trimmed and untrimmed lines
(perhaps related to the incorrect fail result.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions