1
0
mirror of https://github.com/go-task/task.git synced 2025-11-25 22:32:55 +02:00

for task up to date check both status and sources (#1035)

* remove redundant if statement

* add subtests to TestStatusChecksum
This commit is contained in:
Harel Wahnich
2023-03-06 08:16:41 +02:00
committed by GitHub
parent d4ed7c3cfc
commit 99ab2a4d62
3 changed files with 49 additions and 32 deletions

View File

@@ -447,36 +447,43 @@ func TestGenerates(t *testing.T) {
func TestStatusChecksum(t *testing.T) {
const dir = "testdata/checksum"
files := []string{
"generated.txt",
".task/checksum/build",
tests := []struct {
files []string
task string
}{
{[]string{"generated.txt", ".task/checksum/build"}, "build"},
{[]string{"generated.txt", ".task/checksum/build-with-status"}, "build-with-status"},
}
for _, f := range files {
_ = os.Remove(filepathext.SmartJoin(dir, f))
for _, test := range tests {
t.Run(test.task, func(t *testing.T) {
for _, f := range test.files {
_ = os.Remove(filepathext.SmartJoin(dir, f))
_, err := os.Stat(filepathext.SmartJoin(dir, f))
assert.Error(t, err)
_, err := os.Stat(filepathext.SmartJoin(dir, f))
assert.Error(t, err)
}
var buff bytes.Buffer
e := task.Executor{
Dir: dir,
TempDir: filepathext.SmartJoin(dir, ".task"),
Stdout: &buff,
Stderr: &buff,
}
assert.NoError(t, e.Setup())
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: test.task}))
for _, f := range test.files {
_, err := os.Stat(filepathext.SmartJoin(dir, f))
assert.NoError(t, err)
}
buff.Reset()
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: test.task}))
assert.Equal(t, `task: Task "`+test.task+`" is up to date`+"\n", buff.String())
})
}
var buff bytes.Buffer
e := task.Executor{
Dir: dir,
TempDir: filepathext.SmartJoin(dir, ".task"),
Stdout: &buff,
Stderr: &buff,
}
assert.NoError(t, e.Setup())
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "build"}))
for _, f := range files {
_, err := os.Stat(filepathext.SmartJoin(dir, f))
assert.NoError(t, err)
}
buff.Reset()
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "build"}))
assert.Equal(t, `task: Task "build" is up to date`+"\n", buff.String())
}
func TestAlias(t *testing.T) {