We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
xgo
os.MkdirAll
GO111MODULE='on' GOARCH='arm64' GOBIN='/Users/sincos/sincos/bin' GOCACHE='/Users/sincos/sincos/tmp/go-cache' GOENV='/Users/sincos/Library/Application Support/go/env' GOEXE='' GOEXPERIMENT='' GOFLAGS='' GOHOSTARCH='arm64' GOHOSTOS='darwin' GOINSECURE='' GOMODCACHE='/Users/sincos/sincos/pkg/mod' GONOPROXY='' GONOSUMDB='' GOOS='darwin' GOPATH='/Users/sincos/sincos' GOPRIVATE='' GOPROXY='https://proxy.golang.org,direct' GOROOT='/opt/homebrew/Cellar/go/1.22.0/libexec' GOSUMDB='sum.golang.org' GOTMPDIR='/Users/sincos/sincos/tmp/go-tmp' GOTOOLCHAIN='auto' GOTOOLDIR='/opt/homebrew/Cellar/go/1.22.0/libexec/pkg/tool/darwin_arm64' GOVCS='' GOVERSION='go1.22.0' GCCGO='gccgo' AR='ar' CC='cc' CXX='c++' CGO_ENABLED='1' GOMOD='/Users/sincos/sincos/src/github.com/sincospro/snippets/xgo/go.mod' GOWORK='' CGO_CFLAGS='-O2 -g' CGO_CPPFLAGS='' CGO_CXXFLAGS='-O2 -g' CGO_FFLAGS='-O2 -g' CGO_LDFLAGS='-O2 -g' PKG_CONFIG='pkg-config' GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/Users/sincos/sincos/tmp/go-tmp/go-build1010920956=/tmp/go-build -gno-record-gcc-switches -fno-common'
func MyFunc(output string) error { if err := os.MkdirAll(output, os.ModePerm); err != nil { return err } // other code return nil } func TestMyFunc(t *testing.T) { t.Run("FailedToMkDir", func(t *testing.T) { mock.Patch(os.MkdirAll, func(string, os.FileMode) error { return nil }) }) }
xgo test ./... -v
=== RUN TestMyFunc === RUN TestMyFunc/FailedToMkDir --- FAIL: TestMyFunc (0.00s) --- FAIL: TestMyFunc/FailedToMkDir (0.00s) panic: failed to setup mock for: os.MkdirAll [recovered] panic: failed to setup mock for: os.MkdirAll goroutine 4 [running]: testing.tRunner.func1.2({0x100da6380, 0x140003b5560}) /Users/sincos/.xgo/go-instrument/go1.22.0_op_ho_Ce_go_1._li_26ff9148/go1.22.0/src/testing/testing.go:1642 +0x1c4 testing.tRunner.func1() /Users/sincos/.xgo/go-instrument/go1.22.0_op_ho_Ce_go_1._li_26ff9148/go1.22.0/src/testing/testing.go:1645 +0x334 panic({0x100da6380?, 0x140003b5560?}) /Users/sincos/.xgo/go-instrument/go1.22.0_op_ho_Ce_go_1._li_26ff9148/go1.22.0/src/runtime/panic.go:770 +0x124 github.com/xhd2015/xgo/runtime/mock.getFunc({0x100d9a660, 0x100e426d8}) /Users/sincos/sincos/pkg/mod/github.com/xhd2015/xgo/[email protected]/mock/mock.go:54 +0xd4 github.com/xhd2015/xgo/runtime/mock.Patch({0x100d9a660, 0x100e426d8}, {0x100d9a660, 0x100e426d0}) /Users/sincos/sincos/pkg/mod/github.com/xhd2015/xgo/[email protected]/mock/patch.go:51 +0x1fc github.com/sincospro/learn/xgo.TestMyFunc.func1(0x14000344b60) /Users/sincos/sincos/src/github.com/sincospro/snippets/xgo/xgo_test.go:19 +0x118 testing.tRunner(0x14000344b60, 0x100e426c8) /Users/sincos/.xgo/go-instrument/go1.22.0_op_ho_Ce_go_1._li_26ff9148/go1.22.0/src/testing/testing.go:1709 +0x23c created by testing.(*T).Run in goroutine 3 /Users/sincos/.xgo/go-instrument/go1.22.0_op_ho_Ce_go_1._li_26ff9148/go1.22.0/src/testing/testing.go:1762 +0x2f4 FAIL github.com/sincospro/learn/xgo 0.438s FAIL exit status 1
The text was updated successfully, but these errors were encountered:
In current version of xgo, you need to add --trap-stdlib to mock stdlib functions.
--trap-stdlib
See #144.
We are planning to make it default in the future versions.
Sorry, something went wrong.
os.MkdirAll has been tested to work with --trap-stdlib, see
xgo/runtime/test/trap_stdlib_any/trap_stdlib_any_test.go
Line 52 in 310d0d4
@saitofun --trap-stdlib has been made default when running xgo test, released with https://github.com/xhd2015/xgo/releases/tag/v1.0.38.
xgo test
To install xgo v1.0.38:
# update xgo go install github.com/xhd2015/xgo/cmd/[email protected] # update dependency go get github.com/xhd2015/xgo/[email protected]
Thanks.
No branches or pull requests
go env
test code:
test command:
xgo test ./... -v
test output:
The text was updated successfully, but these errors were encountered: