Skip to content

Commit 2385abb

Browse files
authored
Correct test input code to support older go versions (#490)
Samples used for testing need to have build tags for new and old style: ``` //go:build tag // +build tag ``` The particular problem here seems to be that 1.16 was actually importing the package referred in the `TestGoModules` test (`import "golang.org/x/text/unicode/norm"`) which, in the CI system's version lacks an old style go tag comment. Hence go complaining of a `//go:build` without a `// +build`. I made all files bi-tagged for consistency.
1 parent 0fddccb commit 2385abb

File tree

46 files changed

+71
-26
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+71
-26
lines changed

bootstrap.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//+build ignore
1+
//go:build ignore
2+
// +build ignore
23

34
package main
45

install_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//+build CI
1+
//go:build CI
2+
// +build CI
23

34
package main
45

mage/main_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,14 +1739,14 @@ func TestGoModules(t *testing.T) {
17391739
t.Fatal(err)
17401740
}
17411741
defer os.RemoveAll(dir)
1742-
err = ioutil.WriteFile(filepath.Join(dir, "magefile.go"), []byte(`//+build mage
1742+
// beware, mage builds in go versions older than 1.17 so both build tag formats need to be present
1743+
err = ioutil.WriteFile(filepath.Join(dir, "magefile.go"), []byte(`//go:build mage
1744+
// +build mage
17431745
17441746
package main
17451747
1746-
import "golang.org/x/text/unicode/norm"
1747-
17481748
func Test() {
1749-
print("unicode version: " + norm.Version)
1749+
print("nothing is imported here for >1.17 compatibility")
17501750
}
17511751
`), 0600)
17521752
if err != nil {

mage/template.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ package mage
33
// this template uses the "data"
44

55
// var only for tests
6-
var mageMainfileTplString = `// +build ignore
6+
var mageMainfileTplString = `//go:build ignore
7+
// +build ignore
78
89
package main
910

mage/testdata/alias/magefile.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//+build mage
1+
//go:build mage
2+
// +build mage
23

34
package main
45

mage/testdata/args/magefile.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//+build mage
1+
//go:build mage
2+
// +build mage
23

34
package main
45

mage/testdata/command.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build mage
12
// +build mage
23

34
package main

mage/testdata/compiled/custom.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build mage
12
// +build mage
23

34
// Compiled package description.

mage/testdata/context/context.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//+build mage
1+
//go:build mage
2+
// +build mage
23

34
package main
45

mage/testdata/error.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build mage
12
// +build mage
23

34
package main

0 commit comments

Comments
 (0)