1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-02-03 13:11:48 +02:00

fix: add -c flags when building go test (#4473)

when building a go test without the `-c` flag like so:
```yaml
 builds:
- command: test
  binary: env.test
  dir: ./internal/builders/golang
  no_main_check: true
  ```

will result in the error: `exit status 1: fork/exec : exec format error`

adding the -c flags when not present in the flags
adding unit test

https://github.com/goreleaser/goreleaser/issues/4462

---------

Co-authored-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
Florent Lecoultre 2023-12-12 21:41:02 +01:00 committed by GitHub
parent aa9986e826
commit 159211ae78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import (
"os"
"os/exec"
"path/filepath"
"slices"
"strings"
"dario.cat/mergo"
@ -283,6 +284,9 @@ func buildGoBuildLine(ctx *context.Context, build config.Build, details config.B
return cmd, err
}
cmd = append(cmd, flags...)
if build.Command == "test" && !slices.Contains(flags, "-c") {
cmd = append(cmd, "-c")
}
asmflags, err := processFlags(ctx, artifact, env, details.Asmflags, "-asmflags=")
if err != nil {

View File

@ -1175,6 +1175,15 @@ func TestBuildGoBuildLine(t *testing.T) {
}, strings.Fields("go test -c -o foo.test ."))
})
t.Run("build test always as c flags", func(t *testing.T) {
requireEqualCmd(t, config.Build{
Main: ".",
GoBinary: "go",
Command: "test",
Binary: "foo.test",
}, strings.Fields("go test -c -o foo.test ."))
})
t.Run("ldflags1", func(t *testing.T) {
requireEqualCmd(t, config.Build{
Main: ".",