From ac48ee066e1987993c94733935d291c0107db36d Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Sat, 8 Jul 2017 10:25:15 -0300 Subject: [PATCH] fix panic for invalid task in cyclic dep detection resolves partly #37 --- cyclic.go | 7 ++++++- cyclic_test.go | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/cyclic.go b/cyclic.go index 07726528..1fb395ae 100644 --- a/cyclic.go +++ b/cyclic.go @@ -13,7 +13,12 @@ func (e *Executor) CheckCyclicDep() error { defer delete(visits, name) for _, d := range t.Deps { - if err := checkCyclicDep(d.Task, e.Tasks[d.Task]); err != nil { + // FIXME: ignoring by now. should return an error instead? + task, ok := e.Tasks[d.Task] + if !ok { + continue + } + if err := checkCyclicDep(d.Task, task); err != nil { return err } } diff --git a/cyclic_test.go b/cyclic_test.go index 88b20ef0..602378cd 100644 --- a/cyclic_test.go +++ b/cyclic_test.go @@ -35,4 +35,22 @@ func TestCyclicDepCheck(t *testing.T) { } assert.NoError(t, isNotCyclic.CheckCyclicDep()) + + inexixtentTask := &task.Executor{ + Tasks: task.Tasks{ + "task-a": &task.Task{ + Deps: []*task.Dep{&task.Dep{Task: "invalid-task"}}, + }, + }, + } + + // FIXME: by now Task should ignore non existent tasks + // in the future we should improve the detection of + // tasks called with interpolation? + // task: + // deps: + // - task: "task{{.VARIABLE}}" + // vars: + // VARIABLE: something + assert.NoError(t, inexixtentTask.CheckCyclicDep()) }