1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-08-08 22:36:49 +02:00

Provide a simple way to debug an integration test

This commit is contained in:
Stefan Haller
2023-09-09 15:00:58 +02:00
parent 28d12e4e5d
commit b6c892a08a
22 changed files with 975 additions and 12 deletions

View File

@ -3,12 +3,14 @@ package main
import (
"fmt"
"os"
"time"
"github.com/jesseduffield/lazygit/pkg/app"
"github.com/jesseduffield/lazygit/pkg/app/daemon"
"github.com/jesseduffield/lazygit/pkg/integration/components"
"github.com/jesseduffield/lazygit/pkg/integration/tests"
integrationTypes "github.com/jesseduffield/lazygit/pkg/integration/types"
"github.com/mitchellh/go-ps"
)
// The purpose of this program is to run lazygit with an integration test passed in.
@ -29,6 +31,15 @@ func main() {
integrationTest := getIntegrationTest()
if os.Getenv("WAIT_FOR_DEBUGGER") != "" {
println("Waiting for debugger to attach...")
for !isDebuggerAttached() {
time.Sleep(time.Millisecond * 100)
}
println("Debugger attached, continuing")
}
app.Start(dummyBuildInfo, integrationTest)
}
@ -56,3 +67,21 @@ func getIntegrationTest() integrationTypes.IntegrationTest {
panic("Could not find integration test with name: " + integrationTestName)
}
// Returns whether we are running under a debugger. It uses a heuristic to find
// out: when using dlv, it starts a debugserver executable (which is part of
// lldb), and the debuggee becomes a child process of that. So if the name of
// our parent process is "debugserver", we run under a debugger. This works even
// if the parent process used to be the shell and you then attach to the running
// executable.
//
// On Mac this works with VS Code, with the Jetbrains Goland IDE, and when using
// dlv attach in a terminal. I have not been able to verify that it works on
// other platforms, it may have to be adapted there.
func isDebuggerAttached() bool {
process, err := ps.FindProcess(os.Getppid())
if err != nil {
return false
}
return process.Executable() == "debugserver"
}