mirror of
https://github.com/go-task/task.git
synced 2024-12-04 10:24:45 +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:
parent
d4ed7c3cfc
commit
99ab2a4d62
13
status.go
13
status.go
@ -29,9 +29,8 @@ func (e *Executor) Status(ctx context.Context, calls ...taskfile.Call) error {
|
||||
}
|
||||
|
||||
func (e *Executor) isTaskUpToDate(ctx context.Context, t *taskfile.Task) (bool, error) {
|
||||
if len(t.Status) == 0 && len(t.Sources) == 0 {
|
||||
return false, nil
|
||||
}
|
||||
isUpToDateStatus := true
|
||||
isUpToDateChecker := true
|
||||
|
||||
if len(t.Status) > 0 {
|
||||
isUpToDate, err := e.isTaskUpToDateStatus(ctx, t)
|
||||
@ -39,7 +38,7 @@ func (e *Executor) isTaskUpToDate(ctx context.Context, t *taskfile.Task) (bool,
|
||||
return false, err
|
||||
}
|
||||
if !isUpToDate {
|
||||
return false, nil
|
||||
isUpToDateStatus = false
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,11 +52,13 @@ func (e *Executor) isTaskUpToDate(ctx context.Context, t *taskfile.Task) (bool,
|
||||
return false, err
|
||||
}
|
||||
if !isUpToDate {
|
||||
return false, nil
|
||||
isUpToDateChecker = false
|
||||
}
|
||||
}
|
||||
|
||||
return true, nil
|
||||
isUpToDate := isUpToDateStatus && isUpToDateChecker
|
||||
|
||||
return isUpToDate, nil
|
||||
}
|
||||
|
||||
func (e *Executor) statusOnError(t *taskfile.Task) error {
|
||||
|
59
task_test.go
59
task_test.go
@ -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) {
|
||||
|
9
testdata/checksum/Taskfile.yml
vendored
9
testdata/checksum/Taskfile.yml
vendored
@ -10,3 +10,12 @@ tasks:
|
||||
generates:
|
||||
- ./generated.txt
|
||||
method: checksum
|
||||
|
||||
build-with-status:
|
||||
cmds:
|
||||
- cp ./source.txt ./generated.txt
|
||||
sources:
|
||||
- ./source.txt
|
||||
status:
|
||||
- test -f ./generated.txt
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user