Skip to content

Commit 7e2e8bc

Browse files
authored
Change generated binary to 1.18 (#91)
* Update to support go 1.18 stuff * add new tests * change release to use 1.18 * fix older versions * drop support of 1.13 * up the code coverage
1 parent ff7c099 commit 7e2e8bc

27 files changed

+8749
-63
lines changed

.github/workflows/build_and_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
matrix:
1515
go:
1616
# Drop support of go 1.12
17-
- "1.13"
17+
# Drop support of go 1.13
1818
- "1.14"
1919
- "1.15"
2020
- "1.16"

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Set up Go
1818
uses: actions/setup-go@v2
1919
with:
20-
go-version: 1.16
20+
go-version: 1.18
2121

2222
- name: Cache Go modules
2323
uses: actions/cache@v1

Makefile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ build: deps
4848
$(GO) build -v -o bin/go-enum -ldflags='-X "main.version=example" -X "main.commit=example" -X "main.date=example" -X "main.builtBy=example"' .
4949

5050
fmt:
51-
gofmt -l -w -s $$(find . -type f -name '*.go' -not -path "./vendor/*")
51+
-$(GO) fmt ./...
5252

5353
test: gen-test generate
5454
$(GO) test -v -race -coverprofile=coverage.out ./...
@@ -104,3 +104,14 @@ bin/go-bindata: go.sum
104104

105105
generate1_15: generator/assets/assets.go generator/enum.tmpl
106106
docker run -i -t -w /app -v $(shell pwd):/app --entrypoint /bin/sh golang:1.15 -c 'make clean $(GOBINDATA) && $(GO) generate ./generator && make clean'
107+
108+
.PHONY: ci
109+
ci: docker_1.14
110+
ci: docker_1.15
111+
ci: docker_1.16
112+
ci: docker_1.17
113+
ci: docker_1.18
114+
115+
docker_%:
116+
echo "##### testing golang $* #####"
117+
docker run -i -t -w /app -v $(shell pwd):/app --entrypoint /bin/sh golang:$* -c 'make clean && make'

example/enum_32_bit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:generate ../bin/go-enum -f=$GOFILE --ptr --marshal
1+
//go:generate ../bin/go-enum -f=$GOFILE --names
22

33
package example
44

example/enum_32_bit_enum.go

Lines changed: 24 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/enum_32_bit_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package example
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestEnum32Bit(t *testing.T) {
10+
11+
tests := map[string]struct {
12+
input string
13+
output Enum32bit
14+
}{
15+
"E2P15": {
16+
input: `E2P15`,
17+
output: Enum32bitE2P15,
18+
},
19+
"E2P30": {
20+
input: `E2P30`,
21+
output: Enum32bitE2P30,
22+
},
23+
}
24+
25+
for name, tc := range tests {
26+
t.Run(name, func(t *testing.T) {
27+
output, err := ParseEnum32bit(tc.input)
28+
assert.NoError(t, err)
29+
assert.Equal(t, tc.output, output)
30+
31+
assert.Equal(t, tc.input, output.String())
32+
})
33+
}
34+
35+
t.Run("basics", func(t *testing.T) {
36+
assert.Equal(t, "E2P23", Enum32bitE2P23.String())
37+
assert.Equal(t, "Enum32bit(99)", Enum32bit(99).String())
38+
_, err := ParseEnum32bit("-1")
39+
assert.Error(t, err)
40+
41+
names := Enum32bitNames()
42+
assert.Len(t, names, 12)
43+
})
44+
45+
}

example/enum_64_bit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:generate ../bin/go-enum -f=$GOFILE --ptr --marshal
1+
//go:generate ../bin/go-enum -f=$GOFILE --names
22

33
package example
44

example/enum_64_bit_enum.go

Lines changed: 28 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/enum_64_bit_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package example
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestEnum64Bit(t *testing.T) {
10+
11+
tests := map[string]struct {
12+
input string
13+
output Enum64bit
14+
}{
15+
"E2P15": {
16+
input: `E2P15`,
17+
output: Enum64bitE2P15,
18+
},
19+
"E2P63": {
20+
input: `E2P63`,
21+
output: Enum64bitE2P63,
22+
},
23+
}
24+
25+
for name, tc := range tests {
26+
t.Run(name, func(t *testing.T) {
27+
output, err := ParseEnum64bit(tc.input)
28+
assert.NoError(t, err)
29+
assert.Equal(t, tc.output, output)
30+
31+
assert.Equal(t, tc.input, output.String())
32+
})
33+
}
34+
35+
t.Run("basics", func(t *testing.T) {
36+
assert.Equal(t, "E2P23", Enum64bitE2P23.String())
37+
assert.Equal(t, "Enum64bit(99)", Enum64bit(99).String())
38+
_, err := ParseEnum64bit("-1")
39+
assert.Error(t, err)
40+
41+
names := Enum64bitNames()
42+
assert.Len(t, names, 16)
43+
})
44+
45+
}

example/force_lower_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,11 @@ func TestForceLowerString(t *testing.T) {
3131
assert.Equal(t, tc.input, output.String())
3232
})
3333
}
34+
35+
t.Run("failures", func(t *testing.T) {
36+
assert.Equal(t, "ForceLowerType(99)", ForceLowerType(99).String())
37+
_, err := ParseForceLowerType("-1")
38+
assert.Error(t, err)
39+
40+
})
3441
}

0 commit comments

Comments
 (0)