task
task copied to clipboard
feature request: Unit Testing Taskfiles
Summary
As remote taskfiles are on the roadmap it probably makes sense to be able to unit test taskfiles as well to ensure that any breaking changes are adequately accounted for as it can have wide ranging impacts.
ref: https://github.com/go-task/task/issues/1317
Proposal
Test Taskfiles should be in the same dir and follow the same convention as go tests. The test taskfiles will call all tasks the test prefix as well to determine which individual tasks within the taskfile should be tested
example dir:
taskfiledir/
git_tasks.yml
test_git_tasks.yml
example task:
version: 'x'
tasks:
task1:
- echo 'somestring' > somefile.txt
example test task:
version: 'x'
tasks:
test_task1:
- test -f somefile.txt
The tests should also be able to mock out sections where tasks other tasks rely on the execution of certain tasks (task1 calls task2) via - task: task2
(which actually makes an HTTP call or something) or the deps
block:
version: 'x'
tasks:
task1:
- task: task2
- echo 'somestring' > somefile.txt
version: 'x'
mocks:
task2:
cmd: 'echo "value=$(some JSON respose)" > some.env'
test_task1:
dotenv: [some.env]
cmds:
- cmd: |
if [[ $value != "" ]]; then
echo "failed"
exit 1
fi
this of course would result in a subcommand of something like:
task --test -f ./...