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: leading/trailing spacing in the output of examples is not handled correctly #9109

Closed
fhs opened this issue Nov 16, 2014 · 2 comments
Milestone

Comments

@fhs
Copy link
Contributor

fhs commented Nov 16, 2014

What does 'go version' print?

go version devel +fe11c71dbee6 Tue Nov 11 16:06:47 2014 +1100 linux/amd64

What steps reproduce the problem?

In the code below, there are leading and trailing spaces in both the Println lines and
each lines of Output section.

$ cat foo_test.go
package foo
import "fmt"
func Example() {
    fmt.Println("  one  ")
    fmt.Println("  two  ")
    fmt.Println("  three  ")
    // Output:
    //   one  
    //   two  
    //   three  
}
$ go test
--- FAIL: Example (0.00s)
got:
one  
  two  
  three
want:
one
  two
  three
FAIL
exit status 1
FAIL    _/home/fhs/tmp/example  0.001s
$

What happened?

It looks like the leading spaces of first line and the trailing spaces of the last line
in the "got" output was removed. All other spaces are still there.

However, for the "want" output, only the leading spaces of the second and
third lines are there. All other spaces were removed (including all the trailing spaces
-- maybe the parser is removing all trailing spaces from comments).

What should have happened instead?

The documentation says: "The comparison ignores leading and trailing space."

It doesn't say the spaces are ignored for each line, but I think it makes more sense to
trim leading and trailing spaces for each line. At least it should be consistent about
how it's removing the spaces.
@ianlancetaylor
Copy link
Contributor

Comment 1:

Labels changed: added repo-main, release-go1.5.

@josharian
Copy link
Contributor

Comment 2:

Status changed to Duplicate.

Merged into issue #6416.

@bradfitz bradfitz modified the milestone: Go1.5 Dec 16, 2014
@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants