From 2385abb49a1fa8f1e160556889f4ba9704a2ddb7 Mon Sep 17 00:00:00 2001 From: Horacio Duran Date: Sat, 18 Nov 2023 18:05:41 +0100 Subject: [PATCH] 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. --- bootstrap.go | 3 ++- install_test.go | 3 ++- mage/main_test.go | 8 ++++---- mage/template.go | 3 ++- mage/testdata/alias/magefile.go | 3 ++- mage/testdata/args/magefile.go | 3 ++- mage/testdata/command.go | 1 + mage/testdata/compiled/custom.go | 1 + mage/testdata/context/context.go | 3 ++- mage/testdata/error.go | 1 + mage/testdata/func.go | 1 + mage/testdata/goos_magefiles/magefile_nonwindows.go | 1 + mage/testdata/goos_magefiles/magefile_windows.go | 1 + mage/testdata/invalid_alias/magefile.go | 1 + mage/testdata/keep_flag/magefile.go | 1 + mage/testdata/list/command.go | 1 + mage/testdata/mageimport/magefile.go | 3 ++- mage/testdata/mageimport/oneline/magefile.go | 1 + .../mageimport/samenamespace/duptargets/magefile.go | 1 + .../mageimport/samenamespace/uniquetargets/magefile.go | 1 + mage/testdata/mageimport/tagged/magefile.go | 3 ++- mage/testdata/mageimport/tagged/pkg/mage.go | 3 ++- mage/testdata/mageimport/trailing/magefile.go | 1 + mage/testdata/main.go | 1 + mage/testdata/mixed_lib_files/mage_helpers.go | 3 ++- mage/testdata/mixed_lib_files/magefile.go | 3 ++- mage/testdata/mixed_lib_files/subdir/magefile.go | 1 + mage/testdata/mixed_main_files/mage_helpers.go | 3 ++- mage/testdata/mixed_main_files/magefile.go | 3 ++- mage/testdata/namespaces/magefile.go | 3 ++- mage/testdata/no_default/magefile.go | 3 ++- mage/testdata/onlyStdLib/command.go | 1 + mage/testdata/panic.go | 1 + mage/testdata/setdir/setdir.go | 3 ++- mage/testdata/setworkdir/magefile.go | 3 ++- mage/testdata/signals/signals.go | 3 ++- mage/testdata/transitiveDeps/magefile.go | 3 ++- mage/testdata/wrong_dep/magefile.go | 3 ++- parse/testdata/alias.go | 1 + parse/testdata/command.go | 1 + parse/testdata/func.go | 1 + parse/testdata/importself/magefile.go | 3 ++- parse/testdata/repeating_synopsis.go | 1 + parse/testdata/subcommand_1.9.go | 3 ++- parse/testdata/subcommands.go | 1 + site/content/zeroInstall/_index.en.md | 1 + 46 files changed, 71 insertions(+), 26 deletions(-) diff --git a/bootstrap.go b/bootstrap.go index c37f6fc8..136aa66a 100644 --- a/bootstrap.go +++ b/bootstrap.go @@ -1,4 +1,5 @@ -//+build ignore +//go:build ignore +// +build ignore package main diff --git a/install_test.go b/install_test.go index d7923c8d..8e3cf9e7 100644 --- a/install_test.go +++ b/install_test.go @@ -1,4 +1,5 @@ -//+build CI +//go:build CI +// +build CI package main diff --git a/mage/main_test.go b/mage/main_test.go index b722d842..07e598e5 100644 --- a/mage/main_test.go +++ b/mage/main_test.go @@ -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 { diff --git a/mage/template.go b/mage/template.go index af822f0f..e6dc1306 100644 --- a/mage/template.go +++ b/mage/template.go @@ -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 diff --git a/mage/testdata/alias/magefile.go b/mage/testdata/alias/magefile.go index d68326d3..97b86f6d 100644 --- a/mage/testdata/alias/magefile.go +++ b/mage/testdata/alias/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/args/magefile.go b/mage/testdata/args/magefile.go index e7f7b262..de0f262e 100644 --- a/mage/testdata/args/magefile.go +++ b/mage/testdata/args/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/command.go b/mage/testdata/command.go index ac2b7350..74b2b845 100644 --- a/mage/testdata/command.go +++ b/mage/testdata/command.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/compiled/custom.go b/mage/testdata/compiled/custom.go index 41aaabe3..2a1bdfd1 100644 --- a/mage/testdata/compiled/custom.go +++ b/mage/testdata/compiled/custom.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage // Compiled package description. diff --git a/mage/testdata/context/context.go b/mage/testdata/context/context.go index aaf08fbe..876bc520 100644 --- a/mage/testdata/context/context.go +++ b/mage/testdata/context/context.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/error.go b/mage/testdata/error.go index bb98a097..a639fd60 100644 --- a/mage/testdata/error.go +++ b/mage/testdata/error.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/func.go b/mage/testdata/func.go index b33fe4b3..503ccdf7 100644 --- a/mage/testdata/func.go +++ b/mage/testdata/func.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/goos_magefiles/magefile_nonwindows.go b/mage/testdata/goos_magefiles/magefile_nonwindows.go index 420f4f89..3be85d86 100644 --- a/mage/testdata/goos_magefiles/magefile_nonwindows.go +++ b/mage/testdata/goos_magefiles/magefile_nonwindows.go @@ -1,3 +1,4 @@ +//go:build mage && !windows // +build mage,!windows package main diff --git a/mage/testdata/goos_magefiles/magefile_windows.go b/mage/testdata/goos_magefiles/magefile_windows.go index 1b8248bb..15173da0 100644 --- a/mage/testdata/goos_magefiles/magefile_windows.go +++ b/mage/testdata/goos_magefiles/magefile_windows.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/invalid_alias/magefile.go b/mage/testdata/invalid_alias/magefile.go index e3f985f1..59e013eb 100644 --- a/mage/testdata/invalid_alias/magefile.go +++ b/mage/testdata/invalid_alias/magefile.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/keep_flag/magefile.go b/mage/testdata/keep_flag/magefile.go index ce97b22a..1ab8e212 100644 --- a/mage/testdata/keep_flag/magefile.go +++ b/mage/testdata/keep_flag/magefile.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/list/command.go b/mage/testdata/list/command.go index ae36007e..3795cec4 100644 --- a/mage/testdata/list/command.go +++ b/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 diff --git a/mage/testdata/mageimport/magefile.go b/mage/testdata/mageimport/magefile.go index f37a8953..ec69c14c 100644 --- a/mage/testdata/mageimport/magefile.go +++ b/mage/testdata/mageimport/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/mageimport/oneline/magefile.go b/mage/testdata/mageimport/oneline/magefile.go index fdbbc213..d8b5c9fe 100644 --- a/mage/testdata/mageimport/oneline/magefile.go +++ b/mage/testdata/mageimport/oneline/magefile.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/mageimport/samenamespace/duptargets/magefile.go b/mage/testdata/mageimport/samenamespace/duptargets/magefile.go index 5c585304..edf4078b 100644 --- a/mage/testdata/mageimport/samenamespace/duptargets/magefile.go +++ b/mage/testdata/mageimport/samenamespace/duptargets/magefile.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package sametarget diff --git a/mage/testdata/mageimport/samenamespace/uniquetargets/magefile.go b/mage/testdata/mageimport/samenamespace/uniquetargets/magefile.go index aebacbb6..c93b2d2f 100644 --- a/mage/testdata/mageimport/samenamespace/uniquetargets/magefile.go +++ b/mage/testdata/mageimport/samenamespace/uniquetargets/magefile.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/mageimport/tagged/magefile.go b/mage/testdata/mageimport/tagged/magefile.go index c04d933b..9efe85fe 100644 --- a/mage/testdata/mageimport/tagged/magefile.go +++ b/mage/testdata/mageimport/tagged/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/mageimport/tagged/pkg/mage.go b/mage/testdata/mageimport/tagged/pkg/mage.go index d5991482..014e2fa2 100644 --- a/mage/testdata/mageimport/tagged/pkg/mage.go +++ b/mage/testdata/mageimport/tagged/pkg/mage.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package pkg diff --git a/mage/testdata/mageimport/trailing/magefile.go b/mage/testdata/mageimport/trailing/magefile.go index ed3691b9..13360367 100644 --- a/mage/testdata/mageimport/trailing/magefile.go +++ b/mage/testdata/mageimport/trailing/magefile.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/main.go b/mage/testdata/main.go index a3f23b4b..53c564a8 100644 --- a/mage/testdata/main.go +++ b/mage/testdata/main.go @@ -1,3 +1,4 @@ +//go:build ignore // +build ignore package main diff --git a/mage/testdata/mixed_lib_files/mage_helpers.go b/mage/testdata/mixed_lib_files/mage_helpers.go index 19c713a0..e4b8872f 100644 --- a/mage/testdata/mixed_lib_files/mage_helpers.go +++ b/mage/testdata/mixed_lib_files/mage_helpers.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/mixed_lib_files/magefile.go b/mage/testdata/mixed_lib_files/magefile.go index 3c30feba..ce6b9c47 100644 --- a/mage/testdata/mixed_lib_files/magefile.go +++ b/mage/testdata/mixed_lib_files/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/mixed_lib_files/subdir/magefile.go b/mage/testdata/mixed_lib_files/subdir/magefile.go index 20a9fe49..63584509 100644 --- a/mage/testdata/mixed_lib_files/subdir/magefile.go +++ b/mage/testdata/mixed_lib_files/subdir/magefile.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/mixed_main_files/mage_helpers.go b/mage/testdata/mixed_main_files/mage_helpers.go index 19c713a0..e4b8872f 100644 --- a/mage/testdata/mixed_main_files/mage_helpers.go +++ b/mage/testdata/mixed_main_files/mage_helpers.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/mixed_main_files/magefile.go b/mage/testdata/mixed_main_files/magefile.go index f4248496..63584509 100644 --- a/mage/testdata/mixed_main_files/magefile.go +++ b/mage/testdata/mixed_main_files/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/namespaces/magefile.go b/mage/testdata/namespaces/magefile.go index d1ae0456..c2b8f4da 100644 --- a/mage/testdata/namespaces/magefile.go +++ b/mage/testdata/namespaces/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/no_default/magefile.go b/mage/testdata/no_default/magefile.go index 4e3d4941..a0046682 100644 --- a/mage/testdata/no_default/magefile.go +++ b/mage/testdata/no_default/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/onlyStdLib/command.go b/mage/testdata/onlyStdLib/command.go index 3822a80a..e1c4b825 100644 --- a/mage/testdata/onlyStdLib/command.go +++ b/mage/testdata/onlyStdLib/command.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/panic.go b/mage/testdata/panic.go index 3714c0d5..2cd54a9e 100644 --- a/mage/testdata/panic.go +++ b/mage/testdata/panic.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/setdir/setdir.go b/mage/testdata/setdir/setdir.go index 3fc20d83..9b8571d6 100644 --- a/mage/testdata/setdir/setdir.go +++ b/mage/testdata/setdir/setdir.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/setworkdir/magefile.go b/mage/testdata/setworkdir/magefile.go index 2eb93235..d0c0ab78 100644 --- a/mage/testdata/setworkdir/magefile.go +++ b/mage/testdata/setworkdir/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/signals/signals.go b/mage/testdata/signals/signals.go index 96d62552..07d0e942 100644 --- a/mage/testdata/signals/signals.go +++ b/mage/testdata/signals/signals.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/transitiveDeps/magefile.go b/mage/testdata/transitiveDeps/magefile.go index 379d6eab..336f1c0d 100644 --- a/mage/testdata/transitiveDeps/magefile.go +++ b/mage/testdata/transitiveDeps/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/wrong_dep/magefile.go b/mage/testdata/wrong_dep/magefile.go index 8da309d8..30c441d7 100644 --- a/mage/testdata/wrong_dep/magefile.go +++ b/mage/testdata/wrong_dep/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/parse/testdata/alias.go b/parse/testdata/alias.go index 0c5d3136..6b1c111f 100644 --- a/parse/testdata/alias.go +++ b/parse/testdata/alias.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/parse/testdata/command.go b/parse/testdata/command.go index d8e6f74a..ab54994c 100644 --- a/parse/testdata/command.go +++ b/parse/testdata/command.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/parse/testdata/func.go b/parse/testdata/func.go index 94927756..ffc81fda 100644 --- a/parse/testdata/func.go +++ b/parse/testdata/func.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/parse/testdata/importself/magefile.go b/parse/testdata/importself/magefile.go index e1978e52..4440b9dd 100644 --- a/parse/testdata/importself/magefile.go +++ b/parse/testdata/importself/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/parse/testdata/repeating_synopsis.go b/parse/testdata/repeating_synopsis.go index bcac14d4..602516f1 100644 --- a/parse/testdata/repeating_synopsis.go +++ b/parse/testdata/repeating_synopsis.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/parse/testdata/subcommand_1.9.go b/parse/testdata/subcommand_1.9.go index 21d1d95d..ee820ae5 100644 --- a/parse/testdata/subcommand_1.9.go +++ b/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 diff --git a/parse/testdata/subcommands.go b/parse/testdata/subcommands.go index 4eb31bdb..502f00e2 100644 --- a/parse/testdata/subcommands.go +++ b/parse/testdata/subcommands.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/site/content/zeroInstall/_index.en.md b/site/content/zeroInstall/_index.en.md index 1a7b1c98..4b8c2212 100644 --- a/site/content/zeroInstall/_index.en.md +++ b/site/content/zeroInstall/_index.en.md @@ -16,6 +16,7 @@ Now you can `go run mage.go ` and it'll work just as if you ran `mage `: ```go +//go:build ignore // +build ignore package main