Skip to content

Commit

Permalink
Correct test input code to support older go versions (#490)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
perrito666 committed Nov 18, 2023
1 parent 0fddccb commit 2385abb
Show file tree
Hide file tree
Showing 46 changed files with 71 additions and 26 deletions.
3 changes: 2 additions & 1 deletion bootstrap.go
@@ -1,4 +1,5 @@
//+build ignore
//go:build ignore
// +build ignore

package main

Expand Down
3 changes: 2 additions & 1 deletion install_test.go
@@ -1,4 +1,5 @@
//+build CI
//go:build CI
// +build CI

package main

Expand Down
8 changes: 4 additions & 4 deletions mage/main_test.go
Expand Up @@ -1739,14 +1739,14 @@ func TestGoModules(t *testing.T) {
t.Fatal(err)
}
defer os.RemoveAll(dir)
err = ioutil.WriteFile(filepath.Join(dir, "magefile.go"), []byte(`//+build mage
// beware, mage builds in go versions older than 1.17 so both build tag formats need to be present
err = ioutil.WriteFile(filepath.Join(dir, "magefile.go"), []byte(`//go:build mage
// +build mage
package main
import "golang.org/x/text/unicode/norm"
func Test() {
print("unicode version: " + norm.Version)
print("nothing is imported here for >1.17 compatibility")
}
`), 0600)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion mage/template.go
Expand Up @@ -3,7 +3,8 @@ package mage
// this template uses the "data"

// var only for tests
var mageMainfileTplString = `// +build ignore
var mageMainfileTplString = `//go:build ignore
// +build ignore
package main
Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/alias/magefile.go
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/args/magefile.go
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
1 change: 1 addition & 0 deletions mage/testdata/command.go
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
1 change: 1 addition & 0 deletions mage/testdata/compiled/custom.go
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

// Compiled package description.
Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/context/context.go
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
1 change: 1 addition & 0 deletions mage/testdata/error.go
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
1 change: 1 addition & 0 deletions mage/testdata/func.go
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
1 change: 1 addition & 0 deletions mage/testdata/goos_magefiles/magefile_nonwindows.go
@@ -1,3 +1,4 @@
//go:build mage && !windows
// +build mage,!windows

package main
Expand Down
1 change: 1 addition & 0 deletions mage/testdata/goos_magefiles/magefile_windows.go
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
1 change: 1 addition & 0 deletions mage/testdata/invalid_alias/magefile.go
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
1 change: 1 addition & 0 deletions mage/testdata/keep_flag/magefile.go
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
1 change: 1 addition & 0 deletions mage/testdata/list/command.go
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

// This is a comment on the package which should get turned into output with the
Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/mageimport/magefile.go
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
1 change: 1 addition & 0 deletions mage/testdata/mageimport/oneline/magefile.go
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package sametarget
Expand Down
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/mageimport/tagged/magefile.go
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/mageimport/tagged/pkg/mage.go
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package pkg

Expand Down
1 change: 1 addition & 0 deletions mage/testdata/mageimport/trailing/magefile.go
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
1 change: 1 addition & 0 deletions mage/testdata/main.go
@@ -1,3 +1,4 @@
//go:build ignore
// +build ignore

package main
Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/mixed_lib_files/mage_helpers.go
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/mixed_lib_files/magefile.go
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
1 change: 1 addition & 0 deletions mage/testdata/mixed_lib_files/subdir/magefile.go
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/mixed_main_files/mage_helpers.go
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/mixed_main_files/magefile.go
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/namespaces/magefile.go
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/no_default/magefile.go
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
1 change: 1 addition & 0 deletions mage/testdata/onlyStdLib/command.go
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
1 change: 1 addition & 0 deletions mage/testdata/panic.go
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/setdir/setdir.go
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/setworkdir/magefile.go
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/signals/signals.go
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/transitiveDeps/magefile.go
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/wrong_dep/magefile.go
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
1 change: 1 addition & 0 deletions parse/testdata/alias.go
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
1 change: 1 addition & 0 deletions parse/testdata/command.go
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
1 change: 1 addition & 0 deletions parse/testdata/func.go
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
3 changes: 2 additions & 1 deletion parse/testdata/importself/magefile.go
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
1 change: 1 addition & 0 deletions parse/testdata/repeating_synopsis.go
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
3 changes: 2 additions & 1 deletion parse/testdata/subcommand_1.9.go
@@ -1,4 +1,5 @@
//+build mage,go1.9
//go:build mage && go1.9
// +build mage,go1.9

package main

Expand Down
1 change: 1 addition & 0 deletions parse/testdata/subcommands.go
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
1 change: 1 addition & 0 deletions site/content/zeroInstall/_index.en.md
Expand Up @@ -16,6 +16,7 @@ Now you can `go run mage.go <target>` and it'll work just as if you ran
`mage <target>`:

```go
//go:build ignore
// +build ignore

package main
Expand Down

0 comments on commit 2385abb

Please sign in to comment.