1
0
mirror of https://github.com/go-task/task.git synced 2025-01-24 05:17:21 +02:00
task/taskfile/ast/precondition_test.go

52 lines
976 B
Go
Raw Normal View History

package ast_test
2019-05-17 13:13:47 -07:00
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
2020-03-28 11:27:49 -03:00
"gopkg.in/yaml.v3"
"github.com/go-task/task/v3/taskfile/ast"
2019-05-17 13:13:47 -07:00
)
func TestPreconditionParse(t *testing.T) {
tests := []struct {
content string
v any
expected any
2019-05-17 13:13:47 -07:00
}{
{
"test -f foo.txt",
&ast.Precondition{},
&ast.Precondition{Sh: `test -f foo.txt`, Msg: "`test -f foo.txt` failed"},
2019-05-17 13:13:47 -07:00
},
{
"sh: '[ 1 = 0 ]'",
&ast.Precondition{},
&ast.Precondition{Sh: "[ 1 = 0 ]", Msg: "[ 1 = 0 ] failed"},
2019-05-17 13:13:47 -07:00
},
2023-03-31 19:13:29 +00:00
{
`
2019-05-17 13:13:47 -07:00
sh: "[ 1 = 2 ]"
msg: "1 is not 2"
`,
&ast.Precondition{},
&ast.Precondition{Sh: "[ 1 = 2 ]", Msg: "1 is not 2"},
2019-05-17 13:13:47 -07:00
},
2023-03-31 19:13:29 +00:00
{
`
2019-05-17 13:13:47 -07:00
sh: "[ 1 = 2 ]"
msg: "1 is not 2"
`,
&ast.Precondition{},
&ast.Precondition{Sh: "[ 1 = 2 ]", Msg: "1 is not 2"},
2019-05-17 13:13:47 -07:00
},
}
for _, test := range tests {
err := yaml.Unmarshal([]byte(test.content), test.v)
require.NoError(t, err)
2019-05-17 13:13:47 -07:00
assert.Equal(t, test.expected, test.v)
}
}