Skip to content

Commit 84d2eb4

Browse files
committed
fix(cli): keep package diagnostics for interrupted tests
1 parent c38f285 commit 84d2eb4

3 files changed

Lines changed: 25 additions & 4 deletions

File tree

‎.github/workflows/test.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,16 +229,16 @@ jobs:
229229
- name: Test
230230
env:
231231
GOTRACEBACK: crash
232-
run: go tool nsgo test ./internal/platform/apple -- -skip '^TestASoundDecodesOnceAndPlaysOverlapping$'
232+
run: go tool nsgo test -ldflags '-s=false -w=false' ./internal/platform/apple -- -count=1
233233
- name: Test widget and Live Activity recording
234234
run: go tool nsgo test -run '^(TestWidgetTimelines|TestLiveActivityRecords|TestUnavailableWidgetServices)$' ./nsgotest
235-
# Each run is a fresh process with Go symbols and a 30-second timeout, so a native fault or a CoreAudio stall leaves a traceback and a crash report (#801).
235+
# Load AuthenticationServices before playback, as in the failed suite (#801).
236236
- name: Stress overlapping sound playback in fresh processes
237237
env:
238238
GOTRACEBACK: crash
239239
run: |
240240
for i in $(seq 1 200); do
241-
go tool nsgo test -ldflags '-s=false -w=false' -run '^TestASoundDecodesOnceAndPlaysOverlapping$' \
241+
go tool nsgo test -ldflags '-s=false -w=false' -run '^(TestAuthenticationServicesLoads|TestASoundDecodesOnceAndPlaysOverlapping)$' \
242242
./internal/platform/apple -- -count=1 -timeout=30s || { echo "run $i failed"; exit 1; }
243243
done
244244
- name: Test main-thread failure propagation

‎cmd/nsgo/test.go‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,9 @@ func (r *testRun) event(ev testEvent) {
526526
}
527527
}
528528

529-
// interrupted ends the tests of pkg still running when its process ended, as a panic on another goroutine or a timeout ends it, with no closing event for the tests it cut short. Each fails with its output, which holds the panic and stack the package's output does not; a benchmark, which ends with no event of its own, hands its output to the package's.
529+
// interrupted fails the tests still running when pkg's process ends without
530+
// their closing events, as after a panic or timeout. Each shows its own output.
531+
// A benchmark hands its output to the package because it has no closing event.
530532
func (r *testRun) interrupted(pkg string) {
531533
var keys []string
532534
for key, t := range r.running {
@@ -546,6 +548,21 @@ func (r *testRun) interrupted(pkg string) {
546548
r.results = append(r.results, t)
547549
r.print(t)
548550
}
551+
// finish skips package output when a failed test already explains the failure.
552+
// An interrupted test can leave diagnostic lines attached to the package.
553+
if len(keys) > 0 && r.anyFailed(pkg) {
554+
var diagnostics strings.Builder
555+
for line := range strings.SplitSeq(r.packages[pkg].Output, "\n") {
556+
if line == "" || goTestLine(line) || strings.HasPrefix(line, "FAIL\t") {
557+
continue
558+
}
559+
diagnostics.WriteString(line)
560+
diagnostics.WriteByte('\n')
561+
}
562+
if diagnostics.Len() > 0 {
563+
fmt.Fprintf(r.out, "%s %s\n%s", margin, pkg, indent(diagnostics.String()))
564+
}
565+
}
549566
}
550567

551568
// benchmark reports each result line a benchmark has printed whole as a

‎cmd/nsgo/test_test.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ func TestInterruptedTestsKeepTheirOutput(t *testing.T) {
552552
{"Action":"run","Package":"p","Test":"TestCrash"}
553553
{"Action":"run","Package":"q","Test":"TestOther"}
554554
{"Action":"output","Package":"p","Test":"TestCrash","Output":"panic: native callback failed\nstack trace\n"}
555+
{"Action":"output","Package":"p","Output":"native crash reported by the test process\n"}
555556
{"Action":"output","Package":"p","Output":"FAIL\tp\t0.1s\n"}
556557
{"Action":"fail","Package":"p","Elapsed":0.1}
557558
{"Action":"pass","Package":"q","Test":"TestOther","Elapsed":0.2}
@@ -566,6 +567,9 @@ func TestInterruptedTestsKeepTheirOutput(t *testing.T) {
566567
t.Errorf("console misses %q:\n%s", want, out.String())
567568
}
568569
}
570+
if got := strings.Count(out.String(), "native crash reported by the test process"); got != 1 {
571+
t.Errorf("console shows the package diagnostic %d times:\n%s", got, out.String())
572+
}
569573
if len(r.running) != 0 {
570574
t.Errorf("unfinished tests = %v", r.running)
571575
}

0 commit comments

Comments
 (0)