refactor: unify how executor tests are written (#2042)

* feat: use TaskTest for executor tests

* feat: more tests

* feat: separate tests for executing and formatting with new functional options that work for both test types

* feat: formatter tests

* refactor: more tests
This commit is contained in:
Pete Davison
2025-03-31 17:53:58 +01:00
committed by GitHub
parent 180fcef364
commit 4736bc2734
175 changed files with 1706 additions and 1111 deletions

View File

@@ -0,0 +1 @@
task: Found multiple tasks (foo, bar) that match "x"

View File

@@ -0,0 +1,12 @@
done 1
done 2
done 3
done 4
done 5
done 6
task: [t1] echo done 1
task: [t2] echo done 2
task: [t3] echo done 3
task: [t4] echo done 4
task: [t5] echo done 5
task: [t6] echo done 6

View File

@@ -1 +0,0 @@
*.txt

View File

@@ -7,50 +7,50 @@ tasks:
d1:
deps: [d11, d12, d13]
cmds:
- echo 'Text' > d1.txt
- echo 'd1'
d2:
deps: [d21, d22, d23]
cmds:
- echo 'Text' > d2.txt
- echo 'd2'
d3:
deps: [d31, d32, d33]
cmds:
- echo 'Text' > d3.txt
- echo 'd3'
d11:
cmds:
- echo 'Text' > d11.txt
- echo 'd11'
d12:
cmds:
- echo 'Text' > d12.txt
- echo 'd12'
d13:
cmds:
- echo 'Text' > d13.txt
- echo 'd13'
d21:
cmds:
- echo 'Text' > d21.txt
- echo 'd21'
d22:
cmds:
- echo 'Text' > d22.txt
- echo 'd22'
d23:
cmds:
- echo 'Text' > d23.txt
- echo 'd23'
d31:
cmds:
- echo 'Text' > d31.txt
- echo 'd31'
d32:
cmds:
- echo 'Text' > d32.txt
- echo 'd32'
d33:
cmds:
- echo 'Text' > d33.txt
- echo 'd33'

1
testdata/deps/d1.txt vendored Normal file
View File

@@ -0,0 +1 @@
Text

1
testdata/deps/d11.txt vendored Normal file
View File

@@ -0,0 +1 @@
Text

1
testdata/deps/d12.txt vendored Normal file
View File

@@ -0,0 +1 @@
Text

1
testdata/deps/d13.txt vendored Normal file
View File

@@ -0,0 +1 @@
Text

1
testdata/deps/d2.txt vendored Normal file
View File

@@ -0,0 +1 @@
Text

1
testdata/deps/d21.txt vendored Normal file
View File

@@ -0,0 +1 @@
Text

1
testdata/deps/d22.txt vendored Normal file
View File

@@ -0,0 +1 @@
Text

1
testdata/deps/d23.txt vendored Normal file
View File

@@ -0,0 +1 @@
Text

1
testdata/deps/d3.txt vendored Normal file
View File

@@ -0,0 +1 @@
Text

1
testdata/deps/d31.txt vendored Normal file
View File

@@ -0,0 +1 @@
Text

1
testdata/deps/d32.txt vendored Normal file
View File

@@ -0,0 +1 @@
Text

1
testdata/deps/d33.txt vendored Normal file
View File

@@ -0,0 +1 @@
Text

12
testdata/deps/testdata/TestDeps.golden vendored Normal file
View File

@@ -0,0 +1,12 @@
d1
d11
d12
d13
d2
d21
d22
d23
d3
d31
d32
d33

View File

View File

@@ -0,0 +1 @@
task: Missing schema version in Taskfile "/testdata/empty_taskfile/Taskfile.yml"

View File

@@ -1 +0,0 @@
*.txt

View File

@@ -28,13 +28,13 @@ tasks:
CGO_ENABLED:
sh: echo '0'
cmds:
- echo "GOOS='$GOOS' GOARCH='$GOARCH' CGO_ENABLED='$CGO_ENABLED'" > local.txt
- echo "GOOS='$GOOS' GOARCH='$GOARCH' CGO_ENABLED='$CGO_ENABLED'"
global:
env:
BAR: overridden
cmds:
- echo "FOO='$FOO' BAR='$BAR' BAZ='$BAZ'" > global.txt
- echo "FOO='$FOO' BAR='$BAR' BAZ='$BAZ'"
multiple_type:
env:
@@ -42,15 +42,15 @@ tasks:
BAR: true
BAZ: 1.1
cmds:
- echo "FOO='$FOO' BAR='$BAR' BAZ='$BAZ'" > multiple_type.txt
- echo "FOO='$FOO' BAR='$BAR' BAZ='$BAZ'"
not-overridden:
cmds:
- echo "QUX='$QUX'" > not-overridden.txt
- echo "QUX='$QUX'"
overridden:
cmds:
- echo "QUX='$QUX'" > overridden.txt
- echo "QUX='$QUX'"
dynamic:
silent: true
@@ -58,4 +58,4 @@ tasks:
DYNAMIC_FOO:
sh: echo $FOO
cmds:
- echo "{{ .DYNAMIC_FOO }}" > dynamic.txt
- echo "{{ .DYNAMIC_FOO }}"

1
testdata/env/dynamic.txt vendored Normal file
View File

@@ -0,0 +1 @@
foo

1
testdata/env/global.txt vendored Normal file
View File

@@ -0,0 +1 @@
FOO='foo' BAR='overridden' BAZ='baz'

1
testdata/env/local.txt vendored Normal file
View File

@@ -0,0 +1 @@
GOOS='linux' GOARCH='amd64' CGO_ENABLED='0'

1
testdata/env/multiple_type.txt vendored Normal file
View File

@@ -0,0 +1 @@
FOO='1' BAR='true' BAZ='1.1'

1
testdata/env/not-overridden.txt vendored Normal file
View File

@@ -0,0 +1 @@
QUX='from_os'

1
testdata/env/overridden.txt vendored Normal file
View File

@@ -0,0 +1 @@
QUX='from_taskfile'

View File

@@ -0,0 +1,5 @@
GOOS='linux' GOARCH='amd64' CGO_ENABLED='0'
FOO='foo' BAR='overridden' BAZ='baz'
QUX='from_os'
FOO='1' BAR='true' BAZ='1.1'
foo

View File

@@ -0,0 +1,5 @@
GOOS='linux' GOARCH='amd64' CGO_ENABLED='0'
FOO='foo' BAR='overridden' BAZ='baz'
QUX='from_taskfile'
FOO='1' BAR='true' BAZ='1.1'
foo

View File

@@ -0,0 +1,3 @@
1
2
3

View File

@@ -0,0 +1,3 @@
a
b
c

View File

@@ -0,0 +1,2 @@
task: Failed to parse /testdata/for/cmds/Taskfile.yml:
matrix reference ".NOT_A_LIST" must resolve to a list

View File

@@ -0,0 +1,6 @@
windows/amd64
windows/arm64
linux/amd64
linux/arm64
darwin/amd64
darwin/arm64

View File

@@ -0,0 +1,6 @@
windows/amd64
windows/arm64
linux/amd64
linux/arm64
darwin/amd64
darwin/arm64

View File

@@ -0,0 +1,2 @@
bar
foo

View File

@@ -0,0 +1,2 @@
bar
foo

View File

@@ -0,0 +1,2 @@
foo
bar

View File

@@ -0,0 +1,2 @@
foo
bar

View File

@@ -0,0 +1,2 @@
bar
foo

View File

@@ -0,0 +1,2 @@
foo
bar

View File

@@ -0,0 +1,3 @@
1
2
3

View File

@@ -0,0 +1,3 @@
a
b
c

View File

@@ -0,0 +1,2 @@
matrix reference ".NOT_A_LIST" must resolve to a list
task: Failed to parse /testdata/for/deps/Taskfile.yml:

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,6 @@
darwin/amd64
darwin/arm64
linux/amd64
linux/arm64
windows/amd64
windows/arm64

View File

@@ -0,0 +1,6 @@
darwin/amd64
darwin/arm64
linux/amd64
linux/arm64
windows/amd64
windows/arm64

View File

@@ -0,0 +1,2 @@
bar
foo

View File

@@ -0,0 +1,2 @@
bar
foo

View File

@@ -0,0 +1,2 @@
bar
foo

View File

@@ -0,0 +1,2 @@
bar
foo

View File

@@ -0,0 +1,2 @@
bar
foo

View File

@@ -0,0 +1,2 @@
bar
foo

View File

@@ -0,0 +1,2 @@
task: Available tasks for this project:
* foo: task description

View File

@@ -0,0 +1 @@
task: Task "foobar" is not up-to-date

View File

View File

@@ -0,0 +1 @@
task: Task "foobar" is up to date

View File

@@ -0,0 +1,3 @@
task: foobar
description

View File

@@ -0,0 +1 @@
task: Task "foobar" is up to date

View File

@@ -0,0 +1 @@
task: Task "foobaz" is up to date

View File

@@ -0,0 +1,3 @@
task: Available tasks for this project:
* bar: task has desc with bar-var
* foo: task has desc with foo-var

View File

@@ -0,0 +1,4 @@
task: Available tasks for this project:
* doo:
* foo: foo has desc and label
* voo:

View File

@@ -0,0 +1,2 @@
task: Available tasks for this project:
* foo: foo has desc and label

View File

@@ -1 +0,0 @@
*.txt

View File

@@ -12,33 +12,33 @@ tasks:
GERMAN: "Welt!"
deps:
- task: write-file
vars: {CONTENT: Dependence1, FILE: dep1.txt}
vars: {CONTENT: Dependence1}
- task: write-file
vars: {CONTENT: Dependence2, FILE: dep2.txt}
vars: {CONTENT: Dependence2}
- task: write-file
vars: {CONTENT: "{{.SPANISH|replace \"mundo\" \"dependencia\"}}", FILE: spanish-dep.txt}
vars: {CONTENT: "{{.SPANISH|replace \"mundo\" \"dependencia\"}}"}
cmds:
- task: write-file
vars: {CONTENT: Hello, FILE: hello.txt}
vars: {CONTENT: Hello}
- task: write-file
vars: {CONTENT: "$echo 'World'", FILE: world.txt}
vars: {CONTENT: "$echo 'World'"}
- task: write-file
vars: {CONTENT: "!", FILE: exclamation.txt}
vars: {CONTENT: "!"}
- task: write-file
vars: {CONTENT: "{{.SPANISH}}", FILE: spanish.txt}
vars: {CONTENT: "{{.SPANISH}}"}
- task: write-file
vars: {CONTENT: "{{.PORTUGUESE}}", FILE: portuguese.txt}
vars: {CONTENT: "{{.PORTUGUESE}}"}
- task: write-file
vars: {CONTENT: "{{.GERMAN}}", FILE: german.txt}
vars: {CONTENT: "{{.GERMAN}}"}
- task: non-default
write-file:
cmds:
- echo {{.CONTENT}} > {{.FILE}}
- echo {{.CONTENT}}
non-default:
vars:
PORTUGUESE: "{{.PORTUGUESE_HELLO_WORLD}}"
cmds:
- task: write-file
vars: {CONTENT: "{{.PORTUGUESE}}", FILE: portuguese2.txt}
vars: {CONTENT: "{{.PORTUGUESE}}"}

1
testdata/params/dep1.txt vendored Normal file
View File

@@ -0,0 +1 @@
Dependence1

1
testdata/params/dep2.txt vendored Normal file
View File

@@ -0,0 +1 @@
Dependence2

1
testdata/params/exclamation.txt vendored Normal file
View File

@@ -0,0 +1 @@
!

1
testdata/params/german.txt vendored Normal file
View File

@@ -0,0 +1 @@
Welt!

1
testdata/params/hello.txt vendored Normal file
View File

@@ -0,0 +1 @@
Hello

1
testdata/params/portuguese.txt vendored Normal file
View File

@@ -0,0 +1 @@
Olá, mundo!

1
testdata/params/portuguese2.txt vendored Normal file
View File

@@ -0,0 +1 @@
Olá, mundo!

1
testdata/params/spanish-dep.txt vendored Normal file
View File

@@ -0,0 +1 @@
¡Holla dependencia!

1
testdata/params/spanish.txt vendored Normal file
View File

@@ -0,0 +1 @@
¡Holla mundo!

View File

@@ -0,0 +1,10 @@
!
Dependence1
Dependence2
Hello
Olá, mundo!
Olá, mundo!
Welt!
World
¡Holla dependencia!
¡Holla mundo!

1
testdata/params/world.txt vendored Normal file
View File

@@ -0,0 +1 @@
World

View File

@@ -0,0 +1 @@
task: precondition not met

View File

@@ -0,0 +1 @@
task: 1 != 0 obviously!

View File

@@ -0,0 +1 @@
task: Failed to run task "executes_failing_task_as_cmd": task: precondition not met

View File

@@ -0,0 +1 @@
task: 1 != 0 obviously!

View File

@@ -0,0 +1 @@
task: precondition not met

View File

@@ -0,0 +1 @@
task: 1 != 0 obviously!

View File

@@ -0,0 +1,3 @@
Do you want to continue? [assuming yes]
task: [foo] echo 'foo'
foo

View File

@@ -0,0 +1 @@
task: Task "foo" cancelled by user

View File

@@ -0,0 +1 @@
Do you want to continue? [y/N]:

View File

@@ -0,0 +1 @@
task: Task "foo" cancelled by user

View File

@@ -0,0 +1 @@
Do you want to continue? [y/N]:

View File

@@ -0,0 +1 @@
task: Task "foo" cancelled by user

View File

@@ -0,0 +1 @@
Do you want to continue? [y/N]:

View File

@@ -0,0 +1,2 @@
Do you want to continue? [y/N]: task: [foo] echo 'foo'
foo

View File

@@ -0,0 +1,2 @@
Do you want to continue? [y/N]: task: [foo] echo 'foo'
foo

View File

@@ -0,0 +1 @@
task: Task "foo" cancelled by user

View File

@@ -0,0 +1 @@
Do you want to continue? [y/N]:

View File

@@ -0,0 +1,2 @@
Do you want to continue? [y/N]: task: [foo] echo 'foo'
foo

View File

@@ -0,0 +1,2 @@
Do you want to continue? [y/N]: task: [show-prompt] echo 'show-prompt'
show-prompt

Some files were not shown because too many files have changed in this diff Show More