mirror of
https://github.com/go-task/task.git
synced 2025-08-10 22:42:19 +02:00
refactor: use require for testing errors (#1100)
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/go-task/task/v3/internal/output"
|
||||
"github.com/go-task/task/v3/internal/templater"
|
||||
@@ -39,7 +40,7 @@ func TestGroup(t *testing.T) {
|
||||
fmt.Fprintln(stdErr, "err")
|
||||
assert.Equal(t, "", b.String())
|
||||
|
||||
assert.NoError(t, cleanup(nil))
|
||||
require.NoError(t, cleanup(nil))
|
||||
assert.Equal(t, "out\nout\nerr\nerr\nout\nerr\n", b.String())
|
||||
}
|
||||
|
||||
@@ -65,13 +66,13 @@ func TestGroupWithBeginEnd(t *testing.T) {
|
||||
assert.Equal(t, "", b.String())
|
||||
fmt.Fprintln(w, "baz")
|
||||
assert.Equal(t, "", b.String())
|
||||
assert.NoError(t, cleanup(nil))
|
||||
require.NoError(t, cleanup(nil))
|
||||
assert.Equal(t, "::group::example-value\nfoo\nbar\nbaz\n::endgroup::\n", b.String())
|
||||
})
|
||||
t.Run("no output", func(t *testing.T) {
|
||||
var b bytes.Buffer
|
||||
_, _, cleanup := o.WrapWriter(&b, io.Discard, "", &tmpl)
|
||||
assert.NoError(t, cleanup(nil))
|
||||
require.NoError(t, cleanup(nil))
|
||||
assert.Equal(t, "", b.String())
|
||||
})
|
||||
}
|
||||
@@ -86,7 +87,7 @@ func TestGroupErrorOnlySwallowsOutputOnNoError(t *testing.T) {
|
||||
_, _ = fmt.Fprintln(stdOut, "std-out")
|
||||
_, _ = fmt.Fprintln(stdErr, "std-err")
|
||||
|
||||
assert.NoError(t, cleanup(nil))
|
||||
require.NoError(t, cleanup(nil))
|
||||
assert.Empty(t, b.String())
|
||||
}
|
||||
|
||||
@@ -100,7 +101,7 @@ func TestGroupErrorOnlyShowsOutputOnError(t *testing.T) {
|
||||
_, _ = fmt.Fprintln(stdOut, "std-out")
|
||||
_, _ = fmt.Fprintln(stdErr, "std-err")
|
||||
|
||||
assert.NoError(t, cleanup(errors.New("any-error")))
|
||||
require.NoError(t, cleanup(errors.New("any-error")))
|
||||
assert.Equal(t, "std-out\nstd-err\n", b.String())
|
||||
}
|
||||
|
||||
@@ -116,7 +117,7 @@ func TestPrefixed(t *testing.T) {
|
||||
assert.Equal(t, "[prefix] foo\n[prefix] bar\n", b.String())
|
||||
fmt.Fprintln(w, "baz")
|
||||
assert.Equal(t, "[prefix] foo\n[prefix] bar\n[prefix] baz\n", b.String())
|
||||
assert.NoError(t, cleanup(nil))
|
||||
require.NoError(t, cleanup(nil))
|
||||
})
|
||||
|
||||
t.Run("multiple writes for a single line", func(t *testing.T) {
|
||||
@@ -127,7 +128,7 @@ func TestPrefixed(t *testing.T) {
|
||||
assert.Equal(t, "", b.String())
|
||||
}
|
||||
|
||||
assert.NoError(t, cleanup(nil))
|
||||
require.NoError(t, cleanup(nil))
|
||||
assert.Equal(t, "[prefix] Test!\n", b.String())
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user