2019-02-24 18:05:37 +02:00
|
|
|
package summary_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"github.com/go-task/task/v2/internal/logger"
|
|
|
|
"github.com/go-task/task/v2/internal/summary"
|
|
|
|
"github.com/go-task/task/v2/internal/taskfile"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2019-02-24 18:10:59 +02:00
|
|
|
func TestPrintsDependenciesIfPresent(t *testing.T) {
|
2019-02-24 18:05:37 +02:00
|
|
|
buffer := &bytes.Buffer{}
|
|
|
|
l := logger.Logger{
|
|
|
|
Stdout: buffer,
|
|
|
|
Stderr: buffer,
|
|
|
|
Verbose: false,
|
|
|
|
}
|
|
|
|
task := &taskfile.Task{
|
|
|
|
Deps: []*taskfile.Dep{
|
|
|
|
{Task: "dep1"},
|
|
|
|
{Task: "dep2"},
|
|
|
|
{Task: "dep3"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
summary.Print(&l, task)
|
|
|
|
|
|
|
|
assert.Contains(t, buffer.String(), "\ndependencies:\n")
|
|
|
|
assert.Contains(t, buffer.String(), "\n - dep1\n")
|
|
|
|
assert.Contains(t, buffer.String(), "\n - dep2\n")
|
|
|
|
assert.Contains(t, buffer.String(), "\n - dep3\n")
|
|
|
|
}
|
|
|
|
|
2019-02-24 18:10:59 +02:00
|
|
|
func TestDoesNotPrintDependenciesIfMissing(t *testing.T) {
|
2019-02-24 18:05:37 +02:00
|
|
|
buffer := &bytes.Buffer{}
|
|
|
|
l := logger.Logger{
|
|
|
|
Stdout: buffer,
|
|
|
|
Stderr: buffer,
|
|
|
|
Verbose: false,
|
|
|
|
}
|
|
|
|
task := &taskfile.Task{
|
|
|
|
Deps: []*taskfile.Dep{},
|
|
|
|
}
|
|
|
|
|
|
|
|
summary.Print(&l, task)
|
|
|
|
|
|
|
|
assert.NotContains(t, buffer.String(), "dependencies:")
|
|
|
|
}
|
2019-02-24 18:10:59 +02:00
|
|
|
|
|
|
|
func TestPrintTaskName(t *testing.T) {
|
|
|
|
buffer := &bytes.Buffer{}
|
|
|
|
l := logger.Logger{
|
|
|
|
Stdout: buffer,
|
|
|
|
Stderr: buffer,
|
|
|
|
Verbose: false,
|
|
|
|
}
|
|
|
|
task := &taskfile.Task{
|
|
|
|
Task: "my-task-name",
|
|
|
|
}
|
|
|
|
|
|
|
|
summary.Print(&l, task)
|
|
|
|
|
|
|
|
assert.Contains(t, buffer.String(), "task: my-task-name\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPrintTaskCommandsIfPresent(t *testing.T) {
|
|
|
|
buffer := &bytes.Buffer{}
|
|
|
|
l := logger.Logger{
|
|
|
|
Stdout: buffer,
|
|
|
|
Stderr: buffer,
|
|
|
|
Verbose: false,
|
|
|
|
}
|
|
|
|
task := &taskfile.Task{
|
|
|
|
Cmds: []*taskfile.Cmd{
|
|
|
|
{Cmd: "command-1"},
|
|
|
|
{Cmd: "command-2"},
|
2019-02-24 18:23:31 +02:00
|
|
|
{Task: "task-1"},
|
2019-02-24 18:10:59 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
summary.Print(&l, task)
|
|
|
|
|
|
|
|
assert.Contains(t, buffer.String(), "\ncommands:\n")
|
|
|
|
assert.Contains(t, buffer.String(), "\n - command-1\n")
|
|
|
|
assert.Contains(t, buffer.String(), "\n - command-2\n")
|
2019-02-24 18:23:31 +02:00
|
|
|
assert.Contains(t, buffer.String(), "\n - Task: task-1\n")
|
2019-02-24 18:10:59 +02:00
|
|
|
}
|
2019-02-24 18:12:22 +02:00
|
|
|
|
|
|
|
func TestDoesNotPrintCommandIfMissing(t *testing.T) {
|
|
|
|
buffer := &bytes.Buffer{}
|
|
|
|
l := logger.Logger{
|
|
|
|
Stdout: buffer,
|
|
|
|
Stderr: buffer,
|
|
|
|
Verbose: false,
|
|
|
|
}
|
|
|
|
task := &taskfile.Task{
|
|
|
|
Cmds: []*taskfile.Cmd{},
|
|
|
|
}
|
|
|
|
|
|
|
|
summary.Print(&l, task)
|
|
|
|
|
|
|
|
assert.NotContains(t, buffer.String(), "commands")
|
|
|
|
}
|
2019-02-24 18:20:29 +02:00
|
|
|
|
|
|
|
func TestFullSummary(t *testing.T) {
|
|
|
|
buffer := &bytes.Buffer{}
|
|
|
|
l := logger.Logger{
|
|
|
|
Stdout: buffer,
|
|
|
|
Stderr: buffer,
|
|
|
|
Verbose: false,
|
|
|
|
}
|
|
|
|
task := &taskfile.Task{
|
|
|
|
Task: "sample-task",
|
|
|
|
Summary: "line1\nline2\nline3\n",
|
|
|
|
Deps: []*taskfile.Dep{
|
|
|
|
{Task: "dependency"},
|
|
|
|
},
|
|
|
|
Cmds: []*taskfile.Cmd{
|
|
|
|
{Cmd: "command"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
summary.Print(&l, task)
|
|
|
|
|
|
|
|
expected :=
|
|
|
|
`task: sample-task
|
|
|
|
|
|
|
|
line1
|
|
|
|
line2
|
|
|
|
line3
|
|
|
|
|
|
|
|
dependencies:
|
|
|
|
- dependency
|
|
|
|
|
|
|
|
commands:
|
|
|
|
- command
|
|
|
|
`
|
|
|
|
|
|
|
|
assert.Equal(t, expected, buffer.String())
|
|
|
|
}
|