2018-02-17 18:22:18 +02:00
|
|
|
package taskfile_test
|
2017-07-02 20:30:50 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
2023-04-06 13:07:57 +02:00
|
|
|
"github.com/go-task/task/v3/internal/orderedmap"
|
2021-01-07 16:48:33 +02:00
|
|
|
"github.com/go-task/task/v3/taskfile"
|
2017-07-02 20:30:50 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCmdParse(t *testing.T) {
|
|
|
|
const (
|
|
|
|
yamlCmd = `echo "a string command"`
|
|
|
|
yamlDep = `"task-name"`
|
|
|
|
yamlTaskCall = `
|
|
|
|
task: another-task
|
2017-07-06 01:07:24 +02:00
|
|
|
vars:
|
2017-07-02 20:30:50 +02:00
|
|
|
PARAM1: VALUE1
|
|
|
|
PARAM2: VALUE2
|
|
|
|
`
|
2022-01-02 23:38:06 +02:00
|
|
|
yamlDeferredCall = `defer: { task: some_task, vars: { PARAM1: "var" } }`
|
2021-12-15 07:03:37 +02:00
|
|
|
yamlDeferredCmd = `defer: echo 'test'`
|
2017-07-02 20:30:50 +02:00
|
|
|
)
|
|
|
|
tests := []struct {
|
|
|
|
content string
|
2023-03-30 22:03:59 +02:00
|
|
|
v any
|
|
|
|
expected any
|
2017-07-02 20:30:50 +02:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
yamlCmd,
|
2018-02-17 18:22:18 +02:00
|
|
|
&taskfile.Cmd{},
|
|
|
|
&taskfile.Cmd{Cmd: `echo "a string command"`},
|
2017-07-02 20:30:50 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
yamlTaskCall,
|
2018-02-17 18:22:18 +02:00
|
|
|
&taskfile.Cmd{},
|
2023-04-06 13:07:57 +02:00
|
|
|
&taskfile.Cmd{
|
|
|
|
Task: "another-task", Vars: &taskfile.Vars{
|
|
|
|
OrderedMap: orderedmap.FromMapWithOrder(
|
|
|
|
map[string]taskfile.Var{
|
|
|
|
"PARAM1": {Static: "VALUE1"},
|
|
|
|
"PARAM2": {Static: "VALUE2"},
|
|
|
|
},
|
|
|
|
[]string{"PARAM1", "PARAM2"},
|
|
|
|
),
|
2020-03-29 21:54:59 +02:00
|
|
|
},
|
2023-04-06 13:07:57 +02:00
|
|
|
},
|
2017-07-02 20:30:50 +02:00
|
|
|
},
|
2021-12-15 07:03:37 +02:00
|
|
|
{
|
|
|
|
yamlDeferredCmd,
|
|
|
|
&taskfile.Cmd{},
|
|
|
|
&taskfile.Cmd{Cmd: "echo 'test'", Defer: true},
|
|
|
|
},
|
|
|
|
{
|
2022-01-02 23:38:06 +02:00
|
|
|
yamlDeferredCall,
|
2021-12-15 07:03:37 +02:00
|
|
|
&taskfile.Cmd{},
|
2023-04-06 13:07:57 +02:00
|
|
|
&taskfile.Cmd{
|
|
|
|
Task: "some_task", Vars: &taskfile.Vars{
|
|
|
|
OrderedMap: orderedmap.FromMapWithOrder(
|
|
|
|
map[string]taskfile.Var{
|
|
|
|
"PARAM1": {Static: "var"},
|
|
|
|
},
|
|
|
|
[]string{"PARAM1"},
|
|
|
|
),
|
2022-01-02 23:38:06 +02:00
|
|
|
},
|
2023-04-06 13:07:57 +02:00
|
|
|
Defer: true,
|
|
|
|
},
|
2021-12-15 07:03:37 +02:00
|
|
|
},
|
2017-07-02 20:30:50 +02:00
|
|
|
{
|
|
|
|
yamlDep,
|
2018-02-17 18:22:18 +02:00
|
|
|
&taskfile.Dep{},
|
|
|
|
&taskfile.Dep{Task: "task-name"},
|
2017-07-02 20:30:50 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
yamlTaskCall,
|
2018-02-17 18:22:18 +02:00
|
|
|
&taskfile.Dep{},
|
2023-04-06 13:07:57 +02:00
|
|
|
&taskfile.Dep{
|
|
|
|
Task: "another-task", Vars: &taskfile.Vars{
|
|
|
|
OrderedMap: orderedmap.FromMapWithOrder(
|
|
|
|
map[string]taskfile.Var{
|
|
|
|
"PARAM1": {Static: "VALUE1"},
|
|
|
|
"PARAM2": {Static: "VALUE2"},
|
|
|
|
},
|
|
|
|
[]string{"PARAM1", "PARAM2"},
|
|
|
|
),
|
2020-03-29 21:54:59 +02:00
|
|
|
},
|
2023-04-06 13:07:57 +02:00
|
|
|
},
|
2017-07-02 20:30:50 +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)
|
2017-07-02 20:30:50 +02:00
|
|
|
assert.Equal(t, test.expected, test.v)
|
|
|
|
}
|
|
|
|
}
|