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

go/parser: example for ParseFile fails on golang.org (playground) #19823

Closed
aaash99999 opened this issue Apr 3, 2017 · 6 comments
Closed

go/parser: example for ParseFile fails on golang.org (playground) #19823

aaash99999 opened this issue Apr 3, 2017 · 6 comments

Comments

@aaash99999
Copy link

@aaash99999 aaash99999 commented Apr 3, 2017

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

n/a (error is on golang.org)

What operating system and processor architecture are you using (go env)?

n/a

What did you do?

Visit https://golang.org/pkg/go/parser/#example_ParseFile (specifically, the example for ParseFile).
Click Run to run the example.

What did you expect to see?

Output of the program.

What did you see instead?

open example_test.go: No such file or directory

Program exited.

@sgen
Copy link

@sgen sgen commented Apr 3, 2017

The example is being run in the (Go Playground)[https://play.golang.org/]
which is run with various restrictions, including (filesystem restrictions)[https://blog.golang.org/playground#TOC_3.2.]. I dont think this example is supposed to run in the playground.

Does the example work when you copy it to a new package and include a valid 'example_test.go' file?

@mvdan
Copy link
Member

@mvdan mvdan commented Apr 3, 2017

The example depends on its own file in the go/parser package: https://golang.org/src/go/parser/

I guess a way to make it work in the playground would be for the example to first write a file to disk, or to use a buffer/string as the source.

@josharian josharian added this to the Go1.9 milestone Apr 3, 2017
@mvdan
Copy link
Member

@mvdan mvdan commented Apr 3, 2017

I'll write up a quick CL doing that.

@mvdan mvdan changed the title Example on golang.org for Parser.ParseFile fails with No such file or directory go/parser: example for ParseFile fails on golang.org (playground) Apr 3, 2017
@sgen
Copy link

@sgen sgen commented Apr 3, 2017

In (Inside the Go Playground)[https://blog.golang.org/playground] its mentioned that zip files may be uploaded for the purpose of examples. Perhaps uploading example_test.go is a better solution?

@mvdan
Copy link
Member

@mvdan mvdan commented Apr 3, 2017

I think that's a bit overkill. If the purpose of the example was precisely to use a file via filename and not a string/bytes/reader via src, then we can just make the example write the sample source to disk first.

@gopherbot
Copy link

@gopherbot gopherbot commented Apr 3, 2017

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

@gopherbot gopherbot closed this in d6b9994 Apr 3, 2017
lparth added a commit to lparth/go that referenced this issue Apr 13, 2017
The example shouldn't rely on the existance of example_test.go. That
breaks in the playground, which is what the "run" button in
https://golang.org/pkg/go/parser/#example_ParseFile does.

Make the example self-sufficient by using a small piece of source via a
string literal instead.

Fixes golang#19823.

Change-Id: Ie8a3c6c5d00724e38ff727862b62e6a3621adc88
Reviewed-on: https://go-review.googlesource.com/39236
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Robert Griesemer <gri@golang.org>
@golang golang locked and limited conversation to collaborators Apr 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.