mirror of
https://github.com/go-task/task.git
synced 2025-01-20 04:59:37 +02:00
Evaluate sources also if status is up-to-date
This commit is contained in:
parent
0ae1681d9c
commit
58c69e36a1
29
status.go
29
status.go
@ -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) {
|
||||
areChecksGiven := false
|
||||
|
||||
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 err != nil {
|
||||
return false, err
|
||||
if len(t.Sources) > 0 {
|
||||
areChecksGiven = true
|
||||
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 {
|
||||
|
42
task_test.go
42
task_test.go
@ -248,12 +248,18 @@ func TestDeps(t *testing.T) {
|
||||
|
||||
func TestStatus(t *testing.T) {
|
||||
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 {
|
||||
t.Errorf("File should not exist: %v", err)
|
||||
for _, f := range files {
|
||||
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
|
||||
@ -265,17 +271,33 @@ func TestStatus(t *testing.T) {
|
||||
}
|
||||
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-bar"}))
|
||||
|
||||
if _, err := os.Stat(file); err != nil {
|
||||
t.Errorf("File should exist: %v", err)
|
||||
for _, f := range files {
|
||||
if _, err := os.Stat(filepath.Join(dir, f)); err != nil {
|
||||
t.Errorf("File should exist: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
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" {
|
||||
t.Errorf("Wrong output message: %s", buff.String())
|
||||
}
|
||||
// all: 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()
|
||||
// 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) {
|
||||
|
12
testdata/status/Taskfile.yml
vendored
12
testdata/status/Taskfile.yml
vendored
@ -4,5 +4,15 @@ tasks:
|
||||
gen-foo:
|
||||
cmds:
|
||||
- touch foo.txt
|
||||
sources:
|
||||
- ./foo.txt
|
||||
status:
|
||||
- test -f foo.txt
|
||||
- test 1 = 0
|
||||
|
||||
gen-bar:
|
||||
cmds:
|
||||
- touch bar.txt
|
||||
sources:
|
||||
- ./bar.txt
|
||||
status:
|
||||
- test 1 = 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user