playground: support examples as tests

Playground handles examples in the same way as "go test" does.

If the program contains examples and does not import the "testing"
package, the playground injects the import without changing line numbers.
This is to prevent a mismatch of highlighted error lines on the
web page. The resulting import code is not properly formatted,
but it does not have to be since it is not meant to be read by humans.

Fixes golang/go#24311

Change-Id: I681a22d40d191fe706dfa9949421f4d3829031a4
Reviewed-on: https://go-review.googlesource.com/99595
Reviewed-by: Yury Smolsky <yury@smolsky.by>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2 files changed
tree: 5006f1c855d5c4698d7bd6ba9847e4c07ec24f99
  1. static/
  2. app.yaml
  3. AUTHORS
  4. cache.go
  5. client.go
  6. codereview.cfg
  7. CONTRIBUTING.md
  8. CONTRIBUTORS
  9. Dockerfile
  10. edit.go
  11. edit.html
  12. enable-fake-time.patch
  13. fake_fs.lst
  14. fmt.go
  15. LICENSE
  16. logger.go
  17. main.go
  18. Makefile
  19. PATENTS
  20. play.go
  21. play_test.go
  22. README.md
  23. sandbox.go
  24. server.go
  25. server_test.go
  26. share.go
  27. store.go
README.md

playground

This subrepository holds the source for the Go playground: https://play.golang.org/

To submit changes to this repository, see http://golang.org/doc/contribute.html.

Building

# build the image
docker build -t playground .

Running

docker run --rm -d -p 8080:8080 playground
# run go some code
cat /path/to/code.go | go run client.go | curl --data @- localhost:8080/compile

Deployment

gcloud --project=golang-org --account=person@example.com app deploy app.yaml

Contributing

To submit changes to this repository, see http://golang.org/doc/contribute.html.