diff --git a/task.go b/task.go index 1a68ada2..6e26d5c2 100644 --- a/task.go +++ b/task.go @@ -98,9 +98,13 @@ func (e *Executor) printTaskSummary(task string) { } func printCommands(cmds []*taskfile.Cmd, logger *logger.Logger) { - logger.Outf("commands:") - for _, c := range cmds { - logger.Outf(" - %s", c.Cmd) + hasCommands := len(cmds) > 0 + if hasCommands { + logger.Outf("") + logger.Outf("commands:") + for _, c := range cmds { + logger.Outf(" - %s", c.Cmd) + } } } @@ -114,7 +118,6 @@ func printTaskDependencies(deps []*taskfile.Dep, logger *logger.Logger) { logger.Outf(" - %s", d.Task) } } - logger.Outf("") } func printTaskSummary(description string, Logger *logger.Logger) { diff --git a/task_test.go b/task_test.go index 9a51886f..a3636826 100644 --- a/task_test.go +++ b/task_test.go @@ -554,19 +554,6 @@ func TestIncludesCallingRoot(t *testing.T) { tt.Run(t) } -func TestSummaryParsing(t *testing.T) { - const dir = "testdata/summary" - - e := task.Executor{ - Dir: dir, - } - assert.NoError(t, e.Setup()) - - assert.Equal(t, e.Taskfile.Tasks["task-with-summary"].Summary, "summary of task-with-summary - line 1\nline 2\nline 3\n") - assert.Equal(t, e.Taskfile.Tasks["other-task-with-summary"].Summary, "summary of other-task-with-summary") - assert.Equal(t, e.Taskfile.Tasks["task-without-summary"].Summary, "") -} - func TestSummary(t *testing.T) { const dir = "testdata/summary" @@ -598,6 +585,10 @@ func TestSummary(t *testing.T) { assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "task-with-summary-containing-empty-line"})) assert.Equal(t, readTestFixture(t, dir, "task-with-summary-containing-empty-line.txt"), buff.String()) + buff.Reset() + assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "task-without-commands"})) + assert.Equal(t, readTestFixture(t, dir, "task-without-commands.txt"), buff.String()) + } func readTestFixture(t *testing.T, dir string, file string) string { diff --git a/testdata/summary/Taskfile.yml b/testdata/summary/Taskfile.yml index 28cec378..2a7fcdaf 100644 --- a/testdata/summary/Taskfile.yml +++ b/testdata/summary/Taskfile.yml @@ -12,7 +12,7 @@ tasks: - exit 0 task-without-summary: - deps: [dependend-task] + deps: [dependend-task-1] cmds: - echo 'task-without-summary was executed' @@ -36,3 +36,7 @@ tasks: Last Line cmds: - exit 0 + + task-without-commands: + summary: summary + deps: [dependend-task-1]