2017-09-07 18:57:06 +02:00
|
|
|
package args_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2017-10-15 21:58:21 +02:00
|
|
|
"github.com/go-task/task/internal/args"
|
2018-02-17 18:22:18 +02:00
|
|
|
"github.com/go-task/task/internal/taskfile"
|
2017-09-07 18:57:06 +02:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestArgs(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
Args []string
|
2018-02-17 18:22:18 +02:00
|
|
|
Expected []taskfile.Call
|
2017-09-07 18:57:06 +02:00
|
|
|
Err error
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Args: []string{"task-a", "task-b", "task-c"},
|
2018-02-17 18:22:18 +02:00
|
|
|
Expected: []taskfile.Call{
|
2017-09-07 18:57:06 +02:00
|
|
|
{Task: "task-a"},
|
|
|
|
{Task: "task-b"},
|
|
|
|
{Task: "task-c"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Args: []string{"task-a", "FOO=bar", "task-b", "task-c", "BAR=baz", "BAZ=foo"},
|
2018-02-17 18:22:18 +02:00
|
|
|
Expected: []taskfile.Call{
|
2017-09-07 18:57:06 +02:00
|
|
|
{
|
|
|
|
Task: "task-a",
|
2018-02-17 18:22:18 +02:00
|
|
|
Vars: taskfile.Vars{
|
|
|
|
"FOO": taskfile.Var{Static: "bar"},
|
2017-09-07 18:57:06 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{Task: "task-b"},
|
|
|
|
{
|
|
|
|
Task: "task-c",
|
2018-02-17 18:22:18 +02:00
|
|
|
Vars: taskfile.Vars{
|
|
|
|
"BAR": taskfile.Var{Static: "baz"},
|
|
|
|
"BAZ": taskfile.Var{Static: "foo"},
|
2017-09-07 18:57:06 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Args: []string{"task-a", "CONTENT=with some spaces"},
|
2018-02-17 18:22:18 +02:00
|
|
|
Expected: []taskfile.Call{
|
2017-09-07 18:57:06 +02:00
|
|
|
{
|
|
|
|
Task: "task-a",
|
2018-02-17 18:22:18 +02:00
|
|
|
Vars: taskfile.Vars{
|
|
|
|
"CONTENT": taskfile.Var{Static: "with some spaces"},
|
2017-09-07 18:57:06 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Args: []string{"FOO=bar", "task-a"},
|
|
|
|
Err: args.ErrVariableWithoutTask,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, test := range tests {
|
|
|
|
t.Run(fmt.Sprintf("TestArgs%d", i+1), func(t *testing.T) {
|
|
|
|
calls, err := args.Parse(test.Args...)
|
|
|
|
assert.Equal(t, test.Err, err)
|
|
|
|
assert.Equal(t, test.Expected, calls)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|