2023-12-29 20:32:03 +00:00
|
|
|
package ast_test
|
2019-05-17 13:13:47 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2023-04-06 11:18:41 +01:00
|
|
|
"github.com/stretchr/testify/require"
|
2020-03-28 11:27:49 -03:00
|
|
|
"gopkg.in/yaml.v3"
|
2021-01-07 11:48:33 -03:00
|
|
|
|
2023-12-29 20:32:03 +00:00
|
|
|
"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
|
2023-03-30 20:03:59 +00:00
|
|
|
v any
|
|
|
|
expected any
|
2019-05-17 13:13:47 -07:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
"test -f foo.txt",
|
2023-12-29 20:32:03 +00:00
|
|
|
&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 ]'",
|
2023-12-29 20:32:03 +00:00
|
|
|
&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"
|
|
|
|
`,
|
2023-12-29 20:32:03 +00:00
|
|
|
&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"
|
|
|
|
`,
|
2023-12-29 20:32:03 +00:00
|
|
|
&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)
|
2023-04-06 11:18:41 +01:00
|
|
|
require.NoError(t, err)
|
2019-05-17 13:13:47 -07:00
|
|
|
assert.Equal(t, test.expected, test.v)
|
|
|
|
}
|
|
|
|
}
|