Skip to content

Commit

Permalink
fix: add -c flags when building go test (#4473)
Browse files Browse the repository at this point in the history
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

#4462

---------

Co-authored-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
fl0Lec and caarlos0 committed Dec 12, 2023
1 parent aa9986e commit 159211a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/builders/golang/build.go
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"os/exec"
"path/filepath"
"slices"
"strings"

"dario.cat/mergo"
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions internal/builders/golang/build_test.go
Expand Up @@ -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: ".",
Expand Down

0 comments on commit 159211a

Please sign in to comment.