1
0
mirror of https://github.com/go-task/task.git synced 2025-07-17 01:43:07 +02:00

Merge pull request #477 from mrngsht/sources_evaluation

Evaluate sources also if status is up-to-date
This commit is contained in:
Andrey Nering
2021-07-10 21:54:47 -03:00
committed by GitHub
3 changed files with 67 additions and 16 deletions

View File

@ -29,16 +29,35 @@ func (e *Executor) Status(ctx context.Context, calls ...taskfile.Call) error {
} }
func (e *Executor) isTaskUpToDate(ctx context.Context, t *taskfile.Task) (bool, error) { func (e *Executor) isTaskUpToDate(ctx context.Context, t *taskfile.Task) (bool, error) {
areChecksGiven := false
if len(t.Status) > 0 { if len(t.Status) > 0 {
return e.isTaskUpToDateStatus(ctx, t) areChecksGiven = true
isUpToDate, err := e.isTaskUpToDateStatus(ctx, t)
if err != nil {
return false, err
}
if !isUpToDate {
return false, nil
}
} }
checker, err := e.getStatusChecker(t) if len(t.Sources) > 0 {
if err != nil { areChecksGiven = true
return false, err checker, err := e.getStatusChecker(t)
if err != nil {
return false, err
}
isUpToDate, err := checker.IsUpToDate()
if err != nil {
return false, err
}
if !isUpToDate {
return false, nil
}
} }
return checker.IsUpToDate() return areChecksGiven, nil
} }
func (e *Executor) statusOnError(t *taskfile.Task) error { func (e *Executor) statusOnError(t *taskfile.Task) error {

View File

@ -252,12 +252,18 @@ func TestDeps(t *testing.T) {
func TestStatus(t *testing.T) { func TestStatus(t *testing.T) {
const dir = "testdata/status" const dir = "testdata/status"
var file = filepath.Join(dir, "foo.txt")
_ = os.Remove(file) files := []string{
"foo.txt",
"bar.txt",
}
if _, err := os.Stat(file); err == nil { for _, f := range files {
t.Errorf("File should not exist: %v", err) path := filepath.Join(dir, f)
_ = os.Remove(path)
if _, err := os.Stat(path); err == nil {
t.Errorf("File should not exist: %v", err)
}
} }
var buff bytes.Buffer var buff bytes.Buffer
@ -269,17 +275,33 @@ func TestStatus(t *testing.T) {
} }
assert.NoError(t, e.Setup()) assert.NoError(t, e.Setup())
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "gen-foo"})) assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "gen-foo"}))
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "gen-bar"}))
if _, err := os.Stat(file); err != nil { for _, f := range files {
t.Errorf("File should exist: %v", err) if _, err := os.Stat(filepath.Join(dir, f)); err != nil {
t.Errorf("File should exist: %v", err)
}
} }
e.Silent = false e.Silent = false
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "gen-foo"}))
if buff.String() != `task: Task "gen-foo" is up to date`+"\n" { // all: not up-to-date
t.Errorf("Wrong output message: %s", buff.String()) assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "gen-foo"}))
} assert.Equal(t, "task: [gen-foo] touch foo.txt", strings.TrimSpace(buff.String()))
buff.Reset()
// status: not up-to-date
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "gen-foo"}))
assert.Equal(t, "task: [gen-foo] touch foo.txt", strings.TrimSpace(buff.String()))
buff.Reset()
// sources: not up-to-date
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "gen-bar"}))
assert.Equal(t, "task: [gen-bar] touch bar.txt", strings.TrimSpace(buff.String()))
buff.Reset()
// all: up-to-date
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "gen-bar"}))
assert.Equal(t, `task: Task "gen-bar" is up to date`, strings.TrimSpace(buff.String()))
buff.Reset()
} }
func TestPrecondition(t *testing.T) { func TestPrecondition(t *testing.T) {

View File

@ -4,5 +4,15 @@ tasks:
gen-foo: gen-foo:
cmds: cmds:
- touch foo.txt - touch foo.txt
sources:
- ./foo.txt
status: status:
- test -f foo.txt - test 1 = 0
gen-bar:
cmds:
- touch bar.txt
sources:
- ./bar.txt
status:
- test 1 = 1