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

cmd/go: inconsistency about no text after "Output:" in examples #18191

Closed
mikioh opened this issue Dec 4, 2016 · 7 comments
Closed

cmd/go: inconsistency about no text after "Output:" in examples #18191

mikioh opened this issue Dec 4, 2016 · 7 comments
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@mikioh
Copy link
Contributor

mikioh commented Dec 4, 2016

go doc cmd/go says that An example with no such comment, or with no text after "Output:" is compiled but not executed but the current implementation behaves differently. Also the testing package never mentions the behavior. It might be better to clarify what's the correct behavior.

@mikioh mikioh added this to the Go1.8Maybe milestone Dec 4, 2016
@quentinmit quentinmit added the NeedsFix The path to resolution is known, but the work has not been done. label Dec 6, 2016
@quentinmit
Copy link
Contributor

Changing the docs is fine now, but if you want to change the behavior, this has to wait for 1.9 at this point.

@bradfitz
Copy link
Contributor

but the current implementation behaves differently

What is the current behavior you see?

Our standard bug report template has a section "What did you expect to see?" and "What did you see instead?". If you're not going to use the template, at least include all the relevant information.

@bradfitz bradfitz modified the milestones: Go1.9, Go1.8Maybe Dec 15, 2016
@mikioh
Copy link
Contributor Author

mikioh commented Dec 16, 2016

"What did you expect to see?"

It's hard to describe to me because I'm not sure whether the behavior must be the same and what's the expected behavior by the original author. The observable things are the following:

  • The testing package mentions nothing about no text after "Output:",
  • The cmd/go package says that no text after "Output:" never executes examples,
  • Running cmd/go test with an example containing no text after "Output:" executes the example.

@ALTree
Copy link
Member

ALTree commented Dec 16, 2016

Examples with no output comment are compiled but not executed (which is correct):

package foo_test

import "fmt"

func ExampleReverse() {
	fmt.Println("hello")
}

Examples with no text after //Output: behave differently from what go doc cmd/go says. The following:

package foo_test

import "fmt"

func ExampleReverse() {
	fmt.Println("hello")
	//Output:
}

is compiled and executed, both on go1.7.3 and on tip (and it fails at run-time because the output is not empty).

Note that rsc asked for an example with no text after //Output: to be actually run. This was Issue #4485.

It looks like it's the documentation that is outdated(?). We actually want to run Examples with no text after //Output:, and check that there's, in fact, no output.

The issue was fixed in https://codereview.appspot.com/7071050 but the author forgot to update the documentation.

@mikioh
Copy link
Contributor Author

mikioh commented Dec 16, 2016

Nice, thanks for the investigation, @ALTree.

@ALTree
Copy link
Member

ALTree commented Dec 16, 2016

I sent https://golang.org/cl/34512 (for 1.8 or 1.9, you decide).

@gopherbot
Copy link

CL https://golang.org/cl/34512 mentions this issue.

@mikioh mikioh modified the milestones: Go1.8, Go1.9 Dec 20, 2016
@golang golang locked and limited conversation to collaborators Dec 20, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants