mirror of
https://github.com/restic/restic.git
synced 2025-12-13 12:52:34 +00:00
fix capturing stdout with termstatus
This commit is contained in:
@@ -15,7 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func testRunDiffOutput(gopts GlobalOptions, firstSnapshotID string, secondSnapshotID string) (string, error) {
|
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{
|
opts := DiffOptions{
|
||||||
ShowMetadata: false,
|
ShowMetadata: false,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func testRunFind(t testing.TB, wantJSON bool, opts FindOptions, gopts GlobalOptions, pattern string) []byte {
|
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
|
gopts.JSON = wantJSON
|
||||||
|
|
||||||
return runFind(context.TODO(), opts, gopts, []string{pattern})
|
return runFind(context.TODO(), opts, gopts, []string{pattern})
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func testRunKeyListOtherIDs(t testing.TB, gopts GlobalOptions) []string {
|
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{})
|
return runKeyList(context.TODO(), gopts, []string{})
|
||||||
})
|
})
|
||||||
rtest.OK(t, err)
|
rtest.OK(t, err)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func testRunList(t testing.TB, gopts GlobalOptions, tpe string) restic.IDs {
|
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})
|
return runList(context.TODO(), gopts, []string{tpe})
|
||||||
})
|
})
|
||||||
rtest.OK(t, err)
|
rtest.OK(t, err)
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func testRunLsWithOpts(t testing.TB, gopts GlobalOptions, opts LsOptions, args []string) []byte {
|
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
|
gopts.Quiet = true
|
||||||
return runLs(context.TODO(), opts, gopts, args)
|
return runLs(context.TODO(), opts, gopts, args)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ func createPrunableRepo(t *testing.T, env *testEnvironment) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testRunForgetJSON(t testing.TB, gopts GlobalOptions, args ...string) {
|
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
|
gopts.JSON = true
|
||||||
opts := ForgetOptions{
|
opts := ForgetOptions{
|
||||||
DryRun: true,
|
DryRun: true,
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func testRunSnapshots(t testing.TB, gopts GlobalOptions) (newest *Snapshot, snapmap map[restic.ID]Snapshot) {
|
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
|
gopts.JSON = true
|
||||||
|
|
||||||
opts := SnapshotOptions{}
|
opts := SnapshotOptions{}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ func Test_PrintFunctionsRespectsGlobalStdout(t *testing.T) {
|
|||||||
func() { Print("message\n") },
|
func() { Print("message\n") },
|
||||||
func() { Printf("mes%s\n", "sage") },
|
func() { Printf("mes%s\n", "sage") },
|
||||||
} {
|
} {
|
||||||
buf, _ := withCaptureStdout(func() error {
|
buf, _ := withCaptureStdout(GlobalOptions{}, func(_ GlobalOptions) error {
|
||||||
p()
|
p()
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -406,11 +406,12 @@ func withRestoreGlobalOptions(inner func() error) error {
|
|||||||
return inner()
|
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)
|
buf := bytes.NewBuffer(nil)
|
||||||
err := withRestoreGlobalOptions(func() error {
|
err := withRestoreGlobalOptions(func() error {
|
||||||
globalOptions.stdout = buf
|
globalOptions.stdout = buf
|
||||||
return inner()
|
gopts.stdout = buf
|
||||||
|
return inner(gopts)
|
||||||
})
|
})
|
||||||
|
|
||||||
return buf, err
|
return buf, err
|
||||||
|
|||||||
Reference in New Issue
Block a user