2021-09-11 13:01:57 -03:00
|
|
|
package buildtarget
|
2017-04-26 20:08:25 -03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2024-05-26 15:02:57 -03:00
|
|
|
"github.com/goreleaser/goreleaser/v2/pkg/config"
|
2020-10-06 09:48:04 -03:00
|
|
|
"github.com/stretchr/testify/require"
|
2017-04-26 20:08:25 -03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestAllBuildTargets(t *testing.T) {
|
2021-02-18 14:29:20 -03:00
|
|
|
build := config.Build{
|
|
|
|
GoBinary: "go",
|
2017-07-01 13:21:07 -03:00
|
|
|
Goos: []string{
|
|
|
|
"linux",
|
|
|
|
"darwin",
|
|
|
|
"freebsd",
|
2017-07-10 13:44:07 +02:00
|
|
|
"openbsd",
|
2021-03-28 12:18:40 -03:00
|
|
|
"windows",
|
2019-10-01 16:00:44 -03:00
|
|
|
"js",
|
2022-07-26 09:30:04 -03:00
|
|
|
"ios",
|
2023-09-02 14:43:07 -03:00
|
|
|
"wasip1",
|
2017-07-01 13:21:07 -03:00
|
|
|
},
|
|
|
|
Goarch: []string{
|
|
|
|
"386",
|
|
|
|
"amd64",
|
|
|
|
"arm",
|
|
|
|
"arm64",
|
2019-10-01 16:00:44 -03:00
|
|
|
"wasm",
|
2020-01-26 14:36:00 -03:00
|
|
|
"mips",
|
|
|
|
"mips64",
|
|
|
|
"mipsle",
|
|
|
|
"mips64le",
|
2021-01-13 14:28:53 -03:00
|
|
|
"riscv64",
|
2022-08-03 09:38:09 -03:00
|
|
|
"loong64",
|
2017-07-01 13:21:07 -03:00
|
|
|
},
|
2024-10-14 09:40:10 -03:00
|
|
|
Goamd64: []string{
|
|
|
|
"v1",
|
|
|
|
"v2",
|
|
|
|
"v3",
|
|
|
|
"v4",
|
|
|
|
},
|
|
|
|
Go386: []string{
|
|
|
|
"sse2",
|
|
|
|
"softfloat",
|
|
|
|
},
|
2017-07-01 13:21:07 -03:00
|
|
|
Goarm: []string{
|
2024-10-14 09:40:10 -03:00
|
|
|
"5",
|
2017-07-01 13:21:07 -03:00
|
|
|
"6",
|
|
|
|
"7",
|
|
|
|
},
|
2024-10-14 09:40:10 -03:00
|
|
|
Goarm64: []string{
|
|
|
|
"v8.0",
|
|
|
|
"v9.0",
|
|
|
|
},
|
2020-01-26 14:36:00 -03:00
|
|
|
Gomips: []string{
|
|
|
|
"hardfloat",
|
|
|
|
"softfloat",
|
|
|
|
},
|
2024-10-14 09:40:10 -03:00
|
|
|
Goppc64: []string{
|
|
|
|
"power8",
|
|
|
|
"power9",
|
|
|
|
"power10",
|
|
|
|
},
|
|
|
|
Goriscv64: []string{
|
|
|
|
"rva20u64",
|
|
|
|
"rva22u64",
|
2022-04-11 22:43:22 -03:00
|
|
|
},
|
2017-07-01 13:21:07 -03:00
|
|
|
Ignore: []config.IgnoredBuild{
|
|
|
|
{
|
|
|
|
Goos: "linux",
|
|
|
|
Goarch: "arm",
|
|
|
|
Goarm: "7",
|
2017-07-10 13:44:07 +02:00
|
|
|
}, {
|
|
|
|
Goos: "openbsd",
|
|
|
|
Goarch: "arm",
|
2024-10-14 09:40:10 -03:00
|
|
|
}, {
|
|
|
|
Goarch: "amd64",
|
|
|
|
Goamd64: "v1",
|
|
|
|
}, {
|
|
|
|
Goarch: "386",
|
|
|
|
Go386: "sse2",
|
|
|
|
}, {
|
|
|
|
Goarch: "arm64",
|
|
|
|
Goarm64: "v8.0",
|
|
|
|
}, {
|
|
|
|
Goarch: "mips",
|
|
|
|
Gomips: "hardfloat",
|
|
|
|
}, {
|
|
|
|
Goarch: "mipsle",
|
|
|
|
Gomips: "hardfloat",
|
2020-01-26 14:36:00 -03:00
|
|
|
}, {
|
|
|
|
Goarch: "mips64",
|
|
|
|
Gomips: "hardfloat",
|
|
|
|
}, {
|
|
|
|
Goarch: "mips64le",
|
2024-10-14 09:40:10 -03:00
|
|
|
Gomips: "hardfloat",
|
2022-04-11 22:43:22 -03:00
|
|
|
}, {
|
2024-10-14 09:40:10 -03:00
|
|
|
Goarch: "ppc64",
|
|
|
|
Goppc64: "power8",
|
|
|
|
}, {
|
|
|
|
Goarch: "ppc64le",
|
|
|
|
Goppc64: "power8",
|
|
|
|
}, {
|
|
|
|
Goarch: "riscv64",
|
|
|
|
Goriscv64: "rva20u64",
|
2017-04-26 20:08:25 -03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-08-16 23:00:56 -03:00
|
|
|
|
2022-03-16 21:51:48 -03:00
|
|
|
t.Run("go 1.18", func(t *testing.T) {
|
2022-07-22 09:51:39 -03:00
|
|
|
result, err := List(build)
|
2021-08-16 23:00:56 -03:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, []string{
|
2024-10-14 09:40:10 -03:00
|
|
|
"linux_386_softfloat",
|
2022-04-11 22:43:22 -03:00
|
|
|
"linux_amd64_v2",
|
2024-10-14 09:40:10 -03:00
|
|
|
"linux_amd64_v3",
|
2022-04-13 21:29:39 -03:00
|
|
|
"linux_amd64_v4",
|
2024-10-14 09:40:10 -03:00
|
|
|
"linux_arm_5",
|
2021-08-16 23:00:56 -03:00
|
|
|
"linux_arm_6",
|
2024-10-14 09:40:10 -03:00
|
|
|
"linux_arm64_v9.0",
|
2021-08-16 23:00:56 -03:00
|
|
|
"linux_mips_softfloat",
|
|
|
|
"linux_mips64_softfloat",
|
|
|
|
"linux_mipsle_softfloat",
|
2024-10-14 09:40:10 -03:00
|
|
|
"linux_mips64le_softfloat",
|
|
|
|
"linux_riscv64_rva22u64",
|
2022-08-03 09:38:09 -03:00
|
|
|
"linux_loong64",
|
2022-04-11 22:43:22 -03:00
|
|
|
"darwin_amd64_v2",
|
2024-10-14 09:40:10 -03:00
|
|
|
"darwin_amd64_v3",
|
2022-04-13 21:29:39 -03:00
|
|
|
"darwin_amd64_v4",
|
2024-10-14 09:40:10 -03:00
|
|
|
"darwin_arm64_v9.0",
|
|
|
|
"freebsd_386_softfloat",
|
2022-04-11 22:43:22 -03:00
|
|
|
"freebsd_amd64_v2",
|
2024-10-14 09:40:10 -03:00
|
|
|
"freebsd_amd64_v3",
|
2022-04-13 21:29:39 -03:00
|
|
|
"freebsd_amd64_v4",
|
2024-10-14 09:40:10 -03:00
|
|
|
"freebsd_arm_5",
|
2021-08-16 23:00:56 -03:00
|
|
|
"freebsd_arm_6",
|
|
|
|
"freebsd_arm_7",
|
2024-10-14 09:40:10 -03:00
|
|
|
"freebsd_arm64_v9.0",
|
|
|
|
"openbsd_386_softfloat",
|
2022-04-11 22:43:22 -03:00
|
|
|
"openbsd_amd64_v2",
|
2024-10-14 09:40:10 -03:00
|
|
|
"openbsd_amd64_v3",
|
2022-04-13 21:29:39 -03:00
|
|
|
"openbsd_amd64_v4",
|
2024-10-14 09:40:10 -03:00
|
|
|
"openbsd_arm64_v9.0",
|
|
|
|
"windows_386_softfloat",
|
2022-04-11 22:43:22 -03:00
|
|
|
"windows_amd64_v2",
|
2024-10-14 09:40:10 -03:00
|
|
|
"windows_amd64_v3",
|
2022-04-13 21:29:39 -03:00
|
|
|
"windows_amd64_v4",
|
2024-10-14 09:40:10 -03:00
|
|
|
"windows_arm_5",
|
2021-08-16 23:00:56 -03:00
|
|
|
"windows_arm_6",
|
|
|
|
"windows_arm_7",
|
2024-10-14 09:40:10 -03:00
|
|
|
"windows_arm64_v9.0",
|
2021-08-16 23:00:56 -03:00
|
|
|
"js_wasm",
|
2024-10-14 09:40:10 -03:00
|
|
|
"ios_arm64_v9.0",
|
2023-09-02 14:43:07 -03:00
|
|
|
"wasip1_wasm",
|
2021-08-16 23:00:56 -03:00
|
|
|
}, result)
|
|
|
|
})
|
2021-09-11 14:32:51 -03:00
|
|
|
|
|
|
|
t.Run("invalid goos", func(t *testing.T) {
|
2022-07-22 09:51:39 -03:00
|
|
|
_, err := List(config.Build{
|
2022-04-11 22:43:22 -03:00
|
|
|
Goos: []string{"invalid"},
|
|
|
|
Goarch: []string{"amd64"},
|
|
|
|
Goamd64: []string{"v2"},
|
2022-07-22 09:51:39 -03:00
|
|
|
})
|
2021-09-11 14:32:51 -03:00
|
|
|
require.EqualError(t, err, "invalid goos: invalid")
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("invalid goarch", func(t *testing.T) {
|
2022-07-22 09:51:39 -03:00
|
|
|
_, err := List(config.Build{
|
2021-09-11 14:32:51 -03:00
|
|
|
Goos: []string{"linux"},
|
|
|
|
Goarch: []string{"invalid"},
|
2022-07-22 09:51:39 -03:00
|
|
|
})
|
2021-09-11 14:32:51 -03:00
|
|
|
require.EqualError(t, err, "invalid goarch: invalid")
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("invalid goarm", func(t *testing.T) {
|
2022-07-22 09:51:39 -03:00
|
|
|
_, err := List(config.Build{
|
2021-09-11 14:32:51 -03:00
|
|
|
Goos: []string{"linux"},
|
|
|
|
Goarch: []string{"arm"},
|
|
|
|
Goarm: []string{"invalid"},
|
2022-07-22 09:51:39 -03:00
|
|
|
})
|
2021-09-11 14:32:51 -03:00
|
|
|
require.EqualError(t, err, "invalid goarm: invalid")
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("invalid gomips", func(t *testing.T) {
|
2022-07-22 09:51:39 -03:00
|
|
|
_, err := List(config.Build{
|
2021-09-11 14:32:51 -03:00
|
|
|
Goos: []string{"linux"},
|
|
|
|
Goarch: []string{"mips"},
|
|
|
|
Gomips: []string{"invalid"},
|
2022-07-22 09:51:39 -03:00
|
|
|
})
|
2021-09-11 14:32:51 -03:00
|
|
|
require.EqualError(t, err, "invalid gomips: invalid")
|
|
|
|
})
|
2022-04-11 22:43:22 -03:00
|
|
|
|
|
|
|
t.Run("invalid goamd64", func(t *testing.T) {
|
2022-07-22 09:51:39 -03:00
|
|
|
_, err := List(config.Build{
|
2022-04-11 22:43:22 -03:00
|
|
|
Goos: []string{"linux"},
|
|
|
|
Goarch: []string{"amd64"},
|
|
|
|
Goamd64: []string{"invalid"},
|
2022-07-22 09:51:39 -03:00
|
|
|
})
|
2022-04-11 22:43:22 -03:00
|
|
|
require.EqualError(t, err, "invalid goamd64: invalid")
|
|
|
|
})
|
2017-04-26 20:08:25 -03:00
|
|
|
}
|
|
|
|
|
2017-07-06 20:13:02 -03:00
|
|
|
func TestGoosGoarchCombos(t *testing.T) {
|
2021-02-18 14:29:20 -03:00
|
|
|
platforms := []struct {
|
2017-07-06 20:13:02 -03:00
|
|
|
os string
|
|
|
|
arch string
|
|
|
|
valid bool
|
2017-04-26 20:08:25 -03:00
|
|
|
}{
|
2017-07-06 20:13:02 -03:00
|
|
|
// valid targets:
|
2019-10-01 15:25:13 -04:00
|
|
|
{"aix", "ppc64", true},
|
|
|
|
{"android", "386", true},
|
|
|
|
{"android", "amd64", true},
|
2017-07-06 20:13:02 -03:00
|
|
|
{"android", "arm", true},
|
2019-10-01 15:25:13 -04:00
|
|
|
{"android", "arm64", true},
|
2017-07-06 20:13:02 -03:00
|
|
|
{"darwin", "amd64", true},
|
2021-02-16 19:51:11 -03:00
|
|
|
{"darwin", "arm64", true},
|
2017-07-06 20:13:02 -03:00
|
|
|
{"dragonfly", "amd64", true},
|
|
|
|
{"freebsd", "386", true},
|
|
|
|
{"freebsd", "amd64", true},
|
|
|
|
{"freebsd", "arm", true},
|
2024-03-17 17:35:55 +00:00
|
|
|
{"freebsd", "arm64", true},
|
2019-10-01 15:25:13 -04:00
|
|
|
{"illumos", "amd64", true},
|
2022-07-26 09:30:04 -03:00
|
|
|
{"ios", "arm64", true},
|
2017-07-06 20:13:02 -03:00
|
|
|
{"linux", "386", true},
|
|
|
|
{"linux", "amd64", true},
|
|
|
|
{"linux", "arm", true},
|
|
|
|
{"linux", "arm64", true},
|
|
|
|
{"linux", "mips", true},
|
|
|
|
{"linux", "mipsle", true},
|
|
|
|
{"linux", "mips64", true},
|
|
|
|
{"linux", "mips64le", true},
|
|
|
|
{"linux", "ppc64", true},
|
|
|
|
{"linux", "ppc64le", true},
|
2017-07-26 01:04:03 -06:00
|
|
|
{"linux", "s390x", true},
|
2021-01-13 14:28:53 -03:00
|
|
|
{"linux", "riscv64", true},
|
2022-08-03 09:38:09 -03:00
|
|
|
{"linux", "loong64", true},
|
2017-07-06 20:13:02 -03:00
|
|
|
{"netbsd", "386", true},
|
|
|
|
{"netbsd", "amd64", true},
|
|
|
|
{"netbsd", "arm", true},
|
2024-03-17 17:35:55 +00:00
|
|
|
{"netbsd", "arm64", true},
|
2017-07-06 20:13:02 -03:00
|
|
|
{"openbsd", "386", true},
|
|
|
|
{"openbsd", "amd64", true},
|
|
|
|
{"openbsd", "arm", true},
|
2024-03-17 17:35:55 +00:00
|
|
|
{"openbsd", "arm64", true},
|
2017-07-06 20:13:02 -03:00
|
|
|
{"plan9", "386", true},
|
|
|
|
{"plan9", "amd64", true},
|
2019-10-01 15:25:13 -04:00
|
|
|
{"plan9", "arm", true},
|
2017-07-06 20:13:02 -03:00
|
|
|
{"solaris", "amd64", true},
|
|
|
|
{"windows", "386", true},
|
|
|
|
{"windows", "amd64", true},
|
2021-03-28 12:18:40 -03:00
|
|
|
{"windows", "arm", true},
|
2021-08-16 23:00:56 -03:00
|
|
|
{"windows", "arm64", true},
|
2019-10-01 16:00:44 -03:00
|
|
|
{"js", "wasm", true},
|
2017-07-06 20:13:02 -03:00
|
|
|
// invalid targets
|
2020-08-16 11:29:44 -03:00
|
|
|
{"darwin", "386", false},
|
2017-07-06 20:13:02 -03:00
|
|
|
{"darwin", "arm", false},
|
2021-01-13 14:28:53 -03:00
|
|
|
{"windows", "riscv64", false},
|
2017-04-26 20:08:25 -03:00
|
|
|
}
|
|
|
|
for _, p := range platforms {
|
2017-07-06 20:13:02 -03:00
|
|
|
t.Run(fmt.Sprintf("%v %v valid=%v", p.os, p.arch, p.valid), func(t *testing.T) {
|
2024-10-14 09:40:10 -03:00
|
|
|
require.Equal(t, p.valid, valid(target{os: p.os, arch: p.arch}))
|
2017-04-26 20:08:25 -03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2021-09-11 14:32:51 -03:00
|
|
|
|
|
|
|
func TestList(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
targets, err := List(config.Build{
|
|
|
|
Goos: []string{"linux"},
|
|
|
|
Goarch: []string{"amd64"},
|
2022-04-11 22:43:22 -03:00
|
|
|
Goamd64: []string{"v2"},
|
2021-09-11 14:32:51 -03:00
|
|
|
GoBinary: "go",
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
2022-04-11 22:43:22 -03:00
|
|
|
require.Equal(t, []string{"linux_amd64_v2"}, targets)
|
2021-09-11 14:32:51 -03:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("success with dir", func(t *testing.T) {
|
|
|
|
targets, err := List(config.Build{
|
|
|
|
Goos: []string{"linux"},
|
|
|
|
Goarch: []string{"amd64"},
|
2022-04-11 22:43:22 -03:00
|
|
|
Goamd64: []string{"v2"},
|
2021-09-11 14:32:51 -03:00
|
|
|
GoBinary: "go",
|
|
|
|
Dir: "./testdata",
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
2022-04-11 22:43:22 -03:00
|
|
|
require.Equal(t, []string{"linux_amd64_v2"}, targets)
|
2021-09-11 14:32:51 -03:00
|
|
|
})
|
|
|
|
}
|