Skip to content

Commit 32e0107

Browse files
authored
This adds a test to bug 508 (#516)
* This adds a test to bug 508 It fails against master before merging the patch on #509 (review)
1 parent 0800736 commit 32e0107

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

mage/main_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1877,6 +1877,28 @@ func TestWrongDependency(t *testing.T) {
18771877
}
18781878
}
18791879

1880+
// Regression tests, add tests to ensure we do not regress on known issues.
1881+
1882+
// TestBug508 is a regression test for: Bug: using Default with imports selects first matching func by name
1883+
func TestBug508(t *testing.T) {
1884+
stdout := &bytes.Buffer{}
1885+
stderr := &bytes.Buffer{}
1886+
inv := Invocation{
1887+
Dir: "./testdata/bug508",
1888+
Stderr: stderr,
1889+
Stdout: stdout,
1890+
}
1891+
code := Invoke(inv)
1892+
if code != 0 {
1893+
t.Log(stderr.String())
1894+
t.Fatalf("expected 0, but got %v", code)
1895+
}
1896+
expected := "test\n"
1897+
if stdout.String() != expected {
1898+
t.Fatalf("expected %q, but got %q", expected, stdout.String())
1899+
}
1900+
}
1901+
18801902
// / This code liberally borrowed from https://github.com/rsc/goversion/blob/master/version/exe.go
18811903

18821904
type (
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package deps
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/magefile/mage/mg"
7+
)
8+
9+
// All code in this package belongs to @na4ma4 in GitHub https://github.com/na4ma4/magefile-test-import
10+
// reproduced here for ease of testing regression on bug 508
11+
12+
type Docker mg.Namespace
13+
14+
func (Docker) Test() {
15+
fmt.Println("docker")
16+
}
17+
18+
func Test() {
19+
fmt.Println("test")
20+
}

mage/testdata/bug508/magefile.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//go:build mage
2+
// +build mage
3+
4+
package main
5+
6+
import (
7+
//mage:import
8+
"github.com/magefile/mage/mage/testdata/bug508/deps"
9+
)
10+
11+
var Default = deps.Test

0 commit comments

Comments
 (0)