change: skip go plugin test for windows

This commit is contained in:
debugtalk
2021-12-28 22:26:27 +08:00
parent 2da666a4e6
commit f2b732a78c
4 changed files with 48 additions and 32 deletions

40
plugin_test.go Normal file
View File

@@ -0,0 +1,40 @@
// +build linux freebsd darwin
// go plugin doesn't support windows
package hrp
import (
"fmt"
"os"
"os/exec"
"plugin"
"testing"
"github.com/stretchr/testify/assert"
)
func TestMain(m *testing.M) {
fmt.Println("[TestMain] build go plugin")
cmd := exec.Command("go", "build", "-buildmode=plugin", "-o=examples/debugtalk.so", "examples/plugin/debugtalk.go")
if err := cmd.Run(); err != nil {
panic(err)
}
os.Exit(m.Run())
}
func TestCallPluginFunction(t *testing.T) {
plugins, err := plugin.Open("examples/debugtalk.so")
if err != nil {
t.Fatalf(err.Error())
}
pluginLoader := &pluginLoader{plugins}
// call function without arguments
f1, _ := getMappingFunction("Concatenate", pluginLoader)
result, err := callFunc(f1, 1, "2", 3.14)
if !assert.NoError(t, err) {
t.Fail()
}
if !assert.Equal(t, result, "1_2_3.14") {
t.Fail()
}
}