Skip to content

testing: leading/trailing spacing in the output of examples is not handled correctly #9109

Closed

Description

@fhs
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.

Activity

  1. ianlancetaylor commented on Nov 16, 2014

    @ianlancetaylor
    Contributor

    Comment 1:

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

  2. josharian commented on Dec 2, 2014

    @josharian
    Contributor

    Comment 2:

    Status changed to Duplicate.

    Merged into issue #6416.

  3. modified the milestone: Go1.5 on Dec 16, 2014
  4. locked and limited conversation to collaborators on Jun 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions