forked from rsc/c2go
-
Notifications
You must be signed in to change notification settings - Fork 4
/
c2go_test.go
79 lines (75 loc) · 1.5 KB
/
c2go_test.go
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"bytes"
"os/exec"
"path/filepath"
"testing"
)
var testcases = []struct {
Name string
Args []string
Output []byte
}{
{
Name: "binarytrees",
Args: []string{"10"},
Output: []byte(`stretch tree of depth 11 check: 4095
1024 trees of depth 4 check: 31744
256 trees of depth 6 check: 32512
64 trees of depth 8 check: 32704
16 trees of depth 10 check: 32752
long lived tree of depth 10 check: 2047
`),
},
{
Name: "fannkuchredux",
Args: []string{"9"},
Output: []byte(`8629
Pfannkuchen(9) = 30
`),
},
{
Name: "nbody",
Args: []string{"10000"},
Output: []byte(`-0.169075164
-0.169016441
`),
},
{
Name: "struct_copy",
Output: []byte("/usr/home 1\n"),
},
{
Name: "macro",
Output: []byte("16\n"),
},
{
Name: "variadic-macro",
Output: []byte(`Something is wrong
Error #435
`),
},
{
Name: "statement_macro",
Output: []byte("-5\n"),
},
}
func TestOutput(t *testing.T) {
for _, c := range testcases {
dir := t.TempDir()
C2Go([]string{filepath.Join("testdata", c.Name+".c")}, options{
cfgFile: filepath.Join("testdata", c.Name+".cfg"),
dst: dir,
})
args := []string{"run", filepath.Join(dir, "main", c.Name+".go")}
args = append(args, c.Args...)
cmd := exec.Command("go", args...)
got, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("error running Go program for %s: %v\n%s", c.Name, err, got)
}
if !bytes.Equal(got, c.Output) {
t.Fatalf("unexpected output from %s: got %q, want %q", c.Name, got, c.Output)
}
}
}