2017-09-07 18:57:06 +02:00
|
|
|
package args_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2018-11-05 01:23:35 +02:00
|
|
|
"github.com/go-task/task/v2/internal/args"
|
|
|
|
"github.com/go-task/task/v2/internal/taskfile"
|
2017-09-07 18:57:06 +02:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestArgs(t *testing.T) {
|
|
|
|
tests := []struct {
|
2019-05-11 16:06:47 +02:00
|
|
|
Args []string
|
|
|
|
ExpectedCalls []taskfile.Call
|
|
|
|
ExpectedGlobals taskfile.Vars
|
2017-09-07 18:57:06 +02:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
Args: []string{"task-a", "task-b", "task-c"},
|
2019-05-11 16:06:47 +02:00
|
|
|
ExpectedCalls: []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"},
|
2019-05-11 16:06:47 +02:00
|
|
|
ExpectedCalls: []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"},
|
2019-05-11 16:06:47 +02:00
|
|
|
ExpectedCalls: []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
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2019-05-11 16:06:47 +02:00
|
|
|
Args: []string{"FOO=bar", "task-a", "task-b"},
|
|
|
|
ExpectedCalls: []taskfile.Call{
|
|
|
|
{Task: "task-a"},
|
|
|
|
{Task: "task-b"},
|
|
|
|
},
|
|
|
|
ExpectedGlobals: taskfile.Vars{
|
|
|
|
"FOO": {Static: "bar"},
|
|
|
|
},
|
2017-09-07 18:57:06 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, test := range tests {
|
|
|
|
t.Run(fmt.Sprintf("TestArgs%d", i+1), func(t *testing.T) {
|
2019-05-11 16:06:47 +02:00
|
|
|
calls, globals := args.Parse(test.Args...)
|
|
|
|
assert.Equal(t, test.ExpectedCalls, calls)
|
|
|
|
assert.Equal(t, test.ExpectedGlobals, globals)
|
2017-09-07 18:57:06 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|