1 [short] skip
2
3 env GODEBUG=gotestjsonbuildtext=0
4
5 # There are several places where paths appear in JSON in regexps here.
6 # For the path separator we use (/|\\\\).
7 # Unfortunately, we can't just use ${/} because, while script test automatically
8 # escapes Windows-style \ in regexps, it doesn't know that it needs to escape
9 # them *again* for JSON. If we ever teach script test about matching JSON,
10 # we can probably fix this.
11
12 # Test a build error directly in a test file.
13 ! go test -json -o=$devnull ./builderror
14 stdout '"ImportPath":"m/builderror \[m/builderror\.test\]","Action":"build-output","Output":"# m/builderror \[m/builderror.test\]\\n"'
15 stdout '"ImportPath":"m/builderror \[m/builderror\.test\]","Action":"build-output","Output":"builderror(/|\\\\)main_test.go:3:11: undefined: y\\n"'
16 stdout '"ImportPath":"m/builderror \[m/builderror\.test\]","Action":"build-fail"'
17 stdout '"Action":"start","Package":"m/builderror"'
18 stdout '"Action":"output","Package":"m/builderror","Output":"FAIL\\tm/builderror \[build failed\]\\n"'
19 stdout '"Action":"fail","Package":"m/builderror","Elapsed":.*,"FailedBuild":"m/builderror \[m/builderror\.test\]"'
20 ! stderr '.'
21
22 # Test a build error in an imported package. Make sure it's attributed to the right package.
23 ! go test -json -o=$devnull ./builderror2
24 stdout '"ImportPath":"m/builderror2/x","Action":"build-output","Output":"# m/builderror2/x\\n"'
25 stdout '"ImportPath":"m/builderror2/x","Action":"build-output","Output":"builderror2(/|\\\\)x(/|\\\\)main.go:3:11: undefined: y\\n"'
26 stdout '"ImportPath":"m/builderror2/x","Action":"build-fail"'
27 stdout '"Action":"start","Package":"m/builderror2"'
28 stdout '"Action":"output","Package":"m/builderror2","Output":"FAIL\\tm/builderror2 \[build failed\]\\n"'
29 stdout '"Action":"fail","Package":"m/builderror2","Elapsed":.*,"FailedBuild":"m/builderror2/x"'
30 ! stderr '.'
31
32 # Test a loading error in a test file
33 # TODO(#65335): ImportPath attribution is weird
34 ! go test -json -o=$devnull ./loaderror
35 stdout '"ImportPath":"x","Action":"build-output","Output":"# m/loaderror\\n"'
36 stdout '"ImportPath":"x","Action":"build-output","Output":".*package x is not in std.*"'
37 stdout '"ImportPath":"x","Action":"build-fail"'
38 stdout '"Action":"start","Package":"m/loaderror"'
39 stdout '"Action":"output","Package":"m/loaderror","Output":"FAIL\\tm/loaderror \[setup failed\]\\n"'
40 stdout '"Action":"fail","Package":"m/loaderror","Elapsed":.*,"FailedBuild":"x"'
41 ! stderr '.'
42
43 # Test a vet error
44 ! go test -json -o=$devnull ./veterror
45 stdout '"ImportPath":"m/veterror \[m/veterror.test\]","Action":"build-output","Output":"# m/veterror\\n"'
46 stdout '"ImportPath":"m/veterror \[m/veterror.test\]","Action":"build-output","Output":"# \[m/veterror\]\\n"'
47 stdout '"ImportPath":"m/veterror \[m/veterror.test\]","Action":"build-output","Output":"veterror(/|\\\\)main_test.go:9:9: fmt.Printf format %s reads arg #1, but call has 0 args\\n"'
48 stdout '"ImportPath":"m/veterror \[m/veterror.test\]","Action":"build-fail"'
49 stdout '"Action":"start","Package":"m/veterror"'
50 stdout '"Action":"output","Package":"m/veterror","Output":"FAIL\\tm/veterror \[build failed\]\\n"'
51 stdout '"Action":"fail","Package":"m/veterror","Elapsed":.*,"FailedBuild":"m/veterror \[m/veterror.test\]"'
52 ! stderr '.'
53
54 # Test that the GODEBUG fallback works.
55 env GODEBUG=gotestjsonbuildtext=1
56 ! go test -json -o=$devnull ./builderror
57 stderr '# m/builderror \[m/builderror.test\]\n'
58 stderr 'builderror'${/}'main_test.go:3:11: undefined: y\n'
59 stdout '"Action":"start","Package":"m/builderror"'
60 stdout '"Action":"output","Package":"m/builderror","Output":"FAIL\\tm/builderror \[build failed\]\\n"'
61 stdout '"Action":"fail","Package":"m/builderror","Elapsed":.*,"FailedBuild":"m/builderror \[m/builderror\.test\]"'
62
63
64 -- go.mod --
65 module m
66 go 1.21
67 -- builderror/main_test.go --
68 package builderror
69
70 const x = y
71 -- builderror2/x/main.go --
72 package x
73
74 const x = y
75 -- builderror2/main_test.go --
76 package builderror2
77
78 import _ "m/builderror2/x"
79 -- loaderror/main_test.go --
80 // A bad import causes a "[setup failed]" message from cmd/go because
81 // it fails in package graph setup, before it can even get to the
82 // build.
83 //
84 // "[setup failed]" can also occur with various low-level failures in
85 // cmd/go, like failing to create a temporary directory.
86
87 package loaderror
88
89 import _ "x"
90 -- veterror/main_test.go --
91 package veterror
92
93 import (
94 "fmt"
95 "testing"
96 )
97
98 func TestVetError(t *testing.T) {
99 fmt.Printf("%s")
100 }
101
View as plain text