-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Description
What version of Go are you using (go version)?
$ go version go version go1.20.2 darwin/amd64
⚠️ This also appears to affect go1.19, though I believe it worked at some point in the past
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env)?
❌ Not relevant, this happens in multiple environments including Go Playground with Go 1.19 and Go 1.20
What did you do?
- Provide a testable example of a function which returns output containing successive newlines
- Example cannot pass tests, since the
Outputannotation is modified by thetestingparser
Minimal example
Viewable here: https://go.dev/play/p/LFktKVr75lz
✅ The ExampleFoo function returns data containing successive newlines:
Single newline:
Double newline:
Final text✅ The ExampleFoo contains an embedded Output: annotation with the same expected output:
//Output:
//Single newline:
//
//Double newline:
//
//
//Final text✅ The Output and stdout are compared, with leading and trailing whitespace removed
❌ Multiple newlines are collapsed into single newlines, making the test fail - only solution is to modify the function under test (which is not an option)
What did you expect to see?
Output: should be parsed as-is, not modified (beyond trimming leading and trailing whitespace)
What did you see instead?
The multiple empty lines are collapsed into a single empty line
Additional context
Did a little hunting to see if I could find a root cause, no success yet
Currently suspect it's either hidden somewhere within the testing package, or is an unintended side effect of how chains of single line comments are parsed by ast