Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing: Example fails with correct output. #5196

Closed
gopherbot opened this issue Apr 3, 2013 · 2 comments

Comments

Projects
None yet
3 participants
@gopherbot
Copy link

commented Apr 3, 2013

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.)
@adg

This comment has been minimized.

Copy link
Contributor

commented Apr 3, 2013

Comment 1:

If you write your example function using a space after the "//" comments (as is the
common convention), it works fine:
func ExampleTable() {
    Table()
    // Output:
    //    1
    //   10
    //  100
    // 1000
}
I think this is a bad interaction with the go parser's comment parsing code and your
comment style. Changing the comment style fixes it. I'm not sure whether we should take
this further.

Status changed to Thinking.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Jul 30, 2013

Comment 2:

I think the ansewr is to use spaces after //.

Status changed to Unfortunate.

@golang golang locked and limited conversation to collaborators Jun 24, 2016

This issue was closed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.