agiledragon / gomonkey

gomonkey is a library to make monkey patching in unit tests easy
MIT License
1.92k stars 178 forks source link

Is it possible to add a `init` func to check whether `-gcflags=all=-l` is in `os.Args`? #160

Closed Ericwww closed 6 days ago

Ericwww commented 5 months ago

Like this

func init() {
    if !slices.Contains(os.Args, "-gcflags=all=-l") {
        fmt.Println("WARNING: inline is enabled, some gomonkey patch will failed")
        os.Exit(1)
    }
}

I think this would remind developers to add -gcflags=all=-l.

But I'm not sure if this will affect go build, and judging from the current situation, my conclusion is that it won't.

agiledragon commented 3 weeks ago

@Ericwww It is a good idea, thank you!

agiledragon commented 3 weeks ago

@Ericwww You can commit a PR: func init() { if !slices.Contains(os.Args, "-gcflags=all=-l") { fmt.Println("WARNING: inline is enabled, some gomonkey patches may be failed!") } }

Remember to run tests before committing your changes.