Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect deps that have already been invoked #346

Merged
merged 5 commits into from Jan 16, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions mg/deps.go
Expand Up @@ -130,6 +130,9 @@ func runDeps(ctx context.Context, fns []Fn) {
func checkFns(fns []interface{}) []Fn {
funcs := make([]Fn, len(fns))
for i, f := range fns {
if f == nil {
panic("A dependency of the current target was defined improperly, with parenthesis. Dependencies should be defined as mg.Deps(MyDep), not mg.Deps(MyDep())")
natefinch marked this conversation as resolved.
Show resolved Hide resolved
}
if fn, ok := f.(Fn); ok {
funcs[i] = fn
continue
Expand Down
21 changes: 21 additions & 0 deletions mg/deps_internal_test.go
Expand Up @@ -2,6 +2,7 @@ package mg

import (
"bytes"
"fmt"
"log"
"os"
"strings"
Expand Down Expand Up @@ -33,3 +34,23 @@ func bar() {
}

func baz() {}

func TestDepWasNotInvoked(t *testing.T) {
fn1 := func() error {
return nil
}
defer func() {
err := recover()
if err == nil {
t.Fatal("expected panic, but didn't get one")
}
gotErr := fmt.Sprint(err)
wantErr := "A dependency of the current target was defined improperly, with parenthesis"
if !strings.Contains(gotErr, wantErr) {
t.Fatalf(`expected to get "%s" but got "%s"`, wantErr, gotErr)
}
}()
func(fns ...interface{}) {
checkFns(fns)
}(fn1())
}