-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathastextract_test.go
55 lines (48 loc) · 1.11 KB
/
astextract_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
package astextract
import (
"flag"
"os"
"path/filepath"
"testing"
"github.com/rogpeppe/go-internal/gotooltest"
"github.com/rogpeppe/go-internal/testscript"
)
func TestMain(m *testing.M) {
os.Exit(testscript.RunMain(m, map[string]func() int{
"astextract": Main1,
}))
}
var update = flag.Bool("u", false, "update testscript output files")
func TestScripts(t *testing.T) {
t.Parallel()
p := testscript.Params{
Dir: filepath.Join("testdata", "scripts"),
Cmds: map[string]func(ts *testscript.TestScript, neg bool, args []string){
"bincmp": bincmp,
},
UpdateScripts: *update,
}
if err := gotooltest.Setup(&p); err != nil {
t.Fatal(err)
}
testscript.Run(t, p)
}
func bincmp(ts *testscript.TestScript, neg bool, args []string) {
if len(args) != 2 {
ts.Fatalf("usage: bincmp file1 file2")
}
data1 := ts.ReadFile(args[0])
data2 := ts.ReadFile(args[1])
if neg {
if data1 == data2 {
ts.Fatalf("%s and %s don't differ",
args[0], args[1])
}
return
}
if data1 != data2 {
sizeDiff := len(data2) - len(data1)
ts.Fatalf("%s and %s differ; size diff: %+d",
args[0], args[1], sizeDiff)
}
}