Skip to content

Commit

Permalink
fix: test for github actions (#0)
Browse files Browse the repository at this point in the history
Signed-off-by: tkrop <[email protected]>
  • Loading branch information
tkrop committed Dec 14, 2023
1 parent eb11a29 commit 0afbfc5
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ jobs:
- name: Build and tests
env:
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
run: make --file=Makefile.base --trace all
LANG: en_US.UTF-8
run: make --file=Makefile.base all

- name: Send coverage report
uses: shogo82148/actions-goveralls@v1
Expand Down
2 changes: 1 addition & 1 deletion Makefile.base
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ bump:
patsplit($$0, v, "[0-9]*", seps); len = length(seps); \
if (arg !~ "-$$") {v[pos]++ } else { v[pos]-- }; \
for (i = 1; i < len; i++) { printf("%d%s", v[i], seps[i]) } \
}' VERSION)"; echo $${VERSION}; \
}' VERSION)"; \
elif ! [[ "$(RUNARGS)" =~ ^[0-9]+(\.[0-9]+){0,2}(-.*)?$$ ]]; then \
echo "error: invalid new version [$(RUNARGS)]"; exit 1; \
else VERSION="$(RUNARGS)"; fi; echo $${VERSION} >VERSION; \
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.6
0.0.5
2 changes: 1 addition & 1 deletion internal/make/fixtures/bash-trace.err
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
call: --trace --completion=bash
info: {"path":"github.com/tkrop/go-make","repo":"[email protected]:tkrop/go-make","build":"0001-01-01T00:00:00Z","commit":"0001-01-01T00:00:00Z","dirty":true,"go":"1.21.4","platform":"linux/amd64","compiler":"gc"}
info: {"path":"github.com/tkrop/go-make","repo":"[email protected]:tkrop/go-make","build":"0001-01-01T00:00:00Z","commit":"0001-01-01T00:00:00Z","dirty":true,"go":"{{GOVERSION}}","platform":"{{PLATFORM}}","compiler":"{{COMPILER}}"}
2 changes: 1 addition & 1 deletion internal/make/fixtures/targets-trace.err
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
call: targets --trace
info: {"path":"github.com/tkrop/go-make","repo":"[email protected]:tkrop/go-make","build":"0001-01-01T00:00:00Z","commit":"0001-01-01T00:00:00Z","dirty":true,"go":"1.21.4","platform":"linux/amd64","compiler":"gc"}
info: {"path":"github.com/tkrop/go-make","repo":"[email protected]:tkrop/go-make","build":"0001-01-01T00:00:00Z","commit":"0001-01-01T00:00:00Z","dirty":true,"go":"{{GOVERSION}}","platform":"{{PLATFORM}}","compiler":"{{COMPILER}}"}
exec: make --file Makefile.base targets --trace [go-make/internal/make]
Makefile.base:18: info: please customize variables in Makefile.vars
2 changes: 1 addition & 1 deletion internal/make/fixtures/version-trace.err
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
call: --trace --version
info: {"path":"github.com/tkrop/go-make","repo":"[email protected]:tkrop/go-make","build":"0001-01-01T00:00:00Z","commit":"0001-01-01T00:00:00Z","dirty":true,"go":"1.21.4","platform":"linux/amd64","compiler":"gc"}
info: {"path":"github.com/tkrop/go-make","repo":"[email protected]:tkrop/go-make","build":"0001-01-01T00:00:00Z","commit":"0001-01-01T00:00:00Z","dirty":true,"go":"{{GOVERSION}}","platform":"{{PLATFORM}}","compiler":"{{COMPILER}}"}
2 changes: 1 addition & 1 deletion internal/make/fixtures/version.out
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"path":"github.com/tkrop/go-make","repo":"[email protected]:tkrop/go-make","build":"0001-01-01T00:00:00Z","commit":"0001-01-01T00:00:00Z","dirty":true,"go":"1.21.4","platform":"linux/amd64","compiler":"gc"}
{"path":"github.com/tkrop/go-make","repo":"[email protected]:tkrop/go-make","build":"0001-01-01T00:00:00Z","commit":"0001-01-01T00:00:00Z","dirty":true,"go":"{{GOVERSION}}","platform":"{{PLATFORM}}","compiler":"{{COMPILER}}"}
20 changes: 17 additions & 3 deletions internal/make/make_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"os/exec"
"regexp"
"runtime"
"strings"
"testing"

Expand Down Expand Up @@ -807,11 +808,21 @@ var (
// build path dependent parts.
regexMatchSourceDir = regexp.MustCompile( //nolint:gosimple // Just wrong!
"(?m)(['\\[])([^'\\]]*/)(go-make/[^'\\]]*)(['\\]])")

replacerFixture = strings.NewReplacer(
"{{GOVERSION}}", runtime.Version()[2:],
"{{PLATFORM}}", runtime.GOOS+"/"+runtime.GOARCH,
"{{COMPILER}}", runtime.Compiler)
)

func FilterMakeOutput(str string) string {
str = regexMatchTestDir.ReplaceAllString(str, "")
return regexMatchSourceDir.ReplaceAllString(str, "$1$3$4")
str = regexMatchSourceDir.ReplaceAllString(str, "$1$3$4")
return str
}

func SetupMakeFixture(str string) string {
return replacerFixture.Replace(str)
}

type MakeExecParams struct {
Expand Down Expand Up @@ -860,6 +871,9 @@ var testMakeExecParams = map[string]MakeExecParams{
},
}

// TODO: this test is sensitive to the execution parameters and fails if the
// make target is started with option `--trace`. We need to figure out how this
// influences the execution of the test and the output.
func TestMakeExec(t *testing.T) {
SetupMakeConfig(t, "../..")

Expand All @@ -875,9 +889,9 @@ func TestMakeExec(t *testing.T) {

// Then
assert.Equal(t, param.expectExit, exit)
assert.Equal(t, param.expectStdout,
assert.Equal(t, SetupMakeFixture(param.expectStdout),
FilterMakeOutput(stdout.String()))
assert.Equal(t, param.expectStderr,
assert.Equal(t, SetupMakeFixture(param.expectStderr),
FilterMakeOutput(stderr.String()))
})
}

0 comments on commit 0afbfc5

Please sign in to comment.