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: multiline example output comparison doesn't strip per-line whitespace #6416

Closed
josharian opened this issue Sep 18, 2013 · 16 comments

Comments

Projects
None yet
6 participants
@josharian
Copy link
Contributor

commented Sep 18, 2013

What steps will reproduce the problem?

1. Write a testing example that generates multiline output and in which interior lines
have trailing whitespace. For example, http://play.golang.org/p/3t5VyhWw7Z or
http://play.golang.org/p/nwSaMHGKU3.
2. go test


What is the expected output?

Interior lines' leading and trailing whitespace is stripped. The examples I provided
should pass.


What do you see instead?

Whitespace is stripped from the beginning of the first and the end of the last line
only. The examples I provided fail.


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

Reproduced with 1.1 and devel +5981425e55ce Tue Sep 17 16:54:22 2013 -0400 darwin/amd64


Please provide any additional information below.

The documentation doesn't strictly imply this behavior -- it says "(The comparison
ignores leading and trailing space.)". However, the fact that gofmt strips trailing
whitespace makes it hard to write certain examples (e.g. those involving raw HTTP
requests/responses) without this behavior.
@josharian

This comment has been minimized.

Copy link
Contributor Author

commented Sep 18, 2013

Comment 1:

Fix sketched in https://golang.org/cl/13469045, for fun. Can't submit it now
due to Go 1.2 freeze.
@robpike

This comment has been minimized.

Copy link
Contributor

commented Sep 18, 2013

Comment 2:

Labels changed: added priority-later, removed priority-triage.

Status changed to Accepted.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Sep 18, 2013

Comment 3:

hard to get that excited. gofmt will remove the spaces
@josharian

This comment has been minimized.

Copy link
Contributor Author

commented Sep 18, 2013

Comment 4:

gofmt removing the spaces *is* the problem (in cases in which you need the spaces to
make the output match).
@adg

This comment has been minimized.

Copy link
Contributor

commented Sep 18, 2013

Comment 5:

If you need explicit spacing, use a /* comment */ that gofmt will not touch.
I'm inclined to leave this WorkingAsIntended.
@josharian

This comment has been minimized.

Copy link
Contributor Author

commented Sep 18, 2013

Comment 6:

That didn't occur to me.
Alas, gofmt inserts tabs at the beginning of each line to make /* comments */ line up
nicely, and those tabs show up as part of the expected output for non-first lines.
@josharian

This comment has been minimized.

Copy link
Contributor Author

commented Sep 18, 2013

Comment 7:

Hmmm...the gofmt /* comments */ behavior seems to be under discussion in
https://golang.org/issue/5128. I guess this depends on what the
outcome of that is.
@adg

This comment has been minimized.

Copy link
Contributor

commented Sep 18, 2013

Comment 8:

Oh, I'm sorry about that. I must have mis-remembered that issue.
I guess your solution is fine, then. Correctness shouldn't depend on leading or trailing
spaces. That's just too finicky.
@rsc

This comment has been minimized.

Copy link
Contributor

commented Nov 27, 2013

Comment 9:

Labels changed: added go1.3maybe.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Dec 4, 2013

Comment 10:

Labels changed: added release-none, removed go1.3maybe.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Dec 4, 2013

Comment 11:

Labels changed: added repo-main.

@robpike

This comment has been minimized.

Copy link
Contributor

commented Dec 14, 2013

Comment 12:

I would prefer to see the output of the examples use exact matching because that's
easiest to specify and allows one to test exact output. For the rare examples for which
that is problematic, sanitize/regularlize the output before matching. That is, write
code.
@josharian

This comment has been minimized.

Copy link
Contributor Author

commented Dec 19, 2013

Comment 13:

I think that this can be closed as WorkingAsIntended.
@adg

This comment has been minimized.

Copy link
Contributor

commented Dec 19, 2013

Comment 14:

Status changed to WorkingAsIntended.

@josharian

This comment has been minimized.

Copy link
Contributor Author

commented Dec 2, 2014

Comment 15:

Issue #9109 has been merged into this issue.

@jbeda

This comment has been minimized.

Copy link

commented Jul 8, 2015

I urge you to reopen this bug. As far as I can figure, there is no way to test output that has trailing whitespace in intermediate lines. At least I can't find an easy work around.

The examples at the top of the issue still don't work and can't, as far as I can figure, be made to work. I also can't make /* */ syntax work: http://play.golang.org/p/51D2DYVHTy

jbeda added a commit to jbeda/kubernetes that referenced this issue Jul 9, 2015

Fix up alignment of columns w/ namespaces.
Fixes kubernetes#10842

All issues for types that use "extra lines" for extended information.  Two issues fixed: (1) When namespaces are listed an extra column isn't inserted for extra lines and (2) trailing tabs aren't inserted when label columns are specified.

This code should probably move to a more explicit model of putting data into "cells".

The test for this hits golang/go#6416 and so I introduced a "LineDelimiter" writer filter to make white space more visible.

jbeda added a commit to jbeda/kubernetes that referenced this issue Jul 9, 2015

Fix up alignment of columns w/ namespaces.
Fixes kubernetes#10842

All issues for types that use "extra lines" for extended information.  Two issues fixed: (1) When namespaces are listed an extra column isn't inserted for extra lines and (2) trailing tabs aren't inserted when label columns are specified.

This code should probably move to a more explicit model of putting data into "cells".

The test for this hits golang/go#6416 and so I introduced a "LineDelimiter" writer filter to make white space more visible.

jbeda added a commit to jbeda/kubernetes that referenced this issue Jul 9, 2015

Fix up alignment of columns w/ namespaces.
Fixes kubernetes#10842

All issues for types that use "extra lines" for extended information.  Two issues fixed: (1) When namespaces are listed an extra column isn't inserted for extra lines and (2) trailing tabs aren't inserted when label columns are specified.

This code should probably move to a more explicit model of putting data into "cells".

The test for this hits golang/go#6416 and so I introduced a "LineDelimiter" writer filter to make white space more visible.

@golang golang locked and limited conversation to collaborators Jul 11, 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.