Skip to content

Commit

Permalink
Modules (#9)
Browse files Browse the repository at this point in the history
* cleanliness
  • Loading branch information
abice authored Jan 17, 2020
1 parent 5bc13a7 commit 0cda63a
Show file tree
Hide file tree
Showing 16 changed files with 265 additions and 254 deletions.
27 changes: 9 additions & 18 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,10 @@ jobBase: &jobBase
working_directory: /go/src/github.com/abice/gencheck
steps:
- checkout
- run:
name: Install Go Deps
command: |
curl https://glide.sh/get | sh
go get -v github.com/kevinburke/go-bindata/...
go get -v golang.org/x/tools/cmd/cover
go get -v github.com/mattn/goveralls
go get -v github.com/modocache/gover
glide install
- run:
name: Build
command: |
make reinstall
make build
- run:
name: Test
command: |
Expand All @@ -25,23 +16,23 @@ jobBase: &jobBase
make coveralls
jobs:
golang_1.9:
golang_1.11:
<<: *jobBase
docker:
- image: circleci/golang:1.9
golang_1.10:
- image: circleci/golang:1.11
golang_1.12:
<<: *jobBase
docker:
- image: circleci/golang:1.10
golang_1.11:
- image: circleci/golang:1.12
golang_1.13:
<<: *jobBase
docker:
- image: circleci/golang:1.11
- image: circleci/golang:1.13

workflows:
version: 2
build_and_test:
jobs:
- golang_1.9
- golang_1.10
- golang_1.11
- golang_1.12
- golang_1.13
55 changes: 28 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,56 +1,57 @@
.DEFAULT_GOAL:=all
ifdef VERBOSE
V = -v
else
.SILENT:
endif

GO ?= GO111MODULE=on go

include $(wildcard *.mk)

COVERAGEDIR = coverage
SERVICE = drone.io
ifdef CIRCLE_ARTIFACTS
COVERAGEDIR = $(CIRCLE_ARTIFACTS)
SERVICE=circle-ci
endif

.PHONY: all
all: generate fmt build test cover install

.PHONY: install-deps
install-deps:
glide install
all: generate fmt build test cover

.PHONY: benchmarks
benchmarks: generate fmt reinstall
benchmarks: generate fmt build
./benchmark.sh

build: generate
if [ ! -d bin ]; then mkdir bin; fi
go build -v -o bin/gencheck ./gencheck
$(GO) build -v -o bin/gencheck ./gencheck
fmt:
gofmt -l -w -s $$(find . -type f -name '*.go' -not -path "./vendor/*")
test: generate gen-test
if [ ! -d coverage ]; then mkdir coverage; fi
go test -v ./generator -race -cover -coverprofile=$(COVERAGEDIR)/generator.coverprofile
go test -v ./ -race -cover -coverprofile=$(COVERAGEDIR)/gencheck.coverprofile
go test -v ./internal/example -race -cover -coverprofile=$(COVERAGEDIR)/example.coverprofile
$(GO) test -v ./... -race -cover -coverprofile=$(COVERAGEDIR)/coverage.out

cover:
go tool cover -html=$(COVERAGEDIR)/generator.coverprofile -o $(COVERAGEDIR)/generator.html
go tool cover -html=$(COVERAGEDIR)/gencheck.coverprofile -o $(COVERAGEDIR)/gencheck.html
go tool cover -html=$(COVERAGEDIR)/gencheck.coverprofile -o $(COVERAGEDIR)/example.html
$(GO) tool cover -html=$(COVERAGEDIR)/coverage.out -o $(COVERAGEDIR)/coverage.html

tc: test cover
coveralls:
gover $(COVERAGEDIR) $(COVERAGEDIR)/coveralls.coverprofile
goveralls -coverprofile=$(COVERAGEDIR)/coveralls.coverprofile -service=$(SERVICE) -repotoken=$(COVERALLS_TOKEN)
clean:
go clean
coveralls: $(GOVERALLS)
$(GOVERALLS) -coverprofile=$(COVERAGEDIR)/coverage.out -service=$(SERVICE) -repotoken=$(COVERALLS_TOKEN)

clean: cleandeps
$(GO) clean
rm -f bin/gencheck
rm -rf coverage/

# go-bindata will take all of the template files and create readable assets from them in the executable.
# This way the templates are readable in atom (or another text editor with golang template language support)
generate:
go-bindata -o generator/assets.go -nometadata -pkg=generator template/*.tmpl
generate: deps
$(GOBINDATA) -o generator/assets.go -nometadata -pkg=generator template/*.tmpl

gen-test: build install
go generate $$(glide novendor)
gen-test: build
$(GO) generate ./...

install:
go install ./gencheck

reinstall: build
go install ./gencheck
$(GO) install ./gencheck

phony: clean tc build
6 changes: 3 additions & 3 deletions benchmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ gencheckBench(){
echo "\`\`\`" >> "$benchMD"
f="-f=./internal/benchmark/types.go"
if [[ -n $options ]]; then
gencheck "$f" "$options"
./bin/gencheck "$f" "$options"
else
gencheck "$f"
./bin/gencheck "$f"
fi
go test -v -run=XXX -bench=BenchmarkCompareGencheck -benchmem ./internal/benchmark >> "$benchMD"
echo "\`\`\`" >> "$benchMD"
Expand All @@ -32,4 +32,4 @@ echo "# PLAYGROUND"
echo "# PLAYGROUND" > "$benchMD"
echo "\`\`\`" >> "$benchMD"
go test -v -run=XXX -bench=BenchmarkComparePlayground -benchmem ./internal/benchmark >> "$benchMD"
echo "\`\`\`" >> "$benchMD"
echo "\`\`\`" >> "$benchMD"
32 changes: 16 additions & 16 deletions benchmark_failfast.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
goos: darwin
goarch: amd64
pkg: github.com/abice/gencheck/internal/benchmark
BenchmarkCompareGencheck/UUID_Pass-8 2000000 739 ns/op 0 B/op 0 allocs/op
BenchmarkCompareGencheck/UUID_Fail-8 1000000 1130 ns/op 208 B/op 6 allocs/op
BenchmarkCompareGencheck/Hex_Pass-8 3000000 538 ns/op 0 B/op 0 allocs/op
BenchmarkCompareGencheck/Hex_Fail-8 2000000 882 ns/op 192 B/op 6 allocs/op
BenchmarkCompareGencheck/ContainsAny_Pass-8 30000000 44.6 ns/op 0 B/op 0 allocs/op
BenchmarkCompareGencheck/ContainsAny_Fail-8 10000000 232 ns/op 128 B/op 4 allocs/op
BenchmarkCompareGencheck/TestStrings_Pass-8 200000000 7.11 ns/op 0 B/op 0 allocs/op
BenchmarkCompareGencheck/TestStrings_Fail-8 10000000 169 ns/op 128 B/op 4 allocs/op
BenchmarkCompareGencheck/TestMap_Pass-8 200000000 8.45 ns/op 0 B/op 0 allocs/op
BenchmarkCompareGencheck/TestMap_Fail-8 10000000 173 ns/op 128 B/op 4 allocs/op
BenchmarkCompareGencheck/TestDive_Pass-8 100000000 23.8 ns/op 0 B/op 0 allocs/op
BenchmarkCompareGencheck/TestDive_Fail-8 1000000 1271 ns/op 800 B/op 15 allocs/op
BenchmarkCompareGencheck/TestDive_Nil-8 10000000 193 ns/op 128 B/op 4 allocs/op
BenchmarkCompareGencheck/TestAll_Pass-8 500000 2682 ns/op 328 B/op 6 allocs/op
BenchmarkCompareGencheck/TestAll_Fail-8 10000000 201 ns/op 128 B/op 4 allocs/op
BenchmarkCompareGencheck/UUID_Pass-12 3019042 413 ns/op 0 B/op 0 allocs/op
BenchmarkCompareGencheck/UUID_Fail-12 1584471 756 ns/op 208 B/op 6 allocs/op
BenchmarkCompareGencheck/Hex_Pass-12 3540170 350 ns/op 0 B/op 0 allocs/op
BenchmarkCompareGencheck/Hex_Fail-12 1829170 651 ns/op 192 B/op 6 allocs/op
BenchmarkCompareGencheck/ContainsAny_Pass-12 31153759 33.7 ns/op 0 B/op 0 allocs/op
BenchmarkCompareGencheck/ContainsAny_Fail-12 6937201 172 ns/op 128 B/op 4 allocs/op
BenchmarkCompareGencheck/TestStrings_Pass-12 169096743 7.32 ns/op 0 B/op 0 allocs/op
BenchmarkCompareGencheck/TestStrings_Fail-12 8132941 143 ns/op 128 B/op 4 allocs/op
BenchmarkCompareGencheck/TestMap_Pass-12 197221968 6.07 ns/op 0 B/op 0 allocs/op
BenchmarkCompareGencheck/TestMap_Fail-12 8839633 140 ns/op 128 B/op 4 allocs/op
BenchmarkCompareGencheck/TestDive_Pass-12 80319295 15.1 ns/op 0 B/op 0 allocs/op
BenchmarkCompareGencheck/TestDive_Fail-12 1629925 751 ns/op 592 B/op 13 allocs/op
BenchmarkCompareGencheck/TestDive_Nil-12 9048465 137 ns/op 128 B/op 4 allocs/op
BenchmarkCompareGencheck/TestAll_Pass-12 714092 1758 ns/op 328 B/op 6 allocs/op
BenchmarkCompareGencheck/TestAll_Fail-12 8258488 154 ns/op 128 B/op 4 allocs/op
PASS
ok github.com/abice/gencheck/internal/benchmark 30.099s
ok github.com/abice/gencheck/internal/benchmark 23.385s
```
32 changes: 16 additions & 16 deletions benchmark_nooptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
goos: darwin
goarch: amd64
pkg: github.com/abice/gencheck/internal/benchmark
BenchmarkCompareGencheck/UUID_Pass-8 2000000 818 ns/op 16 B/op 1 allocs/op
BenchmarkCompareGencheck/UUID_Fail-8 1000000 1230 ns/op 208 B/op 6 allocs/op
BenchmarkCompareGencheck/Hex_Pass-8 2000000 537 ns/op 16 B/op 1 allocs/op
BenchmarkCompareGencheck/Hex_Fail-8 2000000 862 ns/op 192 B/op 6 allocs/op
BenchmarkCompareGencheck/ContainsAny_Pass-8 20000000 94.0 ns/op 16 B/op 1 allocs/op
BenchmarkCompareGencheck/ContainsAny_Fail-8 5000000 265 ns/op 128 B/op 4 allocs/op
BenchmarkCompareGencheck/TestStrings_Pass-8 20000000 88.3 ns/op 64 B/op 1 allocs/op
BenchmarkCompareGencheck/TestStrings_Fail-8 3000000 541 ns/op 416 B/op 10 allocs/op
BenchmarkCompareGencheck/TestMap_Pass-8 30000000 54.4 ns/op 16 B/op 1 allocs/op
BenchmarkCompareGencheck/TestMap_Fail-8 10000000 211 ns/op 128 B/op 4 allocs/op
BenchmarkCompareGencheck/TestDive_Pass-8 20000000 114 ns/op 32 B/op 2 allocs/op
BenchmarkCompareGencheck/TestDive_Fail-8 1000000 1284 ns/op 800 B/op 15 allocs/op
BenchmarkCompareGencheck/TestDive_Nil-8 10000000 204 ns/op 128 B/op 4 allocs/op
BenchmarkCompareGencheck/TestAll_Pass-8 500000 2927 ns/op 632 B/op 8 allocs/op
BenchmarkCompareGencheck/TestAll_Fail-8 300000 6046 ns/op 2929 B/op 56 allocs/op
BenchmarkCompareGencheck/UUID_Pass-12 2869220 407 ns/op 16 B/op 1 allocs/op
BenchmarkCompareGencheck/UUID_Fail-12 1858568 645 ns/op 208 B/op 6 allocs/op
BenchmarkCompareGencheck/Hex_Pass-12 3280252 365 ns/op 16 B/op 1 allocs/op
BenchmarkCompareGencheck/Hex_Fail-12 1954568 632 ns/op 192 B/op 6 allocs/op
BenchmarkCompareGencheck/ContainsAny_Pass-12 21148444 56.3 ns/op 16 B/op 1 allocs/op
BenchmarkCompareGencheck/ContainsAny_Fail-12 7321660 167 ns/op 128 B/op 4 allocs/op
BenchmarkCompareGencheck/TestStrings_Pass-12 19691707 65.2 ns/op 64 B/op 1 allocs/op
BenchmarkCompareGencheck/TestStrings_Fail-12 3345627 363 ns/op 416 B/op 10 allocs/op
BenchmarkCompareGencheck/TestMap_Pass-12 39226683 31.0 ns/op 16 B/op 1 allocs/op
BenchmarkCompareGencheck/TestMap_Fail-12 9257938 131 ns/op 128 B/op 4 allocs/op
BenchmarkCompareGencheck/TestDive_Pass-12 18120820 67.3 ns/op 32 B/op 2 allocs/op
BenchmarkCompareGencheck/TestDive_Fail-12 1685066 704 ns/op 592 B/op 13 allocs/op
BenchmarkCompareGencheck/TestDive_Nil-12 9715989 130 ns/op 128 B/op 4 allocs/op
BenchmarkCompareGencheck/TestAll_Pass-12 644622 1933 ns/op 632 B/op 8 allocs/op
BenchmarkCompareGencheck/TestAll_Fail-12 316861 4088 ns/op 2722 B/op 54 allocs/op
PASS
ok github.com/abice/gencheck/internal/benchmark 28.927s
ok github.com/abice/gencheck/internal/benchmark 22.311s
```
32 changes: 16 additions & 16 deletions benchmark_noprealloc.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
goos: darwin
goarch: amd64
pkg: github.com/abice/gencheck/internal/benchmark
BenchmarkCompareGencheck/UUID_Pass-8 2000000 855 ns/op 0 B/op 0 allocs/op
BenchmarkCompareGencheck/UUID_Fail-8 1000000 1161 ns/op 208 B/op 6 allocs/op
BenchmarkCompareGencheck/Hex_Pass-8 3000000 507 ns/op 0 B/op 0 allocs/op
BenchmarkCompareGencheck/Hex_Fail-8 2000000 861 ns/op 192 B/op 6 allocs/op
BenchmarkCompareGencheck/ContainsAny_Pass-8 30000000 43.2 ns/op 0 B/op 0 allocs/op
BenchmarkCompareGencheck/ContainsAny_Fail-8 10000000 236 ns/op 128 B/op 4 allocs/op
BenchmarkCompareGencheck/TestStrings_Pass-8 200000000 7.11 ns/op 0 B/op 0 allocs/op
BenchmarkCompareGencheck/TestStrings_Fail-8 2000000 594 ns/op 464 B/op 12 allocs/op
BenchmarkCompareGencheck/TestMap_Pass-8 200000000 8.49 ns/op 0 B/op 0 allocs/op
BenchmarkCompareGencheck/TestMap_Fail-8 10000000 175 ns/op 128 B/op 4 allocs/op
BenchmarkCompareGencheck/TestDive_Pass-8 50000000 24.0 ns/op 0 B/op 0 allocs/op
BenchmarkCompareGencheck/TestDive_Fail-8 1000000 1159 ns/op 800 B/op 15 allocs/op
BenchmarkCompareGencheck/TestDive_Nil-8 10000000 167 ns/op 128 B/op 4 allocs/op
BenchmarkCompareGencheck/TestAll_Pass-8 1000000 2300 ns/op 328 B/op 6 allocs/op
BenchmarkCompareGencheck/TestAll_Fail-8 300000 5777 ns/op 3649 B/op 61 allocs/op
BenchmarkCompareGencheck/UUID_Pass-12 3060320 388 ns/op 0 B/op 0 allocs/op
BenchmarkCompareGencheck/UUID_Fail-12 1633210 675 ns/op 208 B/op 6 allocs/op
BenchmarkCompareGencheck/Hex_Pass-12 3488574 345 ns/op 0 B/op 0 allocs/op
BenchmarkCompareGencheck/Hex_Fail-12 1812626 663 ns/op 192 B/op 6 allocs/op
BenchmarkCompareGencheck/ContainsAny_Pass-12 36120229 34.1 ns/op 0 B/op 0 allocs/op
BenchmarkCompareGencheck/ContainsAny_Fail-12 6942110 171 ns/op 128 B/op 4 allocs/op
BenchmarkCompareGencheck/TestStrings_Pass-12 168171955 7.15 ns/op 0 B/op 0 allocs/op
BenchmarkCompareGencheck/TestStrings_Fail-12 2564859 461 ns/op 464 B/op 12 allocs/op
BenchmarkCompareGencheck/TestMap_Pass-12 188108667 6.45 ns/op 0 B/op 0 allocs/op
BenchmarkCompareGencheck/TestMap_Fail-12 8653820 141 ns/op 128 B/op 4 allocs/op
BenchmarkCompareGencheck/TestDive_Pass-12 77069458 15.9 ns/op 0 B/op 0 allocs/op
BenchmarkCompareGencheck/TestDive_Fail-12 1583066 727 ns/op 592 B/op 13 allocs/op
BenchmarkCompareGencheck/TestDive_Nil-12 8740198 132 ns/op 128 B/op 4 allocs/op
BenchmarkCompareGencheck/TestAll_Pass-12 695394 1772 ns/op 328 B/op 6 allocs/op
BenchmarkCompareGencheck/TestAll_Fail-12 286522 4457 ns/op 3443 B/op 59 allocs/op
PASS
ok github.com/abice/gencheck/internal/benchmark 29.262s
ok github.com/abice/gencheck/internal/benchmark 23.473s
```
28 changes: 14 additions & 14 deletions benchmark_playground.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
goos: darwin
goarch: amd64
pkg: github.com/abice/gencheck/internal/benchmark
BenchmarkComparePlayground/UUID_Pass-8 2000000 880 ns/op 16 B/op 1 allocs/op
BenchmarkComparePlayground/UUID_Fail-8 1000000 1168 ns/op 224 B/op 5 allocs/op
BenchmarkComparePlayground/Hex_Pass-8 2000000 621 ns/op 0 B/op 0 allocs/op
BenchmarkComparePlayground/Hex_Fail-8 2000000 850 ns/op 208 B/op 4 allocs/op
BenchmarkComparePlayground/ContainsAny_Pass-8 10000000 170 ns/op 0 B/op 0 allocs/op
BenchmarkComparePlayground/ContainsAny_Fail-8 3000000 412 ns/op 224 B/op 4 allocs/op
BenchmarkComparePlayground/TestStrings_Pass-8 3000000 425 ns/op 16 B/op 1 allocs/op
BenchmarkComparePlayground/TestStrings_Fail-8 1000000 1240 ns/op 816 B/op 13 allocs/op
BenchmarkComparePlayground/UUID_Pass-12 2187891 594 ns/op 16 B/op 1 allocs/op
BenchmarkComparePlayground/UUID_Fail-12 1668792 754 ns/op 224 B/op 5 allocs/op
BenchmarkComparePlayground/Hex_Pass-12 2723215 434 ns/op 0 B/op 0 allocs/op
BenchmarkComparePlayground/Hex_Fail-12 1905054 644 ns/op 208 B/op 4 allocs/op
BenchmarkComparePlayground/ContainsAny_Pass-12 9700926 126 ns/op 0 B/op 0 allocs/op
BenchmarkComparePlayground/ContainsAny_Fail-12 3581966 323 ns/op 224 B/op 4 allocs/op
BenchmarkComparePlayground/TestStrings_Pass-12 3550527 342 ns/op 16 B/op 1 allocs/op
BenchmarkComparePlayground/TestStrings_Fail-12 1000000 1058 ns/op 816 B/op 13 allocs/op
--- SKIP: BenchmarkComparePlayground/TestMap_Pass
--- SKIP: BenchmarkComparePlayground/TestMap_Fail
BenchmarkComparePlayground/TestDive_Pass-8 5000000 327 ns/op 32 B/op 2 allocs/op
BenchmarkComparePlayground/TestDive_Fail-8 3000000 591 ns/op 272 B/op 7 allocs/op
BenchmarkComparePlayground/TestDive_Nil-8 5000000 338 ns/op 208 B/op 4 allocs/op
BenchmarkComparePlayground/TestAll_Pass-8 500000 4019 ns/op 408 B/op 11 allocs/op
BenchmarkComparePlayground/TestAll_Fail-8 200000 6275 ns/op 4209 B/op 51 allocs/op
BenchmarkComparePlayground/TestDive_Pass-12 4978272 240 ns/op 32 B/op 2 allocs/op
BenchmarkComparePlayground/TestDive_Fail-12 2600906 479 ns/op 272 B/op 7 allocs/op
BenchmarkComparePlayground/TestDive_Nil-12 4445193 273 ns/op 208 B/op 4 allocs/op
BenchmarkComparePlayground/TestAll_Pass-12 339356 3064 ns/op 408 B/op 11 allocs/op
BenchmarkComparePlayground/TestAll_Fail-12 223174 5596 ns/op 4211 B/op 51 allocs/op
PASS
ok github.com/abice/gencheck/internal/benchmark 24.609s
ok github.com/abice/gencheck/internal/benchmark 19.918s
```
18 changes: 18 additions & 0 deletions deps.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
GOBINDATA=bin/go/github.com/kevinburke/go-bindata/go-bindata
GOIMPORTS=bin/go/golang.org/x/tools/cmd/goimports
GOVERALLS=bin/go/github.com/mattn/goveralls
MOCKGEN=bin/go/github.com/golang/mock/mockgen
TOOLS = $(GOBINDATA) \
$(GOIMPORTS) \
$(MOCKGEN) \
$(GOVERALLS)

cleandeps:
if [ -d "./bin" ]; then rm -rf "./bin"; fi

freshdeps: cleandeps deps

deps: $(TOOLS)
bin/go/%:
@echo "installing $*"
$(GO) build -o bin/go/$* $*
Loading

0 comments on commit 0cda63a

Please sign in to comment.