package yara

import (
	"os"
	"testing"
)

func TestMain(m *testing.M) {
	if r, err := Compile(`rule test : tag1 { meta: author = "Hilko Bengen" strings: $a = "abc" fullword condition: $a }`, nil); err != nil {
		os.Exit(1)
	} else if err = r.Save("testrules.yac"); err != nil {
		os.Exit(1)
	}
	rc := m.Run()
	os.Remove("testrules.yac")
	os.Exit(rc)
}

package yara

import (
	"io/ioutil"
	"log"
	"os"
	"testing"
)

var compiledTestRulesPath string

func TestMain(m *testing.M) {
	r, err := Compile(`rule test : tag1 { meta: author = "Hilko Bengen" strings: $a = "abc" fullword condition: $a }`, nil)
	if err != nil {
		log.Fatalf("Compile: %v", err)
	}

	f, err := ioutil.TempFile("", "testrules.yac")
	if err != nil {
		log.Fatalf("ioutil.TempFile: %v", err)
	}
	compiledTestRulesPath = f.Name()

	if err := r.Save(compiledTestRulesPath); err != nil {
		os.Remove(compiledTestRulesPath)
		log.Fatalf("Save(%q): %v", compiledTestRulesPath, err)
	}

	rc := m.Run()
	os.Remove(compiledTestRulesPath)
	os.Exit(rc)
}

Update tests to use a writable temp directory
Update tests to use a writable temp directory

Ensure that when compiling the sample rule, it's stored in a writable temp directory.