Skip to content
New issue

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

supermonkey seems to not suit the higher version of golang #20

Open
ZenKaiii opened this issue Sep 30, 2022 · 3 comments
Open

supermonkey seems to not suit the higher version of golang #20

ZenKaiii opened this issue Sep 30, 2022 · 3 comments

Comments

@ZenKaiii
Copy link

Now we are using Go 1.14.2. It seems to be okay with Patch function. But when we need to upgrade our golang version to 1.15 or higher, the supermonkey.Patch seems not okay. Mock is ineffective. Do you konw why, or do you have a plan for suiting golang higher version.
Thank you.

@cch123
Copy link
Owner

cch123 commented Sep 30, 2022

I tried this patch demo in go 1.15.14, and it worked well

package main

import (
	"fmt"

	sm "github.com/cch123/supermonkey"
)

func main() {
	fmt.Println("original function output:")
	heyHeyHey()

	patchGuard := sm.PatchByFullSymbolName("main.heyHeyHey", func() {
		fmt.Println("please be polite")
	})
	fmt.Println("after patch, function output:")
	heyHeyHey()

	patchGuard.Unpatch()
	fmt.Println("unpatch, then output:")
	heyHeyHey()
}

//go:noinline
func heyHeyHey() {
	fmt.Println("fake")
}

can you provide a reproducible demo for your problem?

@ZenKaiii
Copy link
Author

I write golang code with go 1.17.8. Codes are down below. But the result is "hello" instead of "yeah
func hello() {
println("hello")
}

func TestName(t *testing.T) {
supermonkey.Patch(hello, func() {
println("yeah")
})
hello()
}

@cch123
Copy link
Owner

cch123 commented Sep 30, 2022

I write golang code with go 1.17.8. Codes are down below. But the result is "hello" instead of "yeah func hello() { println("hello") }

func TestName(t *testing.T) { supermonkey.Patch(hello, func() { println("yeah") }) hello() }

did you run your demo with proper flags?

Warning : use go test -ldflags="-s=false" -gcflags="-l" to enable symbol table and disable inline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants