skip --update when output has "$ " lines; fix wait
This commit is contained in:
parent
064e817d9b
commit
6df26b90ac
18
cmd.go
18
cmd.go
|
|
@ -178,11 +178,29 @@ func testCmd() *cobra.Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
if update && len(fileOwnResults) > 0 {
|
if update && len(fileOwnResults) > 0 {
|
||||||
|
// Refuse to write if actual output contains "$ " lines —
|
||||||
|
// they'd be misparsed as commands on the next read.
|
||||||
|
hasConflict := false
|
||||||
|
for _, r := range fileOwnResults {
|
||||||
|
for _, line := range r.Actual {
|
||||||
|
if strings.HasPrefix(line, "$ ") {
|
||||||
|
hasConflict = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if hasConflict {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if hasConflict {
|
||||||
|
fmt.Fprintf(os.Stderr, "warning: %s: skipping --update because output contains lines starting with '$ '\n", parsed.Path)
|
||||||
|
} else {
|
||||||
updated := rewriteFile(parsed, fileOwnResults, string(content))
|
updated := rewriteFile(parsed, fileOwnResults, string(content))
|
||||||
if updated != string(content) {
|
if updated != string(content) {
|
||||||
_ = os.WriteFile(filePath, []byte(updated), 0o644)
|
_ = os.WriteFile(filePath, []byte(updated), 0o644)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if keep {
|
if keep {
|
||||||
fmt.Fprintln(os.Stderr, fileResult.TmpDir)
|
fmt.Fprintln(os.Stderr, fileResult.TmpDir)
|
||||||
|
|
|
||||||
10
run.go
10
run.go
|
|
@ -162,8 +162,9 @@ func runFile(file ShoutFile, opts RunOptions) FileResult {
|
||||||
return FileResult{File: file, TmpDir: tmpDir, Error: err.Error()}
|
return FileResult{File: file, TmpDir: tmpDir, Error: err.Error()}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var waited bool
|
||||||
defer func() {
|
defer func() {
|
||||||
if cmd.Process != nil {
|
if !waited && cmd.Process != nil {
|
||||||
_ = syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
|
_ = syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
@ -188,6 +189,11 @@ func runFile(file ShoutFile, opts RunOptions) FileResult {
|
||||||
select {
|
select {
|
||||||
case r := <-ch:
|
case r := <-ch:
|
||||||
if r.err != nil {
|
if r.err != nil {
|
||||||
|
if cmd.Process != nil {
|
||||||
|
_ = syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
|
||||||
|
}
|
||||||
|
_ = cmd.Wait()
|
||||||
|
waited = true
|
||||||
return FileResult{File: file, TmpDir: tmpDir, Error: r.err.Error()}
|
return FileResult{File: file, TmpDir: tmpDir, Error: r.err.Error()}
|
||||||
}
|
}
|
||||||
output = r.data
|
output = r.data
|
||||||
|
|
@ -197,10 +203,12 @@ func runFile(file ShoutFile, opts RunOptions) FileResult {
|
||||||
}
|
}
|
||||||
<-ch // drain the reader goroutine so pipe FDs are released
|
<-ch // drain the reader goroutine so pipe FDs are released
|
||||||
_ = cmd.Wait()
|
_ = cmd.Wait()
|
||||||
|
waited = true
|
||||||
return FileResult{File: file, TmpDir: tmpDir, Error: "Timeout reading output"}
|
return FileResult{File: file, TmpDir: tmpDir, Error: "Timeout reading output"}
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = cmd.Wait()
|
_ = cmd.Wait()
|
||||||
|
waited = true
|
||||||
|
|
||||||
outputs, exitCodesList := parseSentinelOutput(string(output), len(file.Commands), sentinel)
|
outputs, exitCodesList := parseSentinelOutput(string(output), len(file.Commands), sentinel)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,8 +79,6 @@ func rewriteFile(file ShoutFile, results []CommandResult, originalContent string
|
||||||
marker := updateExitCodeMarker(cmd, result.ExitCode)
|
marker := updateExitCodeMarker(cmd, result.ExitCode)
|
||||||
if marker != "" {
|
if marker != "" {
|
||||||
output = append(output, marker)
|
output = append(output, marker)
|
||||||
} else if len(content) > 0 && exitCodeMarkerRe.MatchString(content[len(content)-1]) {
|
|
||||||
output = append(output, "[0]")
|
|
||||||
}
|
}
|
||||||
for k := 0; k < rawTrailing; k++ {
|
for k := 0; k < rawTrailing; k++ {
|
||||||
output = append(output, "")
|
output = append(output, "")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user