From 13601bb4cf415d97d94e1ec655861012daf3c4a9 Mon Sep 17 00:00:00 2001 From: Robert Lin Date: Mon, 16 May 2022 22:59:18 -0700 Subject: [PATCH 1/2] command: add test for mixed output --- command_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/command_test.go b/command_test.go index abc690e..25a9415 100644 --- a/command_test.go +++ b/command_test.go @@ -72,6 +72,36 @@ func TestRunAndAggregate(t *testing.T) { c.Assert(err, qt.IsNil) c.Assert(string(res), qt.Equals, `"world"`) }) + + c.Run("mixed output", func(c *qt.C) { + const mixedOutputCmd = `>&2 echo "stderr" ; echo "stdout"` + + c.Run("stdout only", func(c *qt.C) { + res, err := run.Bash(ctx, mixedOutputCmd). + Run(). + StdOut(). + Lines() + c.Assert(err, qt.IsNil) + c.Assert(res, qt.CmpEquals(), []string{"stdout"}) + }) + + c.Run("stderr only", func(c *qt.C) { + res, err := run.Bash(ctx, mixedOutputCmd). + Run(). + StdErr(). + Lines() + c.Assert(err, qt.IsNil) + c.Assert(res, qt.CmpEquals(), []string{"stderr"}) + }) + + c.Run("combined", func(c *qt.C) { + res, err := run.Bash(ctx, mixedOutputCmd). + Run(). + Lines() + c.Assert(err, qt.IsNil) + c.Assert(res, qt.CmpEquals(), []string{"stderr", "stdout"}) + }) + }) } func TestInput(t *testing.T) { From d071c236e4cd527600bf55d90149d2354a35ba47 Mon Sep 17 00:00:00 2001 From: Robert Lin Date: Mon, 16 May 2022 23:17:52 -0700 Subject: [PATCH 2/2] what the heck --- command_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/command_test.go b/command_test.go index 25a9415..6a9f84b 100644 --- a/command_test.go +++ b/command_test.go @@ -74,7 +74,7 @@ func TestRunAndAggregate(t *testing.T) { }) c.Run("mixed output", func(c *qt.C) { - const mixedOutputCmd = `>&2 echo "stderr" ; echo "stdout"` + const mixedOutputCmd = `echo "stdout" ; sleep 0.001 ; >&2 echo "stderr"` c.Run("stdout only", func(c *qt.C) { res, err := run.Bash(ctx, mixedOutputCmd). @@ -99,7 +99,7 @@ func TestRunAndAggregate(t *testing.T) { Run(). Lines() c.Assert(err, qt.IsNil) - c.Assert(res, qt.CmpEquals(), []string{"stderr", "stdout"}) + c.Assert(res, qt.CmpEquals(), []string{"stdout", "stderr"}) }) }) }