From e3675b2c60e992e6c18ab300e5349c6f0b71cdba Mon Sep 17 00:00:00 2001 From: Phil Prasek Date: Sat, 14 Apr 2018 04:53:10 -0700 Subject: [PATCH 1/5] ci enhancements --- .gitignore | 1 + .travis.yml | 20 +++- Makefile | 9 ++ ci.sh | 93 ++++++++++++++- desc/descriptor.go | 4 +- desc/protoparse/lexer.go | 108 +++++++++--------- dynamic/text.go | 2 - internal/testprotos/make_protos.sh | 4 + .../testprotos/nopkg/desc_test_nopkg.pb.go | 20 +--- .../nopkg/desc_test_nopkg_new.pb.go | 22 +++- 10 files changed, 198 insertions(+), 85 deletions(-) create mode 100644 Makefile diff --git a/.gitignore b/.gitignore index 74682fe5..02a29a0f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ internal/testprotos/protoc +coverage.out diff --git a/.travis.yml b/.travis.yml index bb84b597..a542a65d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,11 +3,21 @@ sudo: false matrix: include: - - go: 1.6 - - go: 1.7 - - go: 1.8 - - go: 1.9 + - go: "1.7" + - go: "1.8" + - go: "1.9" + - go: "1.10" - go: tip +before_install: + - mkdir -p $TRAVIS_BUILD_DIR $GOPATH/src/github.com/jhump + - test ! -d $GOPATH/src/github.com/jhump/protoreflect && mv $TRAVIS_BUILD_DIR $GOPATH/src/github.com/jhump/protoreflect || true + +install: + - make install + script: - - ./ci.sh + - make test + +after_success: + - bash <(curl -s https://codecov.io/bash) -f coverage.out diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..bcf4c3ec --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ + +install: + go get -v ./... + +generate: + cd internal/testprotos && ./make_protos.sh && cd - + +test: + ./ci.sh diff --git a/ci.sh b/ci.sh index ea7c0e70..eef66601 100755 --- a/ci.sh +++ b/ci.sh @@ -1,5 +1,11 @@ #!/usr/bin/env bash -set -e +set +e + +RED=$'\033[31m' +GREEN=$'\033[32m' +TEXTRESET=$'\033[0m' # reset the foreground colour + +REPO=github.com/jhump/protoreflect gover="$(go version | awk '{ print $3 }')" @@ -11,6 +17,8 @@ gover="$(go version | awk '{ print $3 }')" # The second term removes "devel" prefix, so if the two # strings are equal, it does not have that prefix, and # thus this is not a devel version. +echo +echo '+ gofmt -s -l ./' if [[ ${gover} == ${gover#devel*} ]]; then fmtdiff="$(gofmt -s -l ./)" if [[ -n "$fmtdiff" ]]; then @@ -20,4 +28,85 @@ if [[ ${gover} == ${gover#devel*} ]]; then fi fi -go test -v -race ./... +# This helper function walks the current directory looking for directories +# holding certain files ($1 parameter), and prints their paths on standard +# output, one per line. +find_dirs() { + find . -not \( \ + \( \ + -path './.git/*' \ + ${2:+-o -path "$2"} \ + \) \ + -prune \ + \) -name "$1" -print0 | xargs -0n1 dirname | sort -u +} + +if [ -z "$VETDIRS" ]; then + VETDIRS=$(find_dirs '*.go' './internal/testprotos/*') +fi + +if [ -z "$TESTDIRS" ]; then + TESTDIRS=$(find_dirs '*_test.go') +fi + +declare -A TESTS_FAILED + +TESTFLAGS="-v -race -cover -coverprofile=profile.out -covermode=atomic" + +echo + +for dir in $VETDIRS; do + echo '+ go vet' "./${dir#./}" + go vet "${REPO}/${dir#./}" + if [ $? != 0 ]; then + TESTS_FAILED["${dir}"]="go vet failed" + echo "${RED}go vet failed: $dir${TEXTRESET}" + echo + fi +done + +echo + +echo "mode: atomic" > coverage.out + +for dir in $TESTDIRS; do + echo '+ go test' $TESTFLAGS "./${dir#./}" + go test -i "${REPO}/${dir#./}" >& /dev/null # install dependencies, don't execute + go test ${TESTFLAGS} "${REPO}/${dir#./}" >& test.log + + if [ $? != 0 ]; then + TESTS_FAILED["${dir}"]="go test failed" + echo "${RED}Tests failed: $dir${TEXTRESET}" + cat test.log + echo + fi + rm test.log + + if [ -f profile.out ]; then + tail -n +2 profile.out >> coverage.out; rm profile.out + fi +done + +for FAILED in "${!TESTS_FAILED[@]}" +do + text=${TESTS_FAILED[${FAILED}]} + echo ${RED}${FAILED}${TEXTRESET} + if [ "${text}" == "go vet failed" ] + then + echo " "${RED}${text}${TEXTRESET} + fi +done + +echo + +# if some tests fail, we want the bundlescript to fail, but we want to +# try running ALL the tests first, hence TESTS_FAILED +if [ "${#TESTS_FAILED[@]}" -gt 0 ]; then + echo "${RED}Test failures in: ${!TESTS_FAILED[@]}${TEXTRESET}" + echo + exit 1 +else + echo "${GREEN}Test success${TEXTRESET}" + echo + true +fi diff --git a/desc/descriptor.go b/desc/descriptor.go index f85298fe..57a169d2 100644 --- a/desc/descriptor.go +++ b/desc/descriptor.go @@ -422,7 +422,9 @@ func createMessageDescriptor(fd *FileDescriptor, parent Descriptor, enclosing st // proto.ExtensionRange is inclusive (and that's how extension ranges are defined in code). // but protoc converts range to exclusive end in descriptor, so we must convert back end := r.GetEnd() - 1 - ret.extRanges = append(ret.extRanges, proto.ExtensionRange{r.GetStart(), end}) + ret.extRanges = append(ret.extRanges, proto.ExtensionRange{ + Start: r.GetStart(), + End: end}) } sort.Sort(ret.extRanges) ret.isProto3 = fd.isProto3 diff --git a/desc/protoparse/lexer.go b/desc/protoparse/lexer.go index 0e5340ce..547f152a 100644 --- a/desc/protoparse/lexer.go +++ b/desc/protoparse/lexer.go @@ -17,7 +17,7 @@ type runeReader struct { err error } -func (rr *runeReader) ReadRune() (r rune, size int, err error) { +func (rr *runeReader) readRune() (r rune, size int, err error) { if rr.err != nil { return 0, 0, rr.err } @@ -33,7 +33,7 @@ func (rr *runeReader) ReadRune() (r rune, size int, err error) { return r, sz, err } -func (rr *runeReader) UnreadRune(r rune) { +func (rr *runeReader) unreadRune(r rune) { rr.unread = append(rr.unread, r) } @@ -253,7 +253,7 @@ func (l *protoLex) Lex(lval *protoSymType) int { } for { - c, n, err := l.input.ReadRune() + c, n, err := l.input.readRune() if err == io.EOF { // we're not actually returning a rune, but this will associate // accumulated comments as a trailing comment on last symbol @@ -284,7 +284,7 @@ func (l *protoLex) Lex(lval *protoSymType) int { if c == '.' { // tokens that start with a dot include type names and decimal literals - cn, _, err := l.input.ReadRune() + cn, _, err := l.input.readRune() if err != nil { setRune() return int(c) @@ -308,7 +308,7 @@ func (l *protoLex) Lex(lval *protoSymType) int { setFloat(f) return _FLOAT_LIT } - l.input.UnreadRune(cn) + l.input.unreadRune(cn) setRune() return int(c) } @@ -333,15 +333,15 @@ func (l *protoLex) Lex(lval *protoSymType) int { if c >= '0' && c <= '9' { // integer or float literal if c == '0' { - cn, _, err := l.input.ReadRune() + cn, _, err := l.input.readRune() if err != nil { setInt(0) return _INT_LIT } if cn == 'x' || cn == 'X' { - cnn, _, err := l.input.ReadRune() + cnn, _, err := l.input.readRune() if err != nil { - l.input.UnreadRune(cn) + l.input.unreadRune(cn) setInt(0) return _INT_LIT } @@ -358,12 +358,12 @@ func (l *protoLex) Lex(lval *protoSymType) int { setInt(ui) return _INT_LIT } - l.input.UnreadRune(cnn) - l.input.UnreadRune(cn) + l.input.unreadRune(cnn) + l.input.unreadRune(cn) setInt(0) return _INT_LIT } else { - l.input.UnreadRune(cn) + l.input.unreadRune(cn) } } token := []rune{c} @@ -402,7 +402,7 @@ func (l *protoLex) Lex(lval *protoSymType) int { if c == '/' { // comment - cn, _, err := l.input.ReadRune() + cn, _, err := l.input.readRune() if err != nil { setRune() return int(c) @@ -429,7 +429,7 @@ func (l *protoLex) Lex(lval *protoSymType) int { } continue } - l.input.UnreadRune(cn) + l.input.unreadRune(cn) } setRune() @@ -440,24 +440,24 @@ func (l *protoLex) Lex(lval *protoSymType) int { func (l *protoLex) readNumber(sofar []rune, allowDot bool, allowExp bool) []rune { token := sofar for { - c, _, err := l.input.ReadRune() + c, _, err := l.input.readRune() if err != nil { break } if c == '.' { if !allowDot { - l.input.UnreadRune(c) + l.input.unreadRune(c) break } allowDot = false - cn, _, err := l.input.ReadRune() + cn, _, err := l.input.readRune() if err != nil { - l.input.UnreadRune(c) + l.input.unreadRune(c) break } if cn < '0' || cn > '9' { - l.input.UnreadRune(cn) - l.input.UnreadRune(c) + l.input.unreadRune(cn) + l.input.unreadRune(c) break } l.colNo++ @@ -465,26 +465,26 @@ func (l *protoLex) readNumber(sofar []rune, allowDot bool, allowExp bool) []rune c = cn } else if c == 'e' || c == 'E' { if !allowExp { - l.input.UnreadRune(c) + l.input.unreadRune(c) break } allowExp = false - cn, _, err := l.input.ReadRune() + cn, _, err := l.input.readRune() if err != nil { - l.input.UnreadRune(c) + l.input.unreadRune(c) break } if cn == '-' || cn == '+' { - cnn, _, err := l.input.ReadRune() + cnn, _, err := l.input.readRune() if err != nil { - l.input.UnreadRune(cn) - l.input.UnreadRune(c) + l.input.unreadRune(cn) + l.input.unreadRune(c) break } if cnn < '0' || cnn > '9' { - l.input.UnreadRune(cnn) - l.input.UnreadRune(cn) - l.input.UnreadRune(c) + l.input.unreadRune(cnn) + l.input.unreadRune(cn) + l.input.unreadRune(c) break } l.colNo++ @@ -492,15 +492,15 @@ func (l *protoLex) readNumber(sofar []rune, allowDot bool, allowExp bool) []rune c = cn cn = cnn } else if cn < '0' || cn > '9' { - l.input.UnreadRune(cn) - l.input.UnreadRune(c) + l.input.unreadRune(cn) + l.input.unreadRune(c) break } l.colNo++ token = append(token, c) c = cn } else if c < '0' || c > '9' { - l.input.UnreadRune(c) + l.input.unreadRune(c) break } l.colNo++ @@ -512,12 +512,12 @@ func (l *protoLex) readNumber(sofar []rune, allowDot bool, allowExp bool) []rune func (l *protoLex) readHexNumber(sofar []rune) []rune { token := sofar for { - c, _, err := l.input.ReadRune() + c, _, err := l.input.readRune() if err != nil { break } if (c < 'a' || c > 'f') && (c < 'A' || c > 'F') && (c < '0' || c > '9') { - l.input.UnreadRune(c) + l.input.unreadRune(c) break } l.colNo++ @@ -529,26 +529,26 @@ func (l *protoLex) readHexNumber(sofar []rune) []rune { func (l *protoLex) readIdentifier(sofar []rune) []rune { token := sofar for { - c, _, err := l.input.ReadRune() + c, _, err := l.input.readRune() if err != nil { break } if c == '.' { - cn, _, err := l.input.ReadRune() + cn, _, err := l.input.readRune() if err != nil { - l.input.UnreadRune(c) + l.input.unreadRune(c) break } if cn != '_' && (cn < 'a' || cn > 'z') && (cn < 'A' || cn > 'Z') { - l.input.UnreadRune(cn) - l.input.UnreadRune(c) + l.input.unreadRune(cn) + l.input.unreadRune(c) break } l.colNo++ token = append(token, c) c = cn } else if c != '_' && (c < 'a' || c > 'z') && (c < 'A' || c > 'Z') && (c < '0' || c > '9') { - l.input.UnreadRune(c) + l.input.unreadRune(c) break } l.colNo++ @@ -560,7 +560,7 @@ func (l *protoLex) readIdentifier(sofar []rune) []rune { func (l *protoLex) readStringLiteral(quote rune) (string, error) { var buf bytes.Buffer for { - c, _, err := l.input.ReadRune() + c, _, err := l.input.readRune() if err != nil { if err == io.EOF { err = io.ErrUnexpectedEOF @@ -581,25 +581,25 @@ func (l *protoLex) readStringLiteral(quote rune) (string, error) { } if c == '\\' { // escape sequence - c, _, err = l.input.ReadRune() + c, _, err = l.input.readRune() if err != nil { return "", err } l.colNo++ if c == 'x' || c == 'X' { // hex escape - c, _, err := l.input.ReadRune() + c, _, err := l.input.readRune() if err != nil { return "", err } l.colNo++ - c2, _, err := l.input.ReadRune() + c2, _, err := l.input.readRune() if err != nil { return "", err } var hex string if (c2 < '0' || c2 > '9') && (c2 < 'a' || c2 > 'f') && (c2 < 'A' || c2 > 'F') { - l.input.UnreadRune(c2) + l.input.unreadRune(c2) hex = string(c) } else { l.colNo++ @@ -613,22 +613,22 @@ func (l *protoLex) readStringLiteral(quote rune) (string, error) { } else if c >= '0' && c <= '7' { // octal escape - c2, _, err := l.input.ReadRune() + c2, _, err := l.input.readRune() if err != nil { return "", err } var octal string if c2 < '0' || c2 > '7' { - l.input.UnreadRune(c2) + l.input.unreadRune(c2) octal = string(c) } else { l.colNo++ - c3, _, err := l.input.ReadRune() + c3, _, err := l.input.readRune() if err != nil { return "", err } if c3 < '0' || c3 > '7' { - l.input.UnreadRune(c3) + l.input.unreadRune(c3) octal = string([]rune{c, c2}) } else { l.colNo++ @@ -648,7 +648,7 @@ func (l *protoLex) readStringLiteral(quote rune) (string, error) { // short unicode escape u := make([]rune, 4) for i := range u { - c, _, err := l.input.ReadRune() + c, _, err := l.input.readRune() if err != nil { return "", err } @@ -665,7 +665,7 @@ func (l *protoLex) readStringLiteral(quote rune) (string, error) { // long unicode escape u := make([]rune, 8) for i := range u { - c, _, err := l.input.ReadRune() + c, _, err := l.input.readRune() if err != nil { return "", err } @@ -716,7 +716,7 @@ func (l *protoLex) readStringLiteral(quote rune) (string, error) { func (l *protoLex) skipToEndOfLineComment() (bool, string) { txt := []rune{'/', '/'} for { - c, _, err := l.input.ReadRune() + c, _, err := l.input.readRune() if err != nil { return false, string(txt) } @@ -731,7 +731,7 @@ func (l *protoLex) skipToEndOfLineComment() (bool, string) { func (l *protoLex) skipToEndOfBlockComment() (string, bool) { txt := []rune{'/', '*'} for { - c, _, err := l.input.ReadRune() + c, _, err := l.input.readRune() if err != nil { return "", false } @@ -743,7 +743,7 @@ func (l *protoLex) skipToEndOfBlockComment() (string, bool) { } txt = append(txt, c) if c == '*' { - c, _, err := l.input.ReadRune() + c, _, err := l.input.readRune() if err != nil { return "", false } @@ -752,7 +752,7 @@ func (l *protoLex) skipToEndOfBlockComment() (string, bool) { txt = append(txt, c) return string(txt), true } - l.input.UnreadRune(c) + l.input.unreadRune(c) } } } diff --git a/dynamic/text.go b/dynamic/text.go index 2c49bb45..a0c8fba8 100644 --- a/dynamic/text.go +++ b/dynamic/text.go @@ -430,7 +430,6 @@ func marshalUnknownGroupText(b *indentBuffer, in *codedBuffer, topLevel bool) er } } } - return nil } func (m *Message) UnmarshalText(text []byte) error { @@ -541,7 +540,6 @@ func (m *Message) unmarshalText(tr *txtReader, end tokenType) error { tr.next() // consume separator } } - return nil } func textError(tok *token, format string, args ...interface{}) error { diff --git a/internal/testprotos/make_protos.sh b/internal/testprotos/make_protos.sh index 18c9cbe8..540fb43f 100755 --- a/internal/testprotos/make_protos.sh +++ b/internal/testprotos/make_protos.sh @@ -24,6 +24,10 @@ if [[ "$(${PROTOC} --version 2>/dev/null)" != "libprotoc ${PROTOC_VERSION}" ]]; cd ./protoc && unzip protoc.zip && cd .. fi +cd ${GOPATH}/src/github.com/golang/protobuf/protoc-gen-go +go install +cd - + # Output directory will effectively be GOPATH/src. outdir="../../../../.." ${PROTOC} "--go_out=plugins=grpc:$outdir" -I. *.proto diff --git a/internal/testprotos/nopkg/desc_test_nopkg.pb.go b/internal/testprotos/nopkg/desc_test_nopkg.pb.go index 677ce827..d1c6b23c 100644 --- a/internal/testprotos/nopkg/desc_test_nopkg.pb.go +++ b/internal/testprotos/nopkg/desc_test_nopkg.pb.go @@ -1,16 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // source: nopkg/desc_test_nopkg.proto -/* -Package nopkg is a generated protocol buffer package. - -It is generated from these files: - nopkg/desc_test_nopkg.proto - nopkg/desc_test_nopkg_new.proto - -It has these top-level messages: - TopLevel -*/ package nopkg import proto "github.com/golang/protobuf/proto" @@ -22,17 +12,11 @@ var _ = proto.Marshal var _ = fmt.Errorf var _ = math.Inf -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - // Ignoring public import of TopLevel from nopkg/desc_test_nopkg_new.proto -func init() { proto.RegisterFile("nopkg/desc_test_nopkg.proto", fileDescriptor0) } +func init() { proto.RegisterFile("nopkg/desc_test_nopkg.proto", fileDescriptor1) } -var fileDescriptor0 = []byte{ +var fileDescriptor1 = []byte{ // 112 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xce, 0xcb, 0x2f, 0xc8, 0x4e, 0xd7, 0x4f, 0x49, 0x2d, 0x4e, 0x8e, 0x2f, 0x49, 0x2d, 0x2e, 0x89, 0x07, 0xf3, 0xf5, 0x0a, diff --git a/internal/testprotos/nopkg/desc_test_nopkg_new.pb.go b/internal/testprotos/nopkg/desc_test_nopkg_new.pb.go index 1ab2e74b..6ebedad6 100644 --- a/internal/testprotos/nopkg/desc_test_nopkg_new.pb.go +++ b/internal/testprotos/nopkg/desc_test_nopkg_new.pb.go @@ -1,6 +1,16 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // source: nopkg/desc_test_nopkg_new.proto +/* +Package nopkg is a generated protocol buffer package. + +It is generated from these files: + nopkg/desc_test_nopkg_new.proto + nopkg/desc_test_nopkg.proto + +It has these top-level messages: + TopLevel +*/ package nopkg import proto "github.com/golang/protobuf/proto" @@ -12,6 +22,12 @@ var _ = proto.Marshal var _ = fmt.Errorf var _ = math.Inf +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package + type TopLevel struct { I *int32 `protobuf:"varint,1,opt,name=i" json:"i,omitempty"` J *int64 `protobuf:"varint,2,opt,name=j" json:"j,omitempty"` @@ -35,7 +51,7 @@ type TopLevel struct { func (m *TopLevel) Reset() { *m = TopLevel{} } func (m *TopLevel) String() string { return proto.CompactTextString(m) } func (*TopLevel) ProtoMessage() {} -func (*TopLevel) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{0} } +func (*TopLevel) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } var extRange_TopLevel = []proto.ExtensionRange{ {100, 1000}, @@ -154,9 +170,9 @@ func init() { proto.RegisterType((*TopLevel)(nil), "TopLevel") } -func init() { proto.RegisterFile("nopkg/desc_test_nopkg_new.proto", fileDescriptor1) } +func init() { proto.RegisterFile("nopkg/desc_test_nopkg_new.proto", fileDescriptor0) } -var fileDescriptor1 = []byte{ +var fileDescriptor0 = []byte{ // 261 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x1c, 0xd0, 0x3f, 0x6f, 0xf2, 0x40, 0x0c, 0xc7, 0x71, 0xfd, 0xf8, 0x1b, 0xf2, 0xc0, 0x03, 0x65, 0xf2, 0x56, 0xab, 0x93, 0xd5, 0x81, From 41d73dfed2e162f70ee55b94c7d549acfb761a0a Mon Sep 17 00:00:00 2001 From: Phil Prasek Date: Sun, 15 Apr 2018 14:30:39 -0700 Subject: [PATCH 2/5] pr #122 feedback --- .travis.yml | 4 +- Makefile | 84 ++++++++++++++++++++-- ci.sh | 112 ----------------------------- internal/testprotos/make_protos.sh | 4 +- 4 files changed, 83 insertions(+), 121 deletions(-) delete mode 100755 ci.sh diff --git a/.travis.yml b/.travis.yml index a542a65d..48b8b578 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,10 +14,10 @@ before_install: - test ! -d $GOPATH/src/github.com/jhump/protoreflect && mv $TRAVIS_BUILD_DIR $GOPATH/src/github.com/jhump/protoreflect || true install: - - make install + - make deps script: - - make test + - make ci after_success: - bash <(curl -s https://codecov.io/bash) -f coverage.out diff --git a/Makefile b/Makefile index bcf4c3ec..364cd6ca 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,85 @@ +# TODO: run golint, errcheck, staticcheck, unused +.PHONY: default +default: deps checkgofmt vet predeclared test +.PHONY: ci +ci: deps checkgofmt vet predeclared testcover + +.PHONY: deps +deps: + go get -d -v -t ./... + +.PHONY: updatedeps +updatedeps: + go get -d -v -t -u -f ./... + +.PHONY: install install: - go get -v ./... + go install ./... + +.PHONY: checkgofmt +checkgofmt: + gofmt -s -l . + @if [ -n "$$(gofmt -s -l .)" ]; then \ + exit 1; \ + fi + +# workaround https://github.com/golang/protobuf/issues/214 until in master +.PHONY: vet +vet: + @echo go vet ./... --ignore internal/testprotos + @for dir in $$(go list ./... | grep -v 'internal/testprotos'); do \ + go vet $$dir ; \ + done + +.PHONY: staticcheck +staticcheck: + @go get honnef.co/go/tools/cmd/staticcheck + staticcheck ./... + +.PHONY: unused +unused: + @go get honnef.co/go/tools/cmd/unused + unused ./... +.PHONY: ineffassign +ineffassign: + @go get github.com/gordonklaus/ineffassign + ineffassign . + +.PHONY: predeclared +predeclared: + @go get github.com/nishanths/predeclared + predeclared . + +# Intentionally omitted from CI, but target here for ad-hoc reports. +.PHONY: golint +golint: + @go get github.com/golang/lint/golint + golint -min_confidence 0.9 -set_exit_status ./... + +# Intentionally omitted from CI, but target here for ad-hoc reports. +.PHONY: errchack +errcheck: + @go get github.com/kisielk/errcheck + errcheck ./... + +.PHONY: test +test: + go test -cover -race ./... + +.PHONY: generate generate: - cd internal/testprotos && ./make_protos.sh && cd - + go generate github.com/jhump/protoreflect/internal/testprotos/ + +.PHONY: testcover +testcover: + @echo go test -covermode=atomic ./... + @echo "mode: atomic" > coverage.out + @for dir in $$(go list ./...); do \ + go test -race -coverprofile profile.out -covermode=atomic $$dir ; \ + if [ -f profile.out ]; then \ + tail -n +2 profile.out >> coverage.out && rm profile.out ; \ + fi \ + done -test: - ./ci.sh diff --git a/ci.sh b/ci.sh deleted file mode 100755 index eef66601..00000000 --- a/ci.sh +++ /dev/null @@ -1,112 +0,0 @@ -#!/usr/bin/env bash -set +e - -RED=$'\033[31m' -GREEN=$'\033[32m' -TEXTRESET=$'\033[0m' # reset the foreground colour - -REPO=github.com/jhump/protoreflect - -gover="$(go version | awk '{ print $3 }')" - -# We don't run gofmt for devel versions because it -# changed circa 11/2017. So code that passes the gofmt -# check for other versions will fail for devel version. -# For now, just skip the check for devel versions. - -# The second term removes "devel" prefix, so if the two -# strings are equal, it does not have that prefix, and -# thus this is not a devel version. -echo -echo '+ gofmt -s -l ./' -if [[ ${gover} == ${gover#devel*} ]]; then - fmtdiff="$(gofmt -s -l ./)" - if [[ -n "$fmtdiff" ]]; then - gofmt -s -l ./ >&2 - echo "Run gofmt on the above files!" >&2 - exit 1 - fi -fi - -# This helper function walks the current directory looking for directories -# holding certain files ($1 parameter), and prints their paths on standard -# output, one per line. -find_dirs() { - find . -not \( \ - \( \ - -path './.git/*' \ - ${2:+-o -path "$2"} \ - \) \ - -prune \ - \) -name "$1" -print0 | xargs -0n1 dirname | sort -u -} - -if [ -z "$VETDIRS" ]; then - VETDIRS=$(find_dirs '*.go' './internal/testprotos/*') -fi - -if [ -z "$TESTDIRS" ]; then - TESTDIRS=$(find_dirs '*_test.go') -fi - -declare -A TESTS_FAILED - -TESTFLAGS="-v -race -cover -coverprofile=profile.out -covermode=atomic" - -echo - -for dir in $VETDIRS; do - echo '+ go vet' "./${dir#./}" - go vet "${REPO}/${dir#./}" - if [ $? != 0 ]; then - TESTS_FAILED["${dir}"]="go vet failed" - echo "${RED}go vet failed: $dir${TEXTRESET}" - echo - fi -done - -echo - -echo "mode: atomic" > coverage.out - -for dir in $TESTDIRS; do - echo '+ go test' $TESTFLAGS "./${dir#./}" - go test -i "${REPO}/${dir#./}" >& /dev/null # install dependencies, don't execute - go test ${TESTFLAGS} "${REPO}/${dir#./}" >& test.log - - if [ $? != 0 ]; then - TESTS_FAILED["${dir}"]="go test failed" - echo "${RED}Tests failed: $dir${TEXTRESET}" - cat test.log - echo - fi - rm test.log - - if [ -f profile.out ]; then - tail -n +2 profile.out >> coverage.out; rm profile.out - fi -done - -for FAILED in "${!TESTS_FAILED[@]}" -do - text=${TESTS_FAILED[${FAILED}]} - echo ${RED}${FAILED}${TEXTRESET} - if [ "${text}" == "go vet failed" ] - then - echo " "${RED}${text}${TEXTRESET} - fi -done - -echo - -# if some tests fail, we want the bundlescript to fail, but we want to -# try running ALL the tests first, hence TESTS_FAILED -if [ "${#TESTS_FAILED[@]}" -gt 0 ]; then - echo "${RED}Test failures in: ${!TESTS_FAILED[@]}${TEXTRESET}" - echo - exit 1 -else - echo "${GREEN}Test success${TEXTRESET}" - echo - true -fi diff --git a/internal/testprotos/make_protos.sh b/internal/testprotos/make_protos.sh index 540fb43f..a24a92fd 100755 --- a/internal/testprotos/make_protos.sh +++ b/internal/testprotos/make_protos.sh @@ -24,9 +24,7 @@ if [[ "$(${PROTOC} --version 2>/dev/null)" != "libprotoc ${PROTOC_VERSION}" ]]; cd ./protoc && unzip protoc.zip && cd .. fi -cd ${GOPATH}/src/github.com/golang/protobuf/protoc-gen-go -go install -cd - +go install github.com/golang/protobuf/protoc-gen-go # Output directory will effectively be GOPATH/src. outdir="../../../../.." From 163de2a1bd02983a018b15748a752486021a0045 Mon Sep 17 00:00:00 2001 From: Phil Prasek Date: Sun, 15 Apr 2018 14:33:10 -0700 Subject: [PATCH 3/5] prune travis.yml --- .travis.yml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 48b8b578..c37ea37d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,15 +9,10 @@ matrix: - go: "1.10" - go: tip +# accomodate forks before_install: - mkdir -p $TRAVIS_BUILD_DIR $GOPATH/src/github.com/jhump - test ! -d $GOPATH/src/github.com/jhump/protoreflect && mv $TRAVIS_BUILD_DIR $GOPATH/src/github.com/jhump/protoreflect || true -install: - - make deps - script: - - make ci - -after_success: - - bash <(curl -s https://codecov.io/bash) -f coverage.out + - make From 5d1c5ad7410c8afa6fc4b6c6226bfab641c1f99a Mon Sep 17 00:00:00 2001 From: Phil Prasek Date: Sun, 15 Apr 2018 16:25:28 -0700 Subject: [PATCH 4/5] handle gofmt for devel version --- Makefile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 364cd6ca..8e194e9a 100644 --- a/Makefile +++ b/Makefile @@ -19,9 +19,12 @@ install: .PHONY: checkgofmt checkgofmt: - gofmt -s -l . - @if [ -n "$$(gofmt -s -l .)" ]; then \ - exit 1; \ + @if [ -n "$$(go version | awk '{ print $$3 }' | grep -v devel)" ]; then \ + gofmt -s -l . ; \ + if [ -n "$$(gofmt -s -l .)" ]; then \ + echo "Run gofmt on the above files!"; \ + exit 1; \ + fi; \ fi # workaround https://github.com/golang/protobuf/issues/214 until in master From ad5847cd010bc9dc180115b348578717d79353b8 Mon Sep 17 00:00:00 2001 From: Phil Prasek Date: Sun, 15 Apr 2018 16:54:46 -0700 Subject: [PATCH 5/5] fix formatting --- Makefile | 72 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/Makefile b/Makefile index 8e194e9a..af500525 100644 --- a/Makefile +++ b/Makefile @@ -7,82 +7,82 @@ ci: deps checkgofmt vet predeclared testcover .PHONY: deps deps: - go get -d -v -t ./... + go get -d -v -t ./... .PHONY: updatedeps updatedeps: - go get -d -v -t -u -f ./... + go get -d -v -t -u -f ./... .PHONY: install install: - go install ./... + go install ./... .PHONY: checkgofmt checkgofmt: - @if [ -n "$$(go version | awk '{ print $$3 }' | grep -v devel)" ]; then \ - gofmt -s -l . ; \ - if [ -n "$$(gofmt -s -l .)" ]; then \ - echo "Run gofmt on the above files!"; \ - exit 1; \ - fi; \ - fi + @if [ -n "$$(go version | awk '{ print $$3 }' | grep -v devel)" ]; then \ + gofmt -s -l . ; \ + if [ -n "$$(gofmt -s -l .)" ]; then \ + echo "Run gofmt on the above files!"; \ + exit 1; \ + fi; \ + fi # workaround https://github.com/golang/protobuf/issues/214 until in master .PHONY: vet vet: - @echo go vet ./... --ignore internal/testprotos - @for dir in $$(go list ./... | grep -v 'internal/testprotos'); do \ - go vet $$dir ; \ - done + @echo go vet ./... --ignore internal/testprotos + @for dir in $$(go list ./... | grep -v 'internal/testprotos'); do \ + go vet $$dir ; \ + done .PHONY: staticcheck staticcheck: - @go get honnef.co/go/tools/cmd/staticcheck - staticcheck ./... + @go get honnef.co/go/tools/cmd/staticcheck + staticcheck ./... .PHONY: unused unused: - @go get honnef.co/go/tools/cmd/unused - unused ./... + @go get honnef.co/go/tools/cmd/unused + unused ./... .PHONY: ineffassign ineffassign: - @go get github.com/gordonklaus/ineffassign - ineffassign . + @go get github.com/gordonklaus/ineffassign + ineffassign . .PHONY: predeclared predeclared: - @go get github.com/nishanths/predeclared - predeclared . + @go get github.com/nishanths/predeclared + predeclared . # Intentionally omitted from CI, but target here for ad-hoc reports. .PHONY: golint golint: - @go get github.com/golang/lint/golint - golint -min_confidence 0.9 -set_exit_status ./... + @go get github.com/golang/lint/golint + golint -min_confidence 0.9 -set_exit_status ./... # Intentionally omitted from CI, but target here for ad-hoc reports. .PHONY: errchack errcheck: - @go get github.com/kisielk/errcheck - errcheck ./... + @go get github.com/kisielk/errcheck + errcheck ./... .PHONY: test test: - go test -cover -race ./... + go test -cover -race ./... .PHONY: generate generate: - go generate github.com/jhump/protoreflect/internal/testprotos/ + go generate github.com/jhump/protoreflect/internal/testprotos/ .PHONY: testcover testcover: - @echo go test -covermode=atomic ./... - @echo "mode: atomic" > coverage.out - @for dir in $$(go list ./...); do \ - go test -race -coverprofile profile.out -covermode=atomic $$dir ; \ - if [ -f profile.out ]; then \ - tail -n +2 profile.out >> coverage.out && rm profile.out ; \ - fi \ - done + @echo go test -covermode=atomic ./... + @echo "mode: atomic" > coverage.out + @for dir in $$(go list ./...); do \ + go test -race -coverprofile profile.out -covermode=atomic $$dir ; \ + if [ -f profile.out ]; then \ + tail -n +2 profile.out >> coverage.out && rm profile.out ; \ + fi \ + done