Skip to content

cmd/compile: the results of "go test" and "go test -c" are not the same #45626

@chanxuehong

Description

@chanxuehong

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

$ go version
go version go1.16.3 darwin/amd64

Does this issue reproduce with the latest release?

yes

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

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/chan/Library/Caches/go-build"
GOENV="/Users/chan/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/chan/gopath/pkg/mod"
GONOPROXY="*.shmiao.net,*.innotechx.com"
GONOSUMDB="*.shmiao.net,*.innotechx.com"
GOOS="darwin"
GOPATH="/Users/chan/gopath"
GOPRIVATE="*.shmiao.net,*.innotechx.com"
GOPROXY="https://goproxy.cn|https://goproxy.io|direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.16.3"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/qw/ddvmdjjd35xcj6823_nz3z780000gn/T/go-build3676776976=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I wrote an internal SDK (in the attach file below), when I execute go test, I find it fails, this is not what I expected;
When I execute go test -c and then execute this executable test file, it succeeds, this is what I expected.

extract the attach file below, cd to internal directory

go test # failed

go test -c
./internal.test # success

What did you expect to see?

➜  internal go version
go version go1.16.3 darwin/amd64
➜  internal go test -c && ./internal.test 
PASS
➜  internal go test 
--- FAIL: TestMessageToMap (0.00s)
    message_json_test.go:105: failed,
        have:map[bool_val:1 float32_val:5.5 float64_val:6.5 int32_val:1 int64_val:2 message_val:{"string_val":"sub_str", "message_val":{"string_val":"sub_sub_str"}} string_val:str uint32_val:3 uint64_val:4],
        want:map[bool_val:1 float32_val:5.5 float64_val:6.5 int32_val:1 int64_val:2 message_val:{"string_val":"sub_str","message_val":{"string_val":"sub_sub_str"}} string_val:str uint32_val:3 uint64_val:4]
--- FAIL: TestMarshalJSON (0.00s)
    message_json_test.go:206: failed,
        have:{"bool_val":"1","float32_val":"5.5","float64_val":"6.5","int32_val":"1","int64_val":"2","message_val":"{\"string_val\":\"sub_str\", \"message_val\":{\"string_val\":\"sub_sub_str\"}}","string_val":"str","uint32_val":"3","uint64_val":"4"},
        want:{"bool_val":"1","float32_val":"5.5","float64_val":"6.5","int32_val":"1","int64_val":"2","message_val":"{\"string_val\":\"sub_str\",\"message_val\":{\"string_val\":\"sub_sub_str\"}}","string_val":"str","uint32_val":"3","uint64_val":"4"}
--- FAIL: TestUnmarshalJSON (0.00s)
    message_json_test.go:222: nil proto.Message
    message_json_test.go:234: nil *internal.Message
    message_json_test.go:246: json: cannot unmarshal string "\"True\"" into Go value of type bool
    message_json_test.go:258: invalid character 'a' after object key:value pair
    message_json_test.go:315: json: cannot unmarshal string "\"fuck\"" into Go value of type int32
    message_json_test.go:327: json: cannot unmarshal string "\"2147483648\"" into Go value of type int32
    message_json_test.go:339: json: cannot unmarshal string "\"fuck\"" into Go value of type int64
    message_json_test.go:351: json: cannot unmarshal string "\"9223372036854775808\"" into Go value of type int64
    message_json_test.go:363: json: cannot unmarshal string "\"fuck\"" into Go value of type uint32
    message_json_test.go:375: json: cannot unmarshal string "\"4294967296\"" into Go value of type uint32
    message_json_test.go:387: json: cannot unmarshal string "\"fuck\"" into Go value of type uint64
    message_json_test.go:399: json: cannot unmarshal string "\"18446744073709551616\"" into Go value of type uint64
    message_json_test.go:411: json: cannot unmarshal string "\"fuck\"" into Go value of type float32
    message_json_test.go:423: json: cannot unmarshal string "\"3.4028234663852886e+39\"" into Go value of type float32
    message_json_test.go:435: json: cannot unmarshal string "\"fuck\"" into Go value of type float64
    message_json_test.go:447: json: cannot unmarshal string "\"1.7976931348623157e+309\"" into Go value of type float64
    message_json_test.go:459: json: cannot unmarshal string "\"fuck\"" into Go value of type *internal.SubMessage
    message_json_test.go:693: failed,
        have:{"bool_val":"1","float32_val":"3.4028234663852886e+38","float64_val":"1.7976931348623157e+308","int32_val":"2147483647","int64_val":"9223372036854775807","message_val":"{\"string_val\":\"sub_str\", \"message_val\":{\"string_val\":\"sub_sub_str\"}}","string_val":"str","uint32_val":"4294967295","uint64_val":"18446744073709551615"},
        want:{"bool_val":"1","float32_val":"3.4028234663852886e+38","float64_val":"1.7976931348623157e+308","int32_val":"2147483647","int64_val":"9223372036854775807","message_val":"{\"string_val\":\"sub_str\",\"message_val\":{\"string_val\":\"sub_sub_str\"}}","string_val":"str","uint32_val":"4294967295","uint64_val":"18446744073709551615"}
FAIL
exit status 1
FAIL    test3/internal  0.528s
➜  internal 

What did you see instead?

➜  internal go version
go version go1.16.3 darwin/amd64
➜  internal go test -c && ./internal.test 
PASS
➜  internal go test 
PASS
➜  internal 

test files

test3.tar.gz

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions