-
Notifications
You must be signed in to change notification settings - Fork 0
/
evaluate_test.go
69 lines (62 loc) · 1.56 KB
/
evaluate_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
package scanlib
import (
"bytes"
"errors"
"os"
"path/filepath"
"strings"
"testing"
"git.furqansoftware.net/toph/scanlib/ast"
"git.furqansoftware.net/toph/scanlib/eval"
)
func TestEvaluate(t *testing.T) {
fis, err := os.ReadDir("./testdata")
if err != nil {
t.Fatal(err)
}
for _, fi := range fis {
t.Run(fi.Name(), func(t *testing.T) {
_, err := os.Stat(filepath.Join("./testdata", fi.Name(), "_skip"))
if err == nil {
t.Skip()
}
specsrc, err := os.ReadFile(filepath.Join("./testdata", fi.Name(), "scanspec"))
if err != nil {
t.Fatal(err)
}
n, err := ast.ParseString("inputspec", string(specsrc))
if err != nil {
t.Fatal(err)
}
pis, err := os.ReadDir(filepath.Join("./testdata", fi.Name(), "inputs"))
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return
}
t.Fatal(err)
}
for _, pi := range pis {
if !strings.HasSuffix(pi.Name(), ".in") {
continue
}
t.Run(pi.Name(), func(t *testing.T) {
instr, err := os.ReadFile(filepath.Join("./testdata", fi.Name(), "inputs", pi.Name()))
if err != nil {
t.Fatal(err)
}
errstr, _ := os.ReadFile(filepath.Join("./testdata", fi.Name(), "inputs", strings.TrimSuffix(pi.Name(), ".in")+".err"))
_, err = eval.Evaluate(n, bytes.NewReader(instr))
if err != nil {
if err.Error() != string(errstr) {
t.Fatalf("want err == %q, got %q", string(errstr), err.Error())
}
} else {
if string(errstr) != "" {
t.Fatalf("want err == %q, got nil", string(errstr))
}
}
})
}
})
}
}