| 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 an import cycle loading error in a non test file. (#70820) |
| 44 |
! go test -json -o=$devnull ./cycle/p |
| 45 |
stdout '"ImportPath":"m/cycle/q","Action":"build-output","Output":"# m/cycle/p\\n"' |
| 46 |
stdout '"ImportPath":"m/cycle/q","Action":"build-output","Output":"package m/cycle/p\\n"' |
| 47 |
stdout '"ImportPath":"m/cycle/q","Action":"build-output","Output":"\\timports m/cycle/q from p.go\\n"' |
| 48 |
stdout '"ImportPath":"m/cycle/q","Action":"build-output","Output":"\\timports m/cycle/q from q.go: import cycle not allowed\\n"' |
| 49 |
stdout '"ImportPath":"m/cycle/q","Action":"build-fail"' |
| 50 |
stdout '"Action":"start","Package":"m/cycle/p"' |
| 51 |
stdout '"Action":"output","Package":"m/cycle/p","Output":"FAIL\\tm/cycle/p \[setup failed\]\\n"' |
| 52 |
stdout '"Action":"fail","Package":"m/cycle/p","Elapsed":.*,"FailedBuild":"m/cycle/q"' |
| 53 |
! stderr '.' |
| 54 |
|
| 55 |
# Test a vet error |
| 56 |
! go test -json -o=$devnull ./veterror |
| 57 |
stdout '"ImportPath":"m/veterror \[m/veterror.test\]","Action":"build-output","Output":"# m/veterror\\n"' |
| 58 |
stdout '"ImportPath":"m/veterror \[m/veterror.test\]","Action":"build-output","Output":"# \[m/veterror\]\\n"' |
| 59 |
stdout '"ImportPath":"m/veterror \[m/veterror.test\]","Action":"build-output","Output":"veterror(/|\\\\)main_test.go:9:21: fmt.Printf format %s reads arg #1, but call has 0 args\\n"' |
| 60 |
stdout '"ImportPath":"m/veterror \[m/veterror.test\]","Action":"build-fail"' |
| 61 |
stdout '"Action":"start","Package":"m/veterror"' |
| 62 |
stdout '"Action":"output","Package":"m/veterror","Output":"FAIL\\tm/veterror \[build failed\]\\n"' |
| 63 |
stdout '"Action":"fail","Package":"m/veterror","Elapsed":.*,"FailedBuild":"m/veterror \[m/veterror.test\]"' |
| 64 |
! stderr '.' |
| 65 |
|
| 66 |
# Test that the GODEBUG fallback works. |
| 67 |
env GODEBUG=gotestjsonbuildtext=1 |
| 68 |
! go test -json -o=$devnull ./builderror |
| 69 |
stderr '# m/builderror \[m/builderror.test\]\n' |
| 70 |
stderr 'builderror'${/}'main_test.go:3:11: undefined: y\n' |
| 71 |
stdout '"Action":"start","Package":"m/builderror"' |
| 72 |
stdout '"Action":"output","Package":"m/builderror","Output":"FAIL\\tm/builderror \[build failed\]\\n"' |
| 73 |
stdout '"Action":"fail","Package":"m/builderror","Elapsed":[0-9.]+\}' |
| 74 |
# FailedBuild should NOT appear in the output in this mode. |
| 75 |
! stdout '"FailedBuild"' |
| 76 |
|
| 77 |
-- go.mod -- |
| 78 |
module m |
| 79 |
go 1.21 |
| 80 |
-- builderror/main_test.go -- |
| 81 |
package builderror |
| 82 |
|
| 83 |
const x = y |
| 84 |
-- builderror2/x/main.go -- |
| 85 |
package x |
| 86 |
|
| 87 |
const x = y |
| 88 |
-- builderror2/main_test.go -- |
| 89 |
package builderror2 |
| 90 |
|
| 91 |
import _ "m/builderror2/x" |
| 92 |
-- loaderror/main_test.go -- |
| 93 |
// A bad import causes a "[setup failed]" message from cmd/go because |
| 94 |
// it fails in package graph setup, before it can even get to the |
| 95 |
// build. |
| 96 |
// |
| 97 |
// "[setup failed]" can also occur with various low-level failures in |
| 98 |
// cmd/go, like failing to create a temporary directory. |
| 99 |
|
| 100 |
package loaderror |
| 101 |
|
| 102 |
import _ "x" |
| 103 |
-- veterror/main_test.go -- |
| 104 |
package veterror |
| 105 |
|
| 106 |
import ( |
| 107 |
"fmt" |
| 108 |
"testing" |
| 109 |
) |
| 110 |
|
| 111 |
func TestVetError(t *testing.T) { |
| 112 |
fmt.Printf("%s") |
| 113 |
} |
| 114 |
-- cycle/p/p.go -- |
| 115 |
package p |
| 116 |
|
| 117 |
import "m/cycle/q" |
| 118 |
-- cycle/q/q.go -- |
| 119 |
package q |
| 120 |
|
| 121 |
import ( |
| 122 |
"m/cycle/q" |
| 123 |
) |