2017-03-25 21:06:49 +02:00
|
|
|
package task_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/go-task/task"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCyclicDepCheck(t *testing.T) {
|
2017-06-04 21:02:04 +02:00
|
|
|
isCyclic := &task.Executor{
|
2017-06-04 21:41:38 +02:00
|
|
|
Tasks: task.Tasks{
|
2017-06-04 21:02:04 +02:00
|
|
|
"task-a": &task.Task{
|
2017-07-02 20:30:50 +02:00
|
|
|
Deps: []*task.Dep{&task.Dep{Task: "task-b"}},
|
2017-06-04 21:02:04 +02:00
|
|
|
},
|
|
|
|
"task-b": &task.Task{
|
2017-07-02 20:30:50 +02:00
|
|
|
Deps: []*task.Dep{&task.Dep{Task: "task-a"}},
|
2017-06-04 21:02:04 +02:00
|
|
|
},
|
2017-03-25 21:06:49 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-06-04 21:02:04 +02:00
|
|
|
if !isCyclic.HasCyclicDep() {
|
2017-03-25 21:06:49 +02:00
|
|
|
t.Error("Task should be cyclic")
|
|
|
|
}
|
|
|
|
|
2017-06-04 21:02:04 +02:00
|
|
|
isNotCyclic := &task.Executor{
|
2017-06-04 21:41:38 +02:00
|
|
|
Tasks: task.Tasks{
|
2017-06-04 21:02:04 +02:00
|
|
|
"task-a": &task.Task{
|
2017-07-02 20:30:50 +02:00
|
|
|
Deps: []*task.Dep{&task.Dep{Task: "task-c"}},
|
2017-06-04 21:02:04 +02:00
|
|
|
},
|
|
|
|
"task-b": &task.Task{
|
2017-07-02 20:30:50 +02:00
|
|
|
Deps: []*task.Dep{&task.Dep{Task: "task-c"}},
|
2017-06-04 21:02:04 +02:00
|
|
|
},
|
|
|
|
"task-c": &task.Task{},
|
2017-03-25 21:06:49 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-06-04 21:02:04 +02:00
|
|
|
if isNotCyclic.HasCyclicDep() {
|
2017-03-25 21:06:49 +02:00
|
|
|
t.Error("Task should not be cyclic")
|
|
|
|
}
|
|
|
|
}
|