From f2b732a78c53ed0cb739a0516023c042b81030c9 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Tue, 28 Dec 2021 22:26:27 +0800 Subject: [PATCH] change: skip go plugin test for windows --- parser_test.go | 19 ------------------- plugin_test.go | 40 ++++++++++++++++++++++++++++++++++++++++ runner.go | 10 ++++++++-- runner_test.go | 11 ----------- 4 files changed, 48 insertions(+), 32 deletions(-) create mode 100644 plugin_test.go diff --git a/parser_test.go b/parser_test.go index 4147bf5f..d7629fd8 100644 --- a/parser_test.go +++ b/parser_test.go @@ -1,7 +1,6 @@ package hrp import ( - "plugin" "sort" "testing" "time" @@ -369,24 +368,6 @@ func TestCallBuiltinFunction(t *testing.T) { } } -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() - } -} - func TestLiteralEval(t *testing.T) { testData := []struct { expr string diff --git a/plugin_test.go b/plugin_test.go new file mode 100644 index 00000000..eebfc59a --- /dev/null +++ b/plugin_test.go @@ -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() + } +} diff --git a/runner.go b/runner.go index 1b804911..737b33fc 100644 --- a/runner.go +++ b/runner.go @@ -12,6 +12,7 @@ import ( "os" "path/filepath" "plugin" + "runtime" "strconv" "strings" "testing" @@ -519,6 +520,11 @@ type pluginLoader struct { } func (r *caseRunner) loadPlugin(path string) error { + if runtime.GOOS == "windows" { + log.Warn().Msg("go plugin does not support windows") + return nil + } + if path == "" { return nil } @@ -551,8 +557,8 @@ func (r *hrpRunner) getSummary() *testCaseSummary { return &testCaseSummary{} } -// locatePlugin -// searching will be recursive upward until current working directory or system root dir. +// locatePlugin searches debugtalk.so upward recursively until current +// working directory or system root dir. func locatePlugin(startPath string) (string, error) { stat, err := os.Stat(startPath) if os.IsNotExist(err) { diff --git a/runner_test.go b/runner_test.go index 80770b4b..4318a754 100644 --- a/runner_test.go +++ b/runner_test.go @@ -1,23 +1,12 @@ package hrp import ( - "fmt" "os" - "os/exec" "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 TestLocatePlugin(t *testing.T) { cwd, _ := os.Getwd() _, err := locatePlugin(cwd)