2019-05-17 22:13:47 +02:00
|
|
|
package taskfile_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
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
|
|
|
|
v interface{}
|
|
|
|
expected interface{}
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"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
|
|
|
},
|
|
|
|
{`
|
|
|
|
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
|
|
|
},
|
|
|
|
{`
|
|
|
|
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)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, test.expected, test.v)
|
|
|
|
}
|
|
|
|
}
|