aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/testdata/script/list_parse_err.txt
diff options
context:
space:
mode:
authorJay Conrod <jayconrod@google.com>2019-12-11 13:16:35 -0500
committerJay Conrod <jayconrod@google.com>2020-04-06 18:06:41 +0000
commit74d6de03fd7db2c6faa7794620a9bcf0c4f018f2 (patch)
tree204c67aaa8e82be30da6fe004b68345d8c8a9405 /src/cmd/go/testdata/script/list_parse_err.txt
parent7dc1c62cc9eb7a8c0c554dd6d67da9bd4ddeac1c (diff)
downloadgo-74d6de03fd7db2c6faa7794620a9bcf0c4f018f2.tar.gz
go-74d6de03fd7db2c6faa7794620a9bcf0c4f018f2.zip
cmd/go: report scan error position in 'go list -e'tls
This CL extracts some error handling code into a common method for presenting errors encountered when loading package data. Fixes #36087 Fixes #36762 Change-Id: I87c8d41e3cc6e6afa152d9c067bc60923bf19fbe Reviewed-on: https://go-review.googlesource.com/c/go/+/210938 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/go/testdata/script/list_parse_err.txt')
-rw-r--r--src/cmd/go/testdata/script/list_parse_err.txt36
1 files changed, 32 insertions, 4 deletions
diff --git a/src/cmd/go/testdata/script/list_parse_err.txt b/src/cmd/go/testdata/script/list_parse_err.txt
index 5aacaa88fa..3c5345801a 100644
--- a/src/cmd/go/testdata/script/list_parse_err.txt
+++ b/src/cmd/go/testdata/script/list_parse_err.txt
@@ -1,17 +1,45 @@
-# 'go list' should report imports, even if some files have parse errors
+# 'go list' without -e should fail and print errors on stderr.
+! go list ./p
+stderr '^p[/\\]b.go:2:2: expected ''package'', found ''EOF''$'
+! go list -f '{{range .Imports}}{{.}} {{end}}' ./p
+stderr '^p[/\\]b.go:2:2: expected ''package'', found ''EOF''$'
+! go list -test ./t
+stderr '^can''t load test package: t[/\\]t_test.go:8:1: expected declaration, found ʕ'
+! go list -test -f '{{range .Imports}}{{.}} {{end}}' ./t
+stderr '^can''t load test package: t[/\\]t_test.go:8:1: expected declaration, found ʕ'
+
+# 'go list -e' should report imports, even if some files have parse errors
# before the import block.
-go list -e -f '{{range .Imports}}{{.}} {{end}}'
+go list -e -f '{{range .Imports}}{{.}} {{end}}' ./p
stdout '^fmt '
+# 'go list' should report the position of the error if there's only one.
+go list -e -f '{{.Error.Pos}} => {{.Error.Err}}' ./p
+stdout 'b.go:[0-9:]+ => expected ''package'', found ''EOF'''
+
+# 'go test' should report the position of the error if there's only one.
+go list -e -test -f '{{if .Error}}{{.Error.Pos}} => {{.Error.Err}}{{end}}' ./t
+stdout 't_test.go:[0-9:]+ => expected declaration, found ʕ'
+
-- go.mod --
module m
go 1.13
--- a.go --
+-- p/a.go --
package a
import "fmt"
--- b.go --
+-- p/b.go --
// no package statement
+
+-- t/t_test.go --
+package t
+
+import "testing"
+
+func Test(t *testing.T) {}
+
+// scan error
+ʕ◔ϖ◔ʔ