-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.go
More file actions
52 lines (43 loc) · 1.01 KB
/
debug.go
File metadata and controls
52 lines (43 loc) · 1.01 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"fmt"
"os"
"os/exec"
)
func debugTest(t Test, path, modRoot string) (exec.Cmd, bool) {
p, err := exec.LookPath("dlv")
if err != nil {
panic(err)
}
// Create a temp file to set breakpoints and tell dlv to continue.
tempFile, err := os.CreateTemp("", "go-test_*")
if err != nil {
panic(err)
}
// Attempt cleanup when no longer in use.
defer func() {
err = os.Remove(tempFile.Name())
if err != nil {
panic(err)
}
}()
tempFile.Write([]byte("b " + fmt.Sprintf("%s:%d", packageFromPathAndMod(t.FilePath, modRoot), t.LineNumber) + "\n"))
tempFile.Write([]byte("c\n"))
tempFile.Close()
args := []string{"dlv", "test", "--init", tempFile.Name(), resolvePackage(modRoot, path), "--", "-test.run", t.Name}
fmt.Println("Running test with debugger:", args)
cmd := exec.Cmd{
Path: p,
Env: os.Environ(),
Args: args,
Dir: modRoot,
Stdin: os.Stdin,
Stdout: os.Stdout,
Stderr: os.Stderr,
}
err = cmd.Run()
if err != nil {
panic(err)
}
return cmd, true
}