Skip to content

Commit

Permalink
Change generated binary to 1.18 (#91)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
abice committed Mar 20, 2022
1 parent ff7c099 commit 7e2e8bc
Show file tree
Hide file tree
Showing 27 changed files with 8,749 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
matrix:
go:
# Drop support of go 1.12
- "1.13"
# Drop support of go 1.13
- "1.14"
- "1.15"
- "1.16"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16
go-version: 1.18

- name: Cache Go modules
uses: actions/cache@v1
Expand Down
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ build: deps
$(GO) build -v -o bin/go-enum -ldflags='-X "main.version=example" -X "main.commit=example" -X "main.date=example" -X "main.builtBy=example"' .

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

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

generate1_15: generator/assets/assets.go generator/enum.tmpl
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'

.PHONY: ci
ci: docker_1.14
ci: docker_1.15
ci: docker_1.16
ci: docker_1.17
ci: docker_1.18

docker_%:
echo "##### testing golang $* #####"
docker run -i -t -w /app -v $(shell pwd):/app --entrypoint /bin/sh golang:$* -c 'make clean && make'
2 changes: 1 addition & 1 deletion example/enum_32_bit.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate ../bin/go-enum -f=$GOFILE --ptr --marshal
//go:generate ../bin/go-enum -f=$GOFILE --names

package example

Expand Down
45 changes: 24 additions & 21 deletions example/enum_32_bit_enum.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions example/enum_32_bit_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package example

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestEnum32Bit(t *testing.T) {

tests := map[string]struct {
input string
output Enum32bit
}{
"E2P15": {
input: `E2P15`,
output: Enum32bitE2P15,
},
"E2P30": {
input: `E2P30`,
output: Enum32bitE2P30,
},
}

for name, tc := range tests {
t.Run(name, func(t *testing.T) {
output, err := ParseEnum32bit(tc.input)
assert.NoError(t, err)
assert.Equal(t, tc.output, output)

assert.Equal(t, tc.input, output.String())
})
}

t.Run("basics", func(t *testing.T) {
assert.Equal(t, "E2P23", Enum32bitE2P23.String())
assert.Equal(t, "Enum32bit(99)", Enum32bit(99).String())
_, err := ParseEnum32bit("-1")
assert.Error(t, err)

names := Enum32bitNames()
assert.Len(t, names, 12)
})

}
2 changes: 1 addition & 1 deletion example/enum_64_bit.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate ../bin/go-enum -f=$GOFILE --ptr --marshal
//go:generate ../bin/go-enum -f=$GOFILE --names

package example

Expand Down
49 changes: 28 additions & 21 deletions example/enum_64_bit_enum.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions example/enum_64_bit_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package example

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestEnum64Bit(t *testing.T) {

tests := map[string]struct {
input string
output Enum64bit
}{
"E2P15": {
input: `E2P15`,
output: Enum64bitE2P15,
},
"E2P63": {
input: `E2P63`,
output: Enum64bitE2P63,
},
}

for name, tc := range tests {
t.Run(name, func(t *testing.T) {
output, err := ParseEnum64bit(tc.input)
assert.NoError(t, err)
assert.Equal(t, tc.output, output)

assert.Equal(t, tc.input, output.String())
})
}

t.Run("basics", func(t *testing.T) {
assert.Equal(t, "E2P23", Enum64bitE2P23.String())
assert.Equal(t, "Enum64bit(99)", Enum64bit(99).String())
_, err := ParseEnum64bit("-1")
assert.Error(t, err)

names := Enum64bitNames()
assert.Len(t, names, 16)
})

}
7 changes: 7 additions & 0 deletions example/force_lower_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,11 @@ func TestForceLowerString(t *testing.T) {
assert.Equal(t, tc.input, output.String())
})
}

t.Run("failures", func(t *testing.T) {
assert.Equal(t, "ForceLowerType(99)", ForceLowerType(99).String())
_, err := ParseForceLowerType("-1")
assert.Error(t, err)

})
}
8 changes: 8 additions & 0 deletions example/user_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,12 @@ func TestUserTemplateColor(t *testing.T) {
assert.Equal(t, true, ParseOceanColorExample())
assert.Equal(t, true, ParseOceanColorGlobbedExample())
assert.Equal(t, true, ParseOceanColorGlobbedExample2())

val, err := ParseOceanColor("Cerulean")
assert.NoError(t, err)
assert.Equal(t, "Cerulean", val.String())

assert.Equal(t, "OceanColor(99)", OceanColor(99).String())
_, err = ParseOceanColor("-1")
assert.Error(t, err)
}
Loading

0 comments on commit 7e2e8bc

Please sign in to comment.