You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
garble/testdata/scripts/plugin.txt

55 lines
1.1 KiB
Plaintext

[windows] skip 'Go plugins are not supported on Windows'
garble build -buildmode=plugin ./plugin
binsubstr plugin.so 'PublicVar' 'PublicFunc'
! binsubstr plugin.so 'privateFunc'
# Note that we need -trimpath; see the caveat section in the README.
go build -trimpath
exec ./main
cmp stderr main.stderr
binsubstr main$exe 'PublicVar' 'PublicFunc'
! binsubstr plugin.so 'privateFunc'
[short] stop # no need to verify this with -short
go build -buildmode=plugin ./plugin
binsubstr plugin.so 'PublicVar' 'PublicFunc' 'privateFunc'
go build
exec ./main
cmp stderr main.stderr
-- go.mod --
module test/main
-- plugin/main.go --
package main
var PublicVar int
func privateFunc(n int) { println("Hello, number", n) }
func PublicFunc() { privateFunc(PublicVar) }
-- main.go --
package main
import "plugin"
func main() {
p, err := plugin.Open("plugin.so")
if err != nil {
panic(err)
}
v, err := p.Lookup("PublicVar")
if err != nil {
panic(err)
}
f, err := p.Lookup("PublicFunc")
if err != nil {
panic(err)
}
*v.(*int) = 7
f.(func())()
}
-- main.stderr --
Hello, number 7