From bcf821b7b7ce1ab3bcc8a0c075cab18ec5971f9e Mon Sep 17 00:00:00 2001 From: Brooke Hatton Date: Wed, 23 Mar 2022 18:46:19 +0000 Subject: [PATCH] confirm correct writer is used --- print_test.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/print_test.go b/print_test.go index 79558e2ed..95bb00fb3 100644 --- a/print_test.go +++ b/print_test.go @@ -161,12 +161,24 @@ func TestFprint(t *testing.T) { pterm.Output = true for _, randomString := range internal.RandomStrings { out := captureStdout(func(w io.Writer) { + // set default to null to confirm that its correctly using the provided writer + pterm.SetDefaultOutput(nil) pterm.Fprint(w, randomString) }) testza.AssertEqual(t, randomString, out) } }) + t.Run("confirm defaults to default output when no writer provided", func(t *testing.T) { + pterm.Output = true + for _, randomString := range internal.RandomStrings { + out := captureStdout(func(w io.Writer) { + pterm.Fprint(nil, randomString) + }) + testza.AssertEqual(t, randomString, out) + } + }) + t.Run("disabled output", func(t *testing.T) { pterm.Output = false for _, randomString := range internal.RandomStrings { @@ -184,12 +196,24 @@ func TestFprintln(t *testing.T) { pterm.Output = true for _, randomString := range internal.RandomStrings { out := captureStdout(func(w io.Writer) { + // set default to null to confirm that its correctly using the provided writer + pterm.SetDefaultOutput(nil) pterm.Fprintln(w, randomString) }) testza.AssertEqual(t, randomString+"\n", out) } }) + t.Run("confirm defaults to default output when no writer provided", func(t *testing.T) { + pterm.Output = true + for _, randomString := range internal.RandomStrings { + out := captureStdout(func(w io.Writer) { + pterm.Fprintln(nil, randomString) + }) + testza.AssertEqual(t, randomString+"\n", out) + } + }) + t.Run("disabled output", func(t *testing.T) { pterm.Output = false for _, randomString := range internal.RandomStrings { @@ -230,12 +254,24 @@ func TestFprinto(t *testing.T) { pterm.Output = true for _, randomString := range internal.RandomStrings { out := captureStdout(func(w io.Writer) { + // set default to null to confirm that its correctly using the provided writer + pterm.SetDefaultOutput(nil) pterm.Fprinto(w, randomString) }) testza.AssertEqual(t, "\r"+randomString, out) } }) + t.Run("confirm defaults to default output when no writer provided", func(t *testing.T) { + pterm.Output = true + for _, randomString := range internal.RandomStrings { + out := captureStdout(func(w io.Writer) { + pterm.Fprinto(nil, randomString) + }) + testza.AssertEqual(t, "\r"+randomString, out) + } + }) + t.Run("disabled output", func(t *testing.T) { pterm.Output = false for _, randomString := range internal.RandomStrings {