1
0
mirror of https://github.com/go-task/task.git synced 2025-01-04 03:48:02 +02:00

Add basic unit tests for label attribute

This commit is contained in:
Adam Wasila 2020-06-14 11:02:25 +02:00
parent 9f83311931
commit 4bc183a8a1
6 changed files with 122 additions and 0 deletions

View File

@ -384,6 +384,90 @@ func TestStatusChecksum(t *testing.T) {
assert.Equal(t, `task: Task "build" is up to date`+"\n", buff.String())
}
func TestLabelUpToDate(t *testing.T) {
const dir = "testdata/label_uptodate"
var buff bytes.Buffer
e := task.Executor{
Dir: dir,
Stdout: &buff,
Stderr: &buff,
}
assert.NoError(t, e.Setup())
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "foo"}))
assert.Contains(t, buff.String(), "foobar")
}
func TestLabelSummary(t *testing.T) {
const dir = "testdata/label_summary"
var buff bytes.Buffer
e := task.Executor{
Dir: dir,
Summary: true,
Stdout: &buff,
Stderr: &buff,
}
assert.NoError(t, e.Setup())
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "foo"}))
assert.Contains(t, buff.String(), "foobar")
}
func TestLabelInStatus(t *testing.T) {
const dir = "testdata/label_status"
e := task.Executor{
Dir: dir,
}
assert.NoError(t, e.Setup())
err := e.Status(context.Background(), taskfile.Call{Task: "foo"})
if assert.Error(t, err) {
assert.Contains(t, err.Error(), "foobar")
}
}
func TestLabelWithVariableExpansion(t *testing.T) {
const dir = "testdata/label_var"
var buff bytes.Buffer
e := task.Executor{
Dir: dir,
Stdout: &buff,
Stderr: &buff,
}
assert.NoError(t, e.Setup())
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "foo"}))
assert.Contains(t, buff.String(), "foobaz")
}
func TestLabelInSummary(t *testing.T) {
const dir = "testdata/label_summary"
var buff bytes.Buffer
e := task.Executor{
Dir: dir,
Stdout: &buff,
Stderr: &buff,
}
assert.NoError(t, e.Setup())
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "foo"}))
assert.Contains(t, buff.String(), "foobar")
}
func TestLabelInList(t *testing.T) {
const dir = "testdata/label_list"
var buff bytes.Buffer
e := task.Executor{
Dir: dir,
Stdout: &buff,
Stderr: &buff,
}
assert.NoError(t, e.Setup())
e.PrintTasksHelp()
assert.Contains(t, buff.String(), "foobar")
}
func TestStatusVariables(t *testing.T) {
const dir = "testdata/status_vars"

6
testdata/label_list/Taskfile.yml vendored Normal file
View File

@ -0,0 +1,6 @@
version: '3'
tasks:
foo:
label: "foobar"
desc: "task description"

7
testdata/label_status/Taskfile.yml vendored Normal file
View File

@ -0,0 +1,7 @@
version: '3'
tasks:
foo:
label: "foobar"
status:
- "false"

8
testdata/label_summary/Taskfile.yml vendored Normal file
View File

@ -0,0 +1,8 @@
version: '3'
tasks:
foo:
label: "foobar"
desc: description
status:
- echo "I'm ok"

7
testdata/label_uptodate/Taskfile.yml vendored Normal file
View File

@ -0,0 +1,7 @@
version: '3'
tasks:
foo:
label: "foobar"
status:
- echo "I'm ok"

10
testdata/label_var/Taskfile.yml vendored Normal file
View File

@ -0,0 +1,10 @@
version: '3'
vars:
BAR: baz
tasks:
foo:
label: "foo{{.BAR}}"
status:
- echo "I'm ok"