mirror of
https://github.com/go-task/task.git
synced 2025-12-16 11:47:44 +01:00
test(if): add tests for task calls and go templates
Add comprehensive test cases for: - Task calls in cmds with if conditions - Go template functions (eq, ne, and, or) - Direct template variable evaluation - CLI variable overrides - Task-level if with templates
This commit is contained in:
92
testdata/if/Taskfile.yml
vendored
92
testdata/if/Taskfile.yml
vendored
@@ -2,6 +2,9 @@ version: '3'
|
||||
|
||||
vars:
|
||||
SHOULD_RUN: "yes"
|
||||
ENV: "prod"
|
||||
FEATURE_ENABLED: "true"
|
||||
FEATURE_DISABLED: "false"
|
||||
|
||||
tasks:
|
||||
# Basic command-level if (condition met)
|
||||
@@ -66,3 +69,92 @@ tasks:
|
||||
- task: subtask
|
||||
if: "false"
|
||||
- echo "after skipped task call"
|
||||
|
||||
# Task call in cmds with if condition met
|
||||
task-call-if-true:
|
||||
cmds:
|
||||
- task: subtask
|
||||
if: "true"
|
||||
- echo "after task call"
|
||||
|
||||
# Task call in cmds with if condition not met
|
||||
task-call-if-false:
|
||||
cmds:
|
||||
- task: subtask
|
||||
if: "false"
|
||||
- echo "continues after skipped task"
|
||||
|
||||
# Template eq - condition met
|
||||
template-eq-true:
|
||||
cmds:
|
||||
- cmd: echo "env is prod"
|
||||
if: '{{ eq .ENV "prod" }}'
|
||||
|
||||
# Template eq - condition not met
|
||||
template-eq-false:
|
||||
cmds:
|
||||
- cmd: echo "should not appear"
|
||||
if: '{{ eq .ENV "dev" }}'
|
||||
- echo "this runs"
|
||||
|
||||
# Template ne (not equal)
|
||||
template-ne:
|
||||
cmds:
|
||||
- cmd: echo "env is not dev"
|
||||
if: '{{ ne .ENV "dev" }}'
|
||||
|
||||
# Template with boolean-like variable
|
||||
template-bool-true:
|
||||
cmds:
|
||||
- cmd: echo "feature enabled"
|
||||
if: '{{ eq .FEATURE_ENABLED "true" }}'
|
||||
|
||||
# Template with boolean-like variable (false)
|
||||
template-bool-false:
|
||||
cmds:
|
||||
- cmd: echo "should not appear"
|
||||
if: '{{ eq .FEATURE_DISABLED "true" }}'
|
||||
- echo "feature was disabled"
|
||||
|
||||
# Direct true/false from template
|
||||
template-direct-true:
|
||||
cmds:
|
||||
- cmd: echo "direct true works"
|
||||
if: '{{ .FEATURE_ENABLED }}'
|
||||
|
||||
# Direct true/false from template (false case)
|
||||
template-direct-false:
|
||||
cmds:
|
||||
- cmd: echo "should not appear"
|
||||
if: '{{ .FEATURE_DISABLED }}'
|
||||
- echo "direct false skipped correctly"
|
||||
|
||||
# Template with CLI variable override
|
||||
template-cli-var:
|
||||
cmds:
|
||||
- cmd: echo "MY_VAR is yes"
|
||||
if: '{{ eq .MY_VAR "yes" }}'
|
||||
|
||||
# Combined template conditions with and
|
||||
template-and:
|
||||
cmds:
|
||||
- cmd: echo "both conditions met"
|
||||
if: '{{ and (eq .ENV "prod") (eq .FEATURE_ENABLED "true") }}'
|
||||
|
||||
# Combined template conditions with or
|
||||
template-or:
|
||||
cmds:
|
||||
- cmd: echo "at least one condition met"
|
||||
if: '{{ or (eq .ENV "dev") (eq .ENV "prod") }}'
|
||||
|
||||
# Task-level if with template
|
||||
task-level-template:
|
||||
if: '{{ eq .ENV "prod" }}'
|
||||
cmds:
|
||||
- echo "task runs in prod"
|
||||
|
||||
# Task-level if with template (not met)
|
||||
task-level-template-false:
|
||||
if: '{{ eq .ENV "dev" }}'
|
||||
cmds:
|
||||
- echo "should not appear"
|
||||
|
||||
Reference in New Issue
Block a user