test(oracle): report oracle dump write errors
The transcript dump now reports Flush and Close errors at the end of each scenario instead of discarding them, which golangci-lint's errcheck flagged.
- commit
- 1e6ecdbaf24da935633f33b601209754c954e7c1
- author
- brice · · 2026-10-02 17:54 UTC
- parent
- 1315cb1
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email - refs
- perf/html-runs
1 file · +8 -6
M oracle_test.go +8 -6
| @@ -5,6 +5,7 @@ import ( | |||
| 5 | 5 | "bytes" | |
| 6 | 6 | "crypto/sha256" | |
| 7 | 7 | "encoding/hex" | |
| 8 | + | "errors" | |
| 8 | 9 | "flag" | |
| 9 | 10 | "fmt" | |
| 10 | 11 | "hash" | |
| @@ -99,10 +100,8 @@ func (o *oracleRun) emit(concern, format string, args ...any) { | |||
| 99 | 100 | h.Write([]byte(line)) | |
| 100 | 101 | h.Write([]byte{'\n'}) | |
| 101 | 102 | if o.dump != nil { | |
| 102 | - | o.dump.WriteString(concern) | |
| 103 | - | o.dump.WriteString(": ") | |
| 104 | - | o.dump.WriteString(line) | |
| 105 | - | o.dump.WriteByte('\n') | |
| 103 | + | // bufio.Writer keeps the first error; the deferred Flush reports it. | |
| 104 | + | _, _ = fmt.Fprintf(o.dump, "%s: %s\n", concern, line) | |
| 106 | 105 | } | |
| 107 | 106 | } | |
| 108 | 107 | ||
| @@ -529,9 +528,12 @@ func runOracleScenario(t *testing.T, idx int) string { | |||
| 529 | 528 | if err != nil { | |
| 530 | 529 | t.Fatal(err) | |
| 531 | 530 | } | |
| 532 | - | defer f.Close() | |
| 533 | 531 | o.dump = bufio.NewWriter(f) | |
| 534 | - | defer o.dump.Flush() | |
| 532 | + | defer func() { | |
| 533 | + | if err := errors.Join(o.dump.Flush(), f.Close()); err != nil { | |
| 534 | + | t.Errorf("write oracle dump: %v", err) | |
| 535 | + | } | |
| 536 | + | }() | |
| 535 | 537 | } | |
| 536 | 538 | if sc.history != nil { | |
| 537 | 539 | o.screen = vt.NewScreenWithHistory(sc.cols, sc.rows, *sc.history) | |
| @@ -5,6 +5,7 @@ import ( | |||||
| 5 | "bytes" | 5 | "bytes" | ||
| 6 | "crypto/sha256" | 6 | "crypto/sha256" | ||
| 7 | "encoding/hex" | 7 | "encoding/hex" | ||
| 8 | + | "errors" | |||
| 8 | "flag" | 9 | "flag" | ||
| 9 | "fmt" | 10 | "fmt" | ||
| 10 | "hash" | 11 | "hash" | ||
| @@ -99,10 +100,8 @@ func (o *oracleRun) emit(concern, format string, args ...any) { | |||||
| 99 | h.Write([]byte(line)) | 100 | h.Write([]byte(line)) | ||
| 100 | h.Write([]byte{'\n'}) | 101 | h.Write([]byte{'\n'}) | ||
| 101 | if o.dump != nil { | 102 | if o.dump != nil { | ||
| 102 | - | o.dump.WriteString(concern) | 103 | + | // bufio.Writer keeps the first error; the deferred Flush reports it. |
| 103 | - | o.dump.WriteString(": ") | 104 | + | _, _ = fmt.Fprintf(o.dump, "%s: %s\n", concern, line) |
| 104 | - | o.dump.WriteString(line) | |||
| 105 | - | o.dump.WriteByte('\n') | |||
| 106 | } | 105 | } | ||
| 107 | } | 106 | } | ||
| 108 | 107 | ||||
| @@ -529,9 +528,12 @@ func runOracleScenario(t *testing.T, idx int) string { | |||||
| 529 | if err != nil { | 528 | if err != nil { | ||
| 530 | t.Fatal(err) | 529 | t.Fatal(err) | ||
| 531 | } | 530 | } | ||
| 532 | - | defer f.Close() | |||
| 533 | o.dump = bufio.NewWriter(f) | 531 | o.dump = bufio.NewWriter(f) | ||
| 534 | - | defer o.dump.Flush() | 532 | + | defer func() { |
| 533 | + | if err := errors.Join(o.dump.Flush(), f.Close()); err != nil { | |||
| 534 | + | t.Errorf("write oracle dump: %v", err) | |||
| 535 | + | } | |||
| 536 | + | }() | |||
| 535 | } | 537 | } | ||
| 536 | if sc.history != nil { | 538 | if sc.history != nil { | ||
| 537 | o.screen = vt.NewScreenWithHistory(sc.cols, sc.rows, *sc.history) | 539 | o.screen = vt.NewScreenWithHistory(sc.cols, sc.rows, *sc.history) | ||