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

99 lines
1.8 KiB
Go
Raw Normal View History

package ast_test
2017-07-02 15:30:50 -03: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"
2024-01-04 00:31:24 +00:00
"github.com/go-task/task/v3/internal/omap"
"github.com/go-task/task/v3/taskfile/ast"
2017-07-02 15:30:50 -03:00
)
func TestCmdParse(t *testing.T) {
const (
yamlCmd = `echo "a string command"`
yamlDep = `"task-name"`
yamlTaskCall = `
task: another-task
2017-07-05 20:07:24 -03:00
vars:
2017-07-02 15:30:50 -03:00
PARAM1: VALUE1
PARAM2: VALUE2
`
yamlDeferredCall = `defer: { task: some_task, vars: { PARAM1: "var" } }`
2021-12-15 00:03:37 -05:00
yamlDeferredCmd = `defer: echo 'test'`
2017-07-02 15:30:50 -03:00
)
tests := []struct {
content string
v any
expected any
2017-07-02 15:30:50 -03:00
}{
{
yamlCmd,
&ast.Cmd{},
&ast.Cmd{Cmd: `echo "a string command"`},
2017-07-02 15:30:50 -03:00
},
{
yamlTaskCall,
&ast.Cmd{},
&ast.Cmd{
Task: "another-task", Vars: &ast.Vars{
2024-01-04 00:31:24 +00:00
OrderedMap: omap.FromMapWithOrder(
map[string]ast.Var{
"PARAM1": {Value: "VALUE1"},
"PARAM2": {Value: "VALUE2"},
},
[]string{"PARAM1", "PARAM2"},
),
},
},
2017-07-02 15:30:50 -03:00
},
2021-12-15 00:03:37 -05:00
{
yamlDeferredCmd,
&ast.Cmd{},
&ast.Cmd{Cmd: "echo 'test'", Defer: true},
2021-12-15 00:03:37 -05:00
},
{
yamlDeferredCall,
&ast.Cmd{},
&ast.Cmd{
Task: "some_task", Vars: &ast.Vars{
2024-01-04 00:31:24 +00:00
OrderedMap: omap.FromMapWithOrder(
map[string]ast.Var{
"PARAM1": {Value: "var"},
},
[]string{"PARAM1"},
),
},
Defer: true,
},
2021-12-15 00:03:37 -05:00
},
2017-07-02 15:30:50 -03:00
{
yamlDep,
&ast.Dep{},
&ast.Dep{Task: "task-name"},
2017-07-02 15:30:50 -03:00
},
{
yamlTaskCall,
&ast.Dep{},
&ast.Dep{
Task: "another-task", Vars: &ast.Vars{
2024-01-04 00:31:24 +00:00
OrderedMap: omap.FromMapWithOrder(
map[string]ast.Var{
"PARAM1": {Value: "VALUE1"},
"PARAM2": {Value: "VALUE2"},
},
[]string{"PARAM1", "PARAM2"},
),
},
},
2017-07-02 15:30:50 -03:00
},
}
for _, test := range tests {
err := yaml.Unmarshal([]byte(test.content), test.v)
require.NoError(t, err)
2017-07-02 15:30:50 -03:00
assert.Equal(t, test.expected, test.v)
}
}