diff --git a/mage/main_test.go b/mage/main_test.go index 07e598e..8b21fb4 100644 --- a/mage/main_test.go +++ b/mage/main_test.go @@ -1877,6 +1877,28 @@ func TestWrongDependency(t *testing.T) { } } +// Regression tests, add tests to ensure we do not regress on known issues. + +// TestBug508 is a regression test for: Bug: using Default with imports selects first matching func by name +func TestBug508(t *testing.T) { + stdout := &bytes.Buffer{} + stderr := &bytes.Buffer{} + inv := Invocation{ + Dir: "./testdata/bug508", + Stderr: stderr, + Stdout: stdout, + } + code := Invoke(inv) + if code != 0 { + t.Log(stderr.String()) + t.Fatalf("expected 0, but got %v", code) + } + expected := "test\n" + if stdout.String() != expected { + t.Fatalf("expected %q, but got %q", expected, stdout.String()) + } +} + // / This code liberally borrowed from https://github.com/rsc/goversion/blob/master/version/exe.go type ( diff --git a/mage/testdata/bug508/deps/ambiguousimports.go b/mage/testdata/bug508/deps/ambiguousimports.go new file mode 100644 index 0000000..631e260 --- /dev/null +++ b/mage/testdata/bug508/deps/ambiguousimports.go @@ -0,0 +1,20 @@ +package deps + +import ( + "fmt" + + "github.com/magefile/mage/mg" +) + +// All code in this package belongs to @na4ma4 in GitHub https://github.com/na4ma4/magefile-test-import +// reproduced here for ease of testing regression on bug 508 + +type Docker mg.Namespace + +func (Docker) Test() { + fmt.Println("docker") +} + +func Test() { + fmt.Println("test") +} diff --git a/mage/testdata/bug508/magefile.go b/mage/testdata/bug508/magefile.go new file mode 100644 index 0000000..65870a7 --- /dev/null +++ b/mage/testdata/bug508/magefile.go @@ -0,0 +1,11 @@ +//go:build mage +// +build mage + +package main + +import ( + //mage:import + "github.com/magefile/mage/mage/testdata/bug508/deps" +) + +var Default = deps.Test