fix capturing stdout with termstatus

This commit is contained in:
Michael Eischer
2025-09-14 13:51:30 +02:00
parent 91ecac8003
commit ef9930cce4
9 changed files with 11 additions and 10 deletions

View File

@@ -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,
}

View File

@@ -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})

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)
})

View File

@@ -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,

View File

@@ -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{}

View File

@@ -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
})

View File

@@ -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