mirror of
https://github.com/go-task/task.git
synced 2025-05-19 22:33:35 +02:00
parent
86e0496555
commit
2a2dfce137
20
task.go
20
task.go
@ -34,6 +34,7 @@ type Task struct {
|
|||||||
Desc string
|
Desc string
|
||||||
Sources []string
|
Sources []string
|
||||||
Generates []string
|
Generates []string
|
||||||
|
Status []string
|
||||||
Dir string
|
Dir string
|
||||||
Vars map[string]string
|
Vars map[string]string
|
||||||
Set string
|
Set string
|
||||||
@ -140,6 +141,25 @@ func (t *Task) runDeps(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *Task) isUpToDate() (bool, error) {
|
func (t *Task) isUpToDate() (bool, error) {
|
||||||
|
if len(t.Status) > 0 {
|
||||||
|
environ, err := t.getEnviron()
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, s := range t.Status {
|
||||||
|
err = execext.RunCommand(&execext.RunCommandOptions{
|
||||||
|
Command: s,
|
||||||
|
Dir: t.Dir,
|
||||||
|
Env: environ,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
if len(t.Sources) == 0 || len(t.Generates) == 0 {
|
if len(t.Sources) == 0 || len(t.Generates) == 0 {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
32
task_test.go
32
task_test.go
@ -1,6 +1,7 @@
|
|||||||
package task_test
|
package task_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -112,3 +113,34 @@ func TestTaskCall(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestStatus(t *testing.T) {
|
||||||
|
const dir = "testdata/status"
|
||||||
|
var file = filepath.Join(dir, "foo.txt")
|
||||||
|
|
||||||
|
_ = os.Remove(file)
|
||||||
|
|
||||||
|
if _, err := os.Stat(file); err == nil {
|
||||||
|
t.Errorf("File should not exists: %v", err)
|
||||||
|
}
|
||||||
|
c := exec.Command("task", "gen-foo")
|
||||||
|
c.Dir = dir
|
||||||
|
if err := c.Run(); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
if _, err := os.Stat(file); err != nil {
|
||||||
|
t.Errorf("File should exists: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
buff := bytes.NewBuffer(nil)
|
||||||
|
c = exec.Command("task", "gen-foo")
|
||||||
|
c.Dir = dir
|
||||||
|
c.Stderr = buff
|
||||||
|
c.Stdout = buff
|
||||||
|
if err := c.Run(); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
if buff.String() != `task: Task "gen-foo" is up to date`+"\n" {
|
||||||
|
t.Errorf("Wrong output message: %s", buff.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
1
testdata/status/.gitignore
vendored
Normal file
1
testdata/status/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
*.txt
|
5
testdata/status/Taskfile.yml
vendored
Normal file
5
testdata/status/Taskfile.yml
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
gen-foo:
|
||||||
|
cmds:
|
||||||
|
- touch foo.txt
|
||||||
|
status:
|
||||||
|
- test -f foo.txt
|
Loading…
x
Reference in New Issue
Block a user