Rebuild binaries for every test

This commit is contained in:
Derek Parker
2014-09-12 15:19:36 -05:00
parent 2fa307f7c7
commit 9c298036b9
4 changed files with 55 additions and 31 deletions

View File

@ -3,6 +3,7 @@ package line
import (
"debug/elf"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
@ -10,12 +11,7 @@ import (
"github.com/davecheney/profile"
)
func grabDebugLineSection(fp string, t *testing.T) []byte {
p, err := filepath.Abs(fp)
if err != nil {
t.Fatal(err)
}
func grabDebugLineSection(p string, t *testing.T) []byte {
f, err := os.Open(p)
if err != nil {
t.Fatal(err)
@ -36,24 +32,24 @@ func grabDebugLineSection(fp string, t *testing.T) []byte {
func TestDebugLinePrologueParser(t *testing.T) {
// Test against known good values, from readelf --debug-dump=rawline _fixtures/testnextprog
var (
data = grabDebugLineSection("../../_fixtures/testnextprog", t)
dbl = Parse(data)
prologue = dbl.Prologue
)
if prologue.Length != uint32(60685) {
t.Fatal("Length was not parsed correctly", prologue.Length)
p, err := filepath.Abs("../../_fixtures/testnextprog")
if err != nil {
t.Fatal(err)
}
err = exec.Command("go", "build", "-gcflags=-N -l", "-o", p, p+".go").Run()
if err != nil {
t.Fatal("Could not compile test file", p, err)
}
defer os.Remove(p)
data := grabDebugLineSection(p, t)
dbl := Parse(data)
prologue := dbl.Prologue
if prologue.Version != uint16(2) {
t.Fatal("Version not parsed correctly", prologue.Version)
}
if prologue.PrologueLength != uint32(5363) {
t.Fatal("Prologue Length not parsed correctly", prologue.PrologueLength)
}
if prologue.MinInstrLength != uint8(1) {
t.Fatal("Minimun Instruction Length not parsed correctly", prologue.MinInstrLength)
}
@ -85,10 +81,6 @@ func TestDebugLinePrologueParser(t *testing.T) {
t.Fatal("Include dirs not parsed correctly")
}
if len(dbl.FileNames) != 126 {
t.Fatal("Filenames not parsed correctly", len(dbl.FileNames))
}
if !strings.Contains(dbl.FileNames[0].Name, "/dbg/_fixtures/testnextprog.go") {
t.Fatal("First entry not parsed correctly")
}
@ -96,7 +88,12 @@ func TestDebugLinePrologueParser(t *testing.T) {
func BenchmarkLineParser(b *testing.B) {
defer profile.Start(profile.MemProfile).Stop()
data := grabDebugLineSection("../../_fixtures/testnextprog", nil)
p, err := filepath.Abs("../../_fixtures/testnextprog")
if err != nil {
b.Fatal(err)
}
data := grabDebugLineSection(p, nil)
b.ResetTimer()
for i := 0; i < b.N; i++ {