mirror of
https://github.com/go-task/task.git
synced 2025-06-23 00:38:19 +02:00
feat: add task name to json output (#2256)
This commit is contained in:
@ -218,3 +218,23 @@ func TestListDescInterpolation(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestJsonListFormat(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
fp, err := filepath.Abs("testdata/json_list_format/Taskfile.yml")
|
||||||
|
require.NoError(t, err)
|
||||||
|
NewFormatterTest(t,
|
||||||
|
WithExecutorOptions(
|
||||||
|
task.WithDir("testdata/json_list_format"),
|
||||||
|
),
|
||||||
|
WithListOptions(task.ListOptions{
|
||||||
|
FormatTaskListAsJSON: true,
|
||||||
|
}),
|
||||||
|
WithFixtureTemplateData(struct {
|
||||||
|
TaskfileLocation string
|
||||||
|
}{
|
||||||
|
TaskfileLocation: fp,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
1
help.go
1
help.go
@ -149,6 +149,7 @@ func (e *Executor) ToEditorOutput(tasks []*ast.Task, noStatus bool) (*editors.Ta
|
|||||||
g.Go(func() error {
|
g.Go(func() error {
|
||||||
o.Tasks[i] = editors.Task{
|
o.Tasks[i] = editors.Task{
|
||||||
Name: tasks[i].Name(),
|
Name: tasks[i].Name(),
|
||||||
|
Task: tasks[i].Task,
|
||||||
Desc: tasks[i].Desc,
|
Desc: tasks[i].Desc,
|
||||||
Summary: tasks[i].Summary,
|
Summary: tasks[i].Summary,
|
||||||
Aliases: aliases,
|
Aliases: aliases,
|
||||||
|
@ -9,6 +9,7 @@ type (
|
|||||||
// Task describes a single task
|
// Task describes a single task
|
||||||
Task struct {
|
Task struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
Task string `json:"task"`
|
||||||
Desc string `json:"desc"`
|
Desc string `json:"desc"`
|
||||||
Summary string `json:"summary"`
|
Summary string `json:"summary"`
|
||||||
Aliases []string `json:"aliases"`
|
Aliases []string `json:"aliases"`
|
||||||
|
33
task_test.go
33
task_test.go
@ -42,9 +42,10 @@ type (
|
|||||||
FormatterTestOption
|
FormatterTestOption
|
||||||
}
|
}
|
||||||
TaskTest struct {
|
TaskTest struct {
|
||||||
name string
|
name string
|
||||||
experiments map[*experiments.Experiment]int
|
experiments map[*experiments.Experiment]int
|
||||||
postProcessFns []PostProcessFn
|
postProcessFns []PostProcessFn
|
||||||
|
fixtureTemplateData any
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -79,7 +80,11 @@ func (tt *TaskTest) writeFixture(
|
|||||||
if goldenFileSuffix != "" {
|
if goldenFileSuffix != "" {
|
||||||
goldenFileName += "-" + goldenFileSuffix
|
goldenFileName += "-" + goldenFileSuffix
|
||||||
}
|
}
|
||||||
g.Assert(t, goldenFileName, b)
|
if tt.fixtureTemplateData != nil {
|
||||||
|
g.AssertWithTemplate(t, goldenFileName, tt.fixtureTemplateData, b)
|
||||||
|
} else {
|
||||||
|
g.Assert(t, goldenFileName, b)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeFixtureBuffer is a wrapper for writing the main output of the task to a
|
// writeFixtureBuffer is a wrapper for writing the main output of the task to a
|
||||||
@ -234,6 +239,26 @@ func (opt *setupErrorTestOption) applyToFormatterTest(t *FormatterTest) {
|
|||||||
t.wantSetupError = true
|
t.wantSetupError = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithFixtureTemplateData sets up data defined in the golden file using golang
|
||||||
|
// template. Useful if the golden file can change depending on the test.
|
||||||
|
// Example template: {{ .Value }}
|
||||||
|
// Example data definition: struct{ Value string }{Value: "value"}
|
||||||
|
func WithFixtureTemplateData(data any) TestOption {
|
||||||
|
return &fixtureTemplateDataTestOption{data: data}
|
||||||
|
}
|
||||||
|
|
||||||
|
type fixtureTemplateDataTestOption struct {
|
||||||
|
data any
|
||||||
|
}
|
||||||
|
|
||||||
|
func (opt *fixtureTemplateDataTestOption) applyToExecutorTest(t *ExecutorTest) {
|
||||||
|
t.fixtureTemplateData = opt.data
|
||||||
|
}
|
||||||
|
|
||||||
|
func (opt *fixtureTemplateDataTestOption) applyToFormatterTest(t *FormatterTest) {
|
||||||
|
t.fixtureTemplateData = opt.data
|
||||||
|
}
|
||||||
|
|
||||||
// Post-processing
|
// Post-processing
|
||||||
|
|
||||||
// A PostProcessFn is a function that can be applied to the output of a test
|
// A PostProcessFn is a function that can be applied to the output of a test
|
||||||
|
6
testdata/json_list_format/Taskfile.yml
vendored
Normal file
6
testdata/json_list_format/Taskfile.yml
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
version: '3'
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
foo:
|
||||||
|
label: "foobar"
|
||||||
|
desc: "task description"
|
18
testdata/json_list_format/testdata/TestJsonListFormat.golden
vendored
Normal file
18
testdata/json_list_format/testdata/TestJsonListFormat.golden
vendored
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"name": "foobar",
|
||||||
|
"task": "foo",
|
||||||
|
"desc": "task description",
|
||||||
|
"summary": "",
|
||||||
|
"aliases": [],
|
||||||
|
"up_to_date": false,
|
||||||
|
"location": {
|
||||||
|
"line": 4,
|
||||||
|
"column": 3,
|
||||||
|
"taskfile": "{{ .TaskfileLocation }}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"location": "{{ .TaskfileLocation }}"
|
||||||
|
}
|
@ -104,6 +104,7 @@ structure:
|
|||||||
"tasks": [
|
"tasks": [
|
||||||
{
|
{
|
||||||
"name": "",
|
"name": "",
|
||||||
|
"task": "",
|
||||||
"desc": "",
|
"desc": "",
|
||||||
"summary": "",
|
"summary": "",
|
||||||
"up_to_date": false,
|
"up_to_date": false,
|
||||||
|
Reference in New Issue
Block a user