2019-05-17 22:13:47 +02:00
|
|
|
package taskfile_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2023-04-06 12:18:41 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
2020-03-28 16:27:49 +02:00
|
|
|
"gopkg.in/yaml.v3"
|
2021-01-07 16:48:33 +02:00
|
|
|
|
|
|
|
"github.com/go-task/task/v3/taskfile"
|
2019-05-17 22:13:47 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestPreconditionParse(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
content string
|
2023-03-30 22:03:59 +02:00
|
|
|
v any
|
|
|
|
expected any
|
2019-05-17 22:13:47 +02:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
"test -f foo.txt",
|
|
|
|
&taskfile.Precondition{},
|
2019-05-28 22:02:59 +02:00
|
|
|
&taskfile.Precondition{Sh: `test -f foo.txt`, Msg: "`test -f foo.txt` failed"},
|
2019-05-17 22:13:47 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"sh: '[ 1 = 0 ]'",
|
|
|
|
&taskfile.Precondition{},
|
2019-05-28 22:02:59 +02:00
|
|
|
&taskfile.Precondition{Sh: "[ 1 = 0 ]", Msg: "[ 1 = 0 ] failed"},
|
2019-05-17 22:13:47 +02:00
|
|
|
},
|
2023-03-31 21:13:29 +02:00
|
|
|
{
|
|
|
|
`
|
2019-05-17 22:13:47 +02:00
|
|
|
sh: "[ 1 = 2 ]"
|
|
|
|
msg: "1 is not 2"
|
|
|
|
`,
|
|
|
|
&taskfile.Precondition{},
|
2019-05-28 22:02:59 +02:00
|
|
|
&taskfile.Precondition{Sh: "[ 1 = 2 ]", Msg: "1 is not 2"},
|
2019-05-17 22:13:47 +02:00
|
|
|
},
|
2023-03-31 21:13:29 +02:00
|
|
|
{
|
|
|
|
`
|
2019-05-17 22:13:47 +02:00
|
|
|
sh: "[ 1 = 2 ]"
|
|
|
|
msg: "1 is not 2"
|
|
|
|
`,
|
|
|
|
&taskfile.Precondition{},
|
2019-05-28 22:02:59 +02:00
|
|
|
&taskfile.Precondition{Sh: "[ 1 = 2 ]", Msg: "1 is not 2"},
|
2019-05-17 22:13:47 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, test := range tests {
|
|
|
|
err := yaml.Unmarshal([]byte(test.content), test.v)
|
2023-04-06 12:18:41 +02:00
|
|
|
require.NoError(t, err)
|
2019-05-17 22:13:47 +02:00
|
|
|
assert.Equal(t, test.expected, test.v)
|
|
|
|
}
|
|
|
|
}
|