| 2251 | } |
| 2252 | |
| 2253 | func TestDeferredCmds(t *testing.T) { |
| 2254 | t.Parallel() |
| 2255 | |
| 2256 | const dir = "testdata/deferred" |
| 2257 | var buff bytes.Buffer |
| 2258 | e := task.NewExecutor( |
| 2259 | task.WithDir(dir), |
| 2260 | task.WithStdout(&buff), |
| 2261 | task.WithStderr(&buff), |
| 2262 | ) |
| 2263 | require.NoError(t, e.Setup()) |
| 2264 | |
| 2265 | expectedOutputOrder := strings.TrimSpace(` |
| 2266 | task: [task-2] echo 'cmd ran' |
| 2267 | cmd ran |
| 2268 | task: [task-2] exit 1 |
| 2269 | task: [task-2] echo 'failing' && exit 2 |
| 2270 | failing |
| 2271 | echo ran |
| 2272 | task-1 ran successfully |
| 2273 | task: [task-1] echo 'task-1 ran successfully' |
| 2274 | task-1 ran successfully |
| 2275 | `) |
| 2276 | require.Error(t, e.Run(t.Context(), &task.Call{Task: "task-2"})) |
| 2277 | assert.Contains(t, buff.String(), expectedOutputOrder) |
| 2278 | buff.Reset() |
| 2279 | require.NoError(t, e.Run(t.Context(), &task.Call{Task: "parent"})) |
| 2280 | assert.Contains(t, buff.String(), "child task deferred value-from-parent") |
| 2281 | } |
| 2282 | |
| 2283 | func TestExitCodeZero(t *testing.T) { |
| 2284 | t.Parallel() |