mirror of
https://github.com/go-delve/delve.git
synced 2025-10-30 18:27:37 +08:00
tests: add missing test cleanup (#4163)
- Changes BuildFixture so that fixtures are not built multiple times - Add some missing calls to AddPathToRemove
This commit is contained in:
committed by
GitHub
parent
fa07b65188
commit
d44aa4b65a
@ -85,6 +85,7 @@ func stripAndCopyDebugInfo(f protest.Fixture, t *testing.T) {
|
|||||||
if err := copyCmd.Run(); err != nil {
|
if err := copyCmd.Run(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
protest.AddPathToRemove(f.Path + ".debug")
|
||||||
|
|
||||||
// Strip the original binary of the debug information.
|
// Strip the original binary of the debug information.
|
||||||
stripCmd := exec.Command("strip", "--strip-debug", "--strip-unneeded", name)
|
stripCmd := exec.Command("strip", "--strip-debug", "--strip-unneeded", name)
|
||||||
|
|||||||
@ -33,6 +33,8 @@ type Fixture struct {
|
|||||||
Source string
|
Source string
|
||||||
// BuildDir is the directory where the build command was run.
|
// BuildDir is the directory where the build command was run.
|
||||||
BuildDir string
|
BuildDir string
|
||||||
|
// buildDone is closed when the fixture is built
|
||||||
|
buildDone <-chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FixtureKey holds the name and builds flags used for a test fixture.
|
// FixtureKey holds the name and builds flags used for a test fixture.
|
||||||
@ -42,7 +44,7 @@ type fixtureKey struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fixtures is a map of fixtureKey{ Fixture.Name, buildFlags } to Fixture.
|
// Fixtures is a map of fixtureKey{ Fixture.Name, buildFlags } to Fixture.
|
||||||
var fixtures = make(map[fixtureKey]Fixture)
|
var fixtures = make(map[fixtureKey]*Fixture)
|
||||||
var fixturesmu sync.Mutex
|
var fixturesmu sync.Mutex
|
||||||
|
|
||||||
// pathsToRemove is a list of files and directories to remove after running all the tests
|
// pathsToRemove is a list of files and directories to remove after running all the tests
|
||||||
@ -105,9 +107,16 @@ func BuildFixture(t testing.TB, name string, flags BuildFlags) Fixture {
|
|||||||
panic("RunTestsWithFixtures not called")
|
panic("RunTestsWithFixtures not called")
|
||||||
}
|
}
|
||||||
fk := fixtureKey{name, flags}
|
fk := fixtureKey{name, flags}
|
||||||
|
fixturesmu.Lock()
|
||||||
if f, ok := fixtures[fk]; ok {
|
if f, ok := fixtures[fk]; ok {
|
||||||
return f
|
fixturesmu.Unlock()
|
||||||
|
<-f.buildDone
|
||||||
|
return *f
|
||||||
}
|
}
|
||||||
|
buildDone := make(chan struct{})
|
||||||
|
fixture := Fixture{Name: name, buildDone: buildDone}
|
||||||
|
fixtures[fk] = &fixture
|
||||||
|
fixturesmu.Unlock()
|
||||||
|
|
||||||
if flags&EnableCGOOptimization == 0 {
|
if flags&EnableCGOOptimization == 0 {
|
||||||
if os.Getenv("CI") == "" || os.Getenv("CGO_CFLAGS") == "" {
|
if os.Getenv("CI") == "" || os.Getenv("CGO_CFLAGS") == "" {
|
||||||
@ -190,6 +199,20 @@ func BuildFixture(t testing.TB, name string, flags BuildFlags) Fixture {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
source, _ := filepath.Abs(path)
|
||||||
|
source = filepath.ToSlash(source)
|
||||||
|
sympath, err := filepath.EvalSymlinks(source)
|
||||||
|
if err == nil {
|
||||||
|
source = strings.ReplaceAll(sympath, "\\", "/")
|
||||||
|
}
|
||||||
|
|
||||||
|
absdir, _ := filepath.Abs(dir)
|
||||||
|
|
||||||
|
fixture.Path = tmpfile
|
||||||
|
fixture.Source = source
|
||||||
|
fixture.BuildDir = absdir
|
||||||
|
close(buildDone)
|
||||||
|
|
||||||
if flags&EnableDWZCompression != 0 {
|
if flags&EnableDWZCompression != 0 {
|
||||||
cmd := exec.Command("dwz", tmpfile)
|
cmd := exec.Command("dwz", tmpfile)
|
||||||
if out, err := cmd.CombinedOutput(); err != nil {
|
if out, err := cmd.CombinedOutput(); err != nil {
|
||||||
@ -203,21 +226,7 @@ func BuildFixture(t testing.TB, name string, flags BuildFlags) Fixture {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
source, _ := filepath.Abs(path)
|
return fixture
|
||||||
source = filepath.ToSlash(source)
|
|
||||||
sympath, err := filepath.EvalSymlinks(source)
|
|
||||||
if err == nil {
|
|
||||||
source = strings.ReplaceAll(sympath, "\\", "/")
|
|
||||||
}
|
|
||||||
|
|
||||||
absdir, _ := filepath.Abs(dir)
|
|
||||||
|
|
||||||
fixture := Fixture{Name: name, Path: tmpfile, Source: source, BuildDir: absdir}
|
|
||||||
|
|
||||||
fixturesmu.Lock()
|
|
||||||
defer fixturesmu.Unlock()
|
|
||||||
fixtures[fk] = fixture
|
|
||||||
return fixtures[fk]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunTestsWithFixtures sets the flag runningWithFixtures to compile fixtures on demand and runs tests with m.Run().
|
// RunTestsWithFixtures sets the flag runningWithFixtures to compile fixtures on demand and runs tests with m.Run().
|
||||||
@ -484,6 +493,7 @@ func getDlvBinInternal(t *testing.T, goflags ...string) string {
|
|||||||
dlvbin := TempFile("dlv.exe")
|
dlvbin := TempFile("dlv.exe")
|
||||||
|
|
||||||
dlvbincache[strargs] = dlvbin
|
dlvbincache[strargs] = dlvbin
|
||||||
|
AddPathToRemove(dlvbin)
|
||||||
|
|
||||||
args := append([]string{"build", "-o", dlvbin}, goflags...)
|
args := append([]string{"build", "-o", dlvbin}, goflags...)
|
||||||
args = append(args, "github.com/go-delve/delve/cmd/dlv")
|
args = append(args, "github.com/go-delve/delve/cmd/dlv")
|
||||||
|
|||||||
@ -2825,6 +2825,7 @@ func TestNonGoDebug(t *testing.T) {
|
|||||||
if out, err := cmd.CombinedOutput(); err != nil {
|
if out, err := cmd.CombinedOutput(); err != nil {
|
||||||
t.Fatalf("Error compiling %s: %s\n%s", path, err, out)
|
t.Fatalf("Error compiling %s: %s\n%s", path, err, out)
|
||||||
}
|
}
|
||||||
|
protest.AddPathToRemove(path)
|
||||||
|
|
||||||
listener, clientConn := service.ListenerPipe()
|
listener, clientConn := service.ListenerPipe()
|
||||||
defer listener.Close()
|
defer listener.Close()
|
||||||
|
|||||||
Reference in New Issue
Block a user