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

This adds a test to bug 508 #516

Merged
merged 6 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions mage/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
20 changes: 20 additions & 0 deletions mage/testdata/bug508/deps/ambiguousimports.go
Original file line number Diff line number Diff line change
@@ -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")
}
11 changes: 11 additions & 0 deletions mage/testdata/bug508/magefile.go
Original file line number Diff line number Diff line change
@@ -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
Loading