mirror of
https://github.com/go-task/task.git
synced 2025-06-17 00:17:51 +02:00
feat: tests for wildcard matching
This commit is contained in:
49
task_test.go
49
task_test.go
@ -2249,3 +2249,52 @@ func TestFor(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestWildcard(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
expectedOutput string
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "wildcard-foo",
|
||||||
|
expectedOutput: "Hello foo\n",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "foo-wildcard-bar",
|
||||||
|
expectedOutput: "Hello foo bar\n",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "start-foo",
|
||||||
|
expectedOutput: "Starting foo\n",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "matches-exactly-*",
|
||||||
|
expectedOutput: "I don't consume matches: \n",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "no-match",
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
var buff bytes.Buffer
|
||||||
|
e := task.Executor{
|
||||||
|
Dir: "testdata/wildcards",
|
||||||
|
Stdout: &buff,
|
||||||
|
Stderr: &buff,
|
||||||
|
Silent: true,
|
||||||
|
Force: true,
|
||||||
|
}
|
||||||
|
require.NoError(t, e.Setup())
|
||||||
|
if test.wantErr {
|
||||||
|
require.Error(t, e.Run(context.Background(), &ast.Call{Task: test.name}))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
require.NoError(t, e.Run(context.Background(), &ast.Call{Task: test.name}))
|
||||||
|
assert.Equal(t, test.expectedOutput, buff.String())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
5
testdata/wildcards/Taskfile.yml
vendored
5
testdata/wildcards/Taskfile.yml
vendored
@ -9,6 +9,11 @@ tasks:
|
|||||||
cmds:
|
cmds:
|
||||||
- echo "Hello {{index .MATCH 0}} {{index .MATCH 1}}"
|
- echo "Hello {{index .MATCH 0}} {{index .MATCH 1}}"
|
||||||
|
|
||||||
|
# Matches is empty when you call the task name exactly (i.e. `task matches-exactly-*`)
|
||||||
|
matches-exactly-*:
|
||||||
|
cmds:
|
||||||
|
- "echo \"I don't consume matches: {{.MATCH}}\""
|
||||||
|
|
||||||
start-*:
|
start-*:
|
||||||
vars:
|
vars:
|
||||||
SERVICE: "{{index .MATCH 0}}"
|
SERVICE: "{{index .MATCH 0}}"
|
||||||
|
Reference in New Issue
Block a user