forked from Velocidex/go-yara
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompiler_test.go
38 lines (34 loc) · 865 Bytes
/
compiler_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
package yara
import "testing"
func TestCompiler(t *testing.T) {
c, _ := NewCompiler()
if err := c.AddString(
"rule test : tag1 { meta: author = \"Hilko Bengen\" strings: $a = \"abc\" fullword condition: $a }", "",
); err != nil {
t.Errorf("error: %s", err)
}
if err := c.AddString("xxx", ""); err == nil {
t.Error("did not recognize error")
} else {
t.Logf("expected error: %s", err)
}
}
func TestPanic(t *testing.T) {
defer func() {
err := recover()
if err == nil {
t.Error("MustCompile with broken data did not panic")
} else {
t.Logf("Everything ok, MustCompile panicked: %v", err)
}
}()
_ = MustCompile("asflkjkl", nil)
}
func TestWarnings(t *testing.T) {
c, _ := NewCompiler()
c.AddString("rule foo { bar }", "")
if len(c.Errors) == 0 {
t.Error()
}
t.Logf("Recorded Errors=%#v, Warnings=%#v", c.Errors, c.Warnings)
}