mirror of
https://github.com/restic/restic.git
synced 2025-12-11 18:21:54 +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) {
|
||||
buf, err := withCaptureStdout(func() error {
|
||||
buf, err := withCaptureStdout(gopts, func(gopts GlobalOptions) error {
|
||||
opts := DiffOptions{
|
||||
ShowMetadata: false,
|
||||
}
|
||||
|
||||
@@ -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})
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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{}
|
||||
|
||||
@@ -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
|
||||
})
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user