| 1536 | } |
| 1537 | |
| 1538 | func TestIncludesFlatten(t *testing.T) { |
| 1539 | t.Parallel() |
| 1540 | |
| 1541 | const dir = "testdata/includes_flatten" |
| 1542 | tests := []struct { |
| 1543 | name string |
| 1544 | taskfile string |
| 1545 | task string |
| 1546 | expectedErr bool |
| 1547 | expectedOutput string |
| 1548 | }{ |
| 1549 | {name: "included flatten", taskfile: "Taskfile.yml", task: "gen", expectedOutput: "gen from included\n"}, |
| 1550 | {name: "included flatten with default", taskfile: "Taskfile.yml", task: "default", expectedOutput: "default from included flatten\n"}, |
| 1551 | {name: "included flatten can call entrypoint tasks", taskfile: "Taskfile.yml", task: "from_entrypoint", expectedOutput: "from entrypoint\n"}, |
| 1552 | {name: "included flatten with deps", taskfile: "Taskfile.yml", task: "with_deps", expectedOutput: "gen from included\nwith_deps from included\n"}, |
| 1553 | {name: "included flatten nested", taskfile: "Taskfile.yml", task: "from_nested", expectedOutput: "from nested\n"}, |
| 1554 | {name: "included flatten multiple same task", taskfile: "Taskfile.multiple.yml", task: "gen", expectedErr: true, expectedOutput: "task: Found multiple tasks (gen) included by \"included\"\""}, |
| 1555 | } |
| 1556 | |
| 1557 | for _, test := range tests { |
| 1558 | t.Run(test.name, func(t *testing.T) { |
| 1559 | t.Parallel() |
| 1560 | |
| 1561 | var buff bytes.Buffer |
| 1562 | e := task.NewExecutor( |
| 1563 | task.WithDir(dir), |
| 1564 | task.WithEntrypoint(dir+"/"+test.taskfile), |
| 1565 | task.WithStdout(&buff), |
| 1566 | task.WithStderr(&buff), |
| 1567 | task.WithSilent(true), |
| 1568 | ) |
| 1569 | err := e.Setup() |
| 1570 | if test.expectedErr { |
| 1571 | assert.EqualError(t, err, test.expectedOutput) |
| 1572 | } else { |
| 1573 | require.NoError(t, err) |
| 1574 | _ = e.Run(t.Context(), &task.Call{Task: test.task}) |
| 1575 | assert.Equal(t, test.expectedOutput, buff.String()) |
| 1576 | } |
| 1577 | }) |
| 1578 | } |
| 1579 | } |
| 1580 | |
| 1581 | func TestIncludesInterpolation(t *testing.T) { // nolint:paralleltest // cannot run in parallel |
| 1582 | const dir = "testdata/includes_interpolation" |