-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbsharp_test.go
78 lines (69 loc) · 1.39 KB
/
bsharp_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
package main
import (
"embed"
"errors"
"io"
"path/filepath"
"testing"
"github.com/Nv7-Github/bsharp/ir"
"github.com/Nv7-Github/bsharp/parser"
"github.com/Nv7-Github/bsharp/tokens"
)
//go:embed std/*.bsp examples/*.bsp
var fuzzcorpus embed.FS
type FuzzFS struct{}
func (f *FuzzFS) Parse(name string) (*parser.Parser, error) {
return nil, errors.New("not implemented")
}
func FuzzIR(f *testing.F) {
files, err := fuzzcorpus.ReadDir("std")
if err != nil {
f.Fatal(err)
}
for _, fi := range files {
v, err := fuzzcorpus.Open(filepath.Join("std", fi.Name()))
if err != nil {
f.Fatal(err)
}
c, err := io.ReadAll(v)
if err != nil {
f.Fatal(err)
}
f.Add(string(c))
v.Close()
}
files, err = fuzzcorpus.ReadDir("examples")
if err != nil {
f.Fatal(err)
}
for _, fi := range files {
v, err := fuzzcorpus.Open(filepath.Join("examples", fi.Name()))
if err != nil {
f.Fatal(err)
}
c, err := io.ReadAll(v)
if err != nil {
f.Fatal(err)
}
f.Add(string(c))
v.Close()
}
f.Fuzz(func(t *testing.T, code string) {
s := tokens.NewStream("main.bsp", code)
tok := tokens.NewTokenizer(s)
err := tok.Tokenize()
if err != nil {
t.Skip("can't tokenize")
}
p := parser.NewParser(tok)
err = p.Parse()
if err != nil {
t.Skip("can't parse")
}
bld := ir.NewBuilder()
err = bld.Build(p, &FuzzFS{})
if err != nil {
t.Skip("can't build")
}
})
}