-
Notifications
You must be signed in to change notification settings - Fork 11
/
prop_test.go
73 lines (61 loc) · 1.54 KB
/
prop_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
package main_test
import (
"bytes"
"os"
"os/exec"
"strings"
"testing"
)
const (
dirTest = "test/"
cmdTest = "../cascadia"
extRef = ".ref" // extension for reference file
extGot = ".got" // extension for generated file
)
// testIt runs @cmdTest with @argv and compares the generated
// output for @name with the corresponding @extRef
func testIt(t *testing.T, name string, argv ...string) {
var (
diffOut bytes.Buffer
generatedOutput = name + extGot
cmd = exec.Command(cmdTest, argv...)
)
t.Logf("Testing %s:\n\t%s %s\n", name, cmdTest, strings.Join(argv, " "))
// open the out file for writing
outfile, err := os.Create(generatedOutput)
if err != nil {
t.Errorf("write error [%s: %s] %s.", name, argv, err)
}
defer outfile.Close()
cmd.Stdout = outfile
err = cmd.Start()
if err != nil {
t.Errorf("start error [%s: %s] %s.", name, argv, err)
}
err = cmd.Wait()
if err != nil {
t.Errorf("exit error [%s: %s] %s.", name, argv, err)
}
cmd = exec.Command("diff", "-U1", name+extRef, generatedOutput)
cmd.Stdout = &diffOut
err = cmd.Start()
if err != nil {
t.Errorf("start error %s [%s: %s]", err, name, argv)
}
err = cmd.Wait()
if err != nil {
t.Errorf("cmp error %s [%s: %s]\n%s", err, name, argv, diffOut.String())
}
//os.Remove(generatedOutput)
}
type testCase struct {
name string
args []string
}
func testCases(t *testing.T, name string, testData []testCase) {
t.Logf("\n\n== Testing %s\n\n", name)
os.Chdir(dirTest)
for _, tc := range testData {
testIt(t, tc.name, tc.args...)
}
}