Skip to content

Commit

Permalink
This adds a test to bug 508 (#516)
Browse files Browse the repository at this point in the history
* This adds a test to bug 508

It fails against master before merging the patch on #509 (review)
  • Loading branch information
perrito666 authored Nov 24, 2024
1 parent 0800736 commit 32e0107
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
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

0 comments on commit 32e0107

Please sign in to comment.