Source file
src/simd/testdata_test.go
1
2
3
4
5
6
7 package simd_test
8
9 import (
10 "internal/testenv"
11 "os"
12 "strings"
13 "testing"
14 )
15
16 func common(t *testing.T, dir, what, failWith string) {
17 t.Helper()
18 t.Logf("subprocess test in testdata")
19 testenv.MustHaveGoRun(t)
20 args := []string{"test", "-C", dir}
21 if testing.Verbose() {
22 args = append(args, "-v")
23 }
24 args = append(args, what)
25 cmd := testenv.Command(t, testenv.GoToolPath(t), args...)
26
27 if failWith == "" {
28 cmd.Stdout = os.Stdout
29 cmd.Stderr = os.Stderr
30 if err := cmd.Run(); err != nil {
31 t.Error(err)
32 }
33 } else {
34 combined, err := cmd.CombinedOutput()
35 combinedString := string(combined)
36 sawFailure := strings.Contains(combinedString, failWith)
37 if err == nil && !sawFailure {
38 t.Errorf("Saw no error and did not see expected failure string '%s' in '%s'", failWith, combinedString)
39 } else if err == nil && sawFailure {
40 t.Errorf("Saw no error but did see expected failure string '%s'", failWith)
41 } else if err != nil && !sawFailure {
42 t.Errorf("Saw error %v but did see expected failure string '%s' in '%s'", err, failWith, combinedString)
43 } else {
44 t.Logf("Saw error %v and expected failure string '%s'", err, failWith)
45 }
46 }
47 }
48 func TestIFace(t *testing.T) {
49 common(t, "testdata", "iface_test.go", "")
50 }
51
52 func TestSizeof(t *testing.T) {
53 common(t, "testdata", "sizeof_test.go", "")
54 }
55
56 func TestCompileOk(t *testing.T) {
57 common(t, "testdata", "compiles_test.go", "")
58 }
59
60 func TestCompileError(t *testing.T) {
61 common(t, "testdata", "errors_test.go",
62 "array length unsafe.Sizeof(v_from_simd) (value of type uintptr) must be constant")
63 }
64
View as plain text