forked from Velocidex/go-yara
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompiler_yara37_test.go
40 lines (35 loc) · 1.05 KB
/
compiler_yara37_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
//+build !yara3.3,!yara3.4,!yara3.5,!yara3.6
package yara
import (
"testing"
)
func setupCompiler(t *testing.T) *Compiler {
c, err := NewCompiler()
if err != nil {
t.Fatal(err)
}
c.SetIncludeCallback(func(name, rulefile, namespace string) []byte {
t.Logf(`Processing include "%s" (from ns="%s", file="%s")`, name, namespace, rulefile)
if name == "existing" {
return []byte(`rule ext { condition: true }`)
}
return nil
})
return c
}
func TestCompilerIncludeCallback(t *testing.T) {
c := setupCompiler(t)
var err error
if err = c.AddString(`include "existing"`, ""); err != nil {
t.Fatalf(`Failed to include "existing" rule "file": %s`, err)
}
if err = c.AddString(`rule int { condition: ext }`, ""); err != nil {
t.Fatalf(`Failed to define rule referring to included rule: %s`, err)
}
c = setupCompiler(t)
if err = c.AddString(`include "non-existing"`, ""); err != nil {
t.Logf("Compiler returned error on attempt to include non-existing rule: %s", err)
} else {
t.Fatal(`Compiler did not return error on non-existing include rule`)
}
}