summaryrefslogtreecommitdiffstats
path: root/dependencies/pkg/mod/github.com/cespare/xxhash/v2@v2.1.2/dynamic/dynamic_test.go
blob: c86bc93d29e05d35e7ec1a41e26ffa8691642be8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// +build linux darwin

package main

import (
	"bytes"
	"log"
	"os/exec"
	"plugin"
	"testing"
)

// This is a cursory test that checks whether things work under dynamic linking.

func TestMain(m *testing.M) {
	cmd := exec.Command(
		"go", "build",
		"-buildmode", "plugin",
		"-o", "plugin.so",
		"plugin.go",
	)
	var out bytes.Buffer
	cmd.Stdout = &out
	cmd.Stderr = &out
	if err := cmd.Run(); err != nil {
		log.Fatalf("Error building plugin: %s\nOutput:\n%s", err, out.String())
	}
	m.Run()
}

func TestDynamic(t *testing.T) {
	plug, err := plugin.Open("plugin.so")
	if err != nil {
		t.Fatal(err)
	}
	for _, test := range []string{
		"TestSum",
		"TestDigest",
	} {
		f, err := plug.Lookup(test)
		if err != nil {
			t.Fatalf("cannot find func %s: %s", test, err)
		}
		f.(func(*testing.T))(t)
	}
}