1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-03-17 21:18:31 +02:00

Print race detector logs after running a test with -race

This commit is contained in:
Stefan Haller 2023-09-09 13:41:26 +02:00
parent f108fd2236
commit 59cc6843e6
3 changed files with 22 additions and 13 deletions

View File

@ -88,12 +88,15 @@ outer:
return testsToRun
}
func runCmdInTerminal(cmd *exec.Cmd) error {
func runCmdInTerminal(cmd *exec.Cmd) (int, error) {
cmd.Stdout = os.Stdout
cmd.Stdin = os.Stdin
cmd.Stderr = os.Stderr
return cmd.Run()
if err := cmd.Start(); err != nil {
return -1, err
}
return cmd.Process.Pid, cmd.Wait()
}
func tryConvert(numStr string, defaultVal int) int {

View File

@ -63,7 +63,7 @@ func TestIntegration(t *testing.T) {
assert.NoError(t, err)
}
func runCmdHeadless(cmd *exec.Cmd) error {
func runCmdHeadless(cmd *exec.Cmd) (int, error) {
cmd.Env = append(
cmd.Env,
"HEADLESS=true",
@ -81,7 +81,7 @@ func runCmdHeadless(cmd *exec.Cmd) error {
// running other commands in a pty.
f, err := pty.StartWithSize(cmd, &pty.Winsize{Rows: 300, Cols: 300})
if err != nil {
return err
return -1, err
}
_, _ = io.Copy(io.Discard, f)
@ -89,8 +89,8 @@ func runCmdHeadless(cmd *exec.Cmd) error {
if cmd.Wait() != nil {
_ = f.Close()
// return an error with the stderr output
return errors.New(stderr.String())
return cmd.Process.Pid, errors.New(stderr.String())
}
return f.Close()
return cmd.Process.Pid, f.Close()
}

View File

@ -26,7 +26,7 @@ const (
func RunTests(
tests []*IntegrationTest,
logf func(format string, formatArgs ...interface{}),
runCmd func(cmd *exec.Cmd) error,
runCmd func(cmd *exec.Cmd) (int, error),
testWrapper func(test *IntegrationTest, f func() error),
sandbox bool,
waitForDebugger bool,
@ -60,7 +60,7 @@ func RunTests(
)
for i := 0; i < maxAttempts; i++ {
err := runTest(test, paths, projectRootDir, logf, runCmd, sandbox, waitForDebugger, inputDelay, gitVersion)
err := runTest(test, paths, projectRootDir, logf, runCmd, sandbox, waitForDebugger, raceDetector, inputDelay, gitVersion)
if err != nil {
if i == maxAttempts-1 {
return err
@ -83,9 +83,10 @@ func runTest(
paths Paths,
projectRootDir string,
logf func(format string, formatArgs ...interface{}),
runCmd func(cmd *exec.Cmd) error,
runCmd func(cmd *exec.Cmd) (int, error),
sandbox bool,
waitForDebugger bool,
raceDetector bool,
inputDelay int,
gitVersion *git_commands.GitVersion,
) error {
@ -108,12 +109,17 @@ func runTest(
return err
}
err = runCmd(cmd)
if err != nil {
return err
pid, err := runCmd(cmd)
// Print race detector log regardless of the command's exit status
if raceDetector {
logPath := fmt.Sprintf("%s.%d", raceDetectorLogsPath(), pid)
if bytes, err := os.ReadFile(logPath); err == nil {
logf("Race detector log:\n" + string(bytes))
}
}
return nil
return err
}
func prepareTestDir(