From ef9930cce48fd95e8af45f45a7c1e782cef84bbf Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sun, 14 Sep 2025 13:51:30 +0200 Subject: [PATCH] fix capturing stdout with termstatus --- cmd/restic/cmd_diff_integration_test.go | 2 +- cmd/restic/cmd_find_integration_test.go | 2 +- cmd/restic/cmd_key_integration_test.go | 2 +- cmd/restic/cmd_list_integration_test.go | 2 +- cmd/restic/cmd_ls_integration_test.go | 2 +- cmd/restic/cmd_prune_integration_test.go | 2 +- cmd/restic/cmd_snapshots_integration_test.go | 2 +- cmd/restic/global_test.go | 2 +- cmd/restic/integration_helpers_test.go | 5 +++-- 9 files changed, 11 insertions(+), 10 deletions(-) diff --git a/cmd/restic/cmd_diff_integration_test.go b/cmd/restic/cmd_diff_integration_test.go index 8782053ed..80cd500e2 100644 --- a/cmd/restic/cmd_diff_integration_test.go +++ b/cmd/restic/cmd_diff_integration_test.go @@ -15,7 +15,7 @@ import ( ) func testRunDiffOutput(gopts GlobalOptions, firstSnapshotID string, secondSnapshotID string) (string, error) { - buf, err := withCaptureStdout(func() error { + buf, err := withCaptureStdout(gopts, func(gopts GlobalOptions) error { opts := DiffOptions{ ShowMetadata: false, } diff --git a/cmd/restic/cmd_find_integration_test.go b/cmd/restic/cmd_find_integration_test.go index 95799749a..b45eae9bc 100644 --- a/cmd/restic/cmd_find_integration_test.go +++ b/cmd/restic/cmd_find_integration_test.go @@ -11,7 +11,7 @@ import ( ) func testRunFind(t testing.TB, wantJSON bool, opts FindOptions, gopts GlobalOptions, pattern string) []byte { - buf, err := withCaptureStdout(func() error { + buf, err := withCaptureStdout(gopts, func(gopts GlobalOptions) error { gopts.JSON = wantJSON return runFind(context.TODO(), opts, gopts, []string{pattern}) diff --git a/cmd/restic/cmd_key_integration_test.go b/cmd/restic/cmd_key_integration_test.go index 0b4533887..8a6b2707f 100644 --- a/cmd/restic/cmd_key_integration_test.go +++ b/cmd/restic/cmd_key_integration_test.go @@ -15,7 +15,7 @@ import ( ) func testRunKeyListOtherIDs(t testing.TB, gopts GlobalOptions) []string { - buf, err := withCaptureStdout(func() error { + buf, err := withCaptureStdout(gopts, func(gopts GlobalOptions) error { return runKeyList(context.TODO(), gopts, []string{}) }) rtest.OK(t, err) diff --git a/cmd/restic/cmd_list_integration_test.go b/cmd/restic/cmd_list_integration_test.go index 0257a13f1..6a32b763b 100644 --- a/cmd/restic/cmd_list_integration_test.go +++ b/cmd/restic/cmd_list_integration_test.go @@ -11,7 +11,7 @@ import ( ) func testRunList(t testing.TB, gopts GlobalOptions, tpe string) restic.IDs { - buf, err := withCaptureStdout(func() error { + buf, err := withCaptureStdout(gopts, func(gopts GlobalOptions) error { return runList(context.TODO(), gopts, []string{tpe}) }) rtest.OK(t, err) diff --git a/cmd/restic/cmd_ls_integration_test.go b/cmd/restic/cmd_ls_integration_test.go index f72a4533a..acbaa9d22 100644 --- a/cmd/restic/cmd_ls_integration_test.go +++ b/cmd/restic/cmd_ls_integration_test.go @@ -13,7 +13,7 @@ import ( ) func testRunLsWithOpts(t testing.TB, gopts GlobalOptions, opts LsOptions, args []string) []byte { - buf, err := withCaptureStdout(func() error { + buf, err := withCaptureStdout(gopts, func(gopts GlobalOptions) error { gopts.Quiet = true return runLs(context.TODO(), opts, gopts, args) }) diff --git a/cmd/restic/cmd_prune_integration_test.go b/cmd/restic/cmd_prune_integration_test.go index 9de2e0b8d..007304921 100644 --- a/cmd/restic/cmd_prune_integration_test.go +++ b/cmd/restic/cmd_prune_integration_test.go @@ -90,7 +90,7 @@ func createPrunableRepo(t *testing.T, env *testEnvironment) { } func testRunForgetJSON(t testing.TB, gopts GlobalOptions, args ...string) { - buf, err := withCaptureStdout(func() error { + buf, err := withCaptureStdout(gopts, func(gopts GlobalOptions) error { gopts.JSON = true opts := ForgetOptions{ DryRun: true, diff --git a/cmd/restic/cmd_snapshots_integration_test.go b/cmd/restic/cmd_snapshots_integration_test.go index 6eaa8faa4..77d7d1dff 100644 --- a/cmd/restic/cmd_snapshots_integration_test.go +++ b/cmd/restic/cmd_snapshots_integration_test.go @@ -10,7 +10,7 @@ import ( ) func testRunSnapshots(t testing.TB, gopts GlobalOptions) (newest *Snapshot, snapmap map[restic.ID]Snapshot) { - buf, err := withCaptureStdout(func() error { + buf, err := withCaptureStdout(gopts, func(gopts GlobalOptions) error { gopts.JSON = true opts := SnapshotOptions{} diff --git a/cmd/restic/global_test.go b/cmd/restic/global_test.go index 8e97ece29..884476614 100644 --- a/cmd/restic/global_test.go +++ b/cmd/restic/global_test.go @@ -17,7 +17,7 @@ func Test_PrintFunctionsRespectsGlobalStdout(t *testing.T) { func() { Print("message\n") }, func() { Printf("mes%s\n", "sage") }, } { - buf, _ := withCaptureStdout(func() error { + buf, _ := withCaptureStdout(GlobalOptions{}, func(_ GlobalOptions) error { p() return nil }) diff --git a/cmd/restic/integration_helpers_test.go b/cmd/restic/integration_helpers_test.go index 71556e55f..c265272e9 100644 --- a/cmd/restic/integration_helpers_test.go +++ b/cmd/restic/integration_helpers_test.go @@ -406,11 +406,12 @@ func withRestoreGlobalOptions(inner func() error) error { return inner() } -func withCaptureStdout(inner func() error) (*bytes.Buffer, error) { +func withCaptureStdout(gopts GlobalOptions, inner func(gopts GlobalOptions) error) (*bytes.Buffer, error) { buf := bytes.NewBuffer(nil) err := withRestoreGlobalOptions(func() error { globalOptions.stdout = buf - return inner() + gopts.stdout = buf + return inner(gopts) }) return buf, err