Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
language: go
go:
- 1.6.3
- 1.7.3
- 1.11.x
- 1.12.x
sudo: false
install:
- go get -d -t -v ./...
- go get -v golang.org/x/tools/cover
- go get -v github.com/bradfitz/goimports
- go get -v github.com/golang/lint/golint
- go get -v github.com/golangci/golangci-lint/cmd/golangci-lint
script:
- export PATH=$PATH:$HOME/gopath/bin
- export GO111MODULE=on
- ./goclean.sh
after_success:
- go get -v github.com/mattn/goveralls
Expand Down
32 changes: 23 additions & 9 deletions goclean.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
#!/bin/bash
# The script does automatic checking on a Go package and its sub-packages, including:
# 1. gofmt (http://golang.org/cmd/gofmt/)
# 2. goimports (https://github.com/bradfitz/goimports)
# 3. golint (https://github.com/golang/lint)
# 4. go vet (http://golang.org/cmd/vet)
# 5. test coverage (http://blog.golang.org/cover)
# 2. golint (https://github.com/golang/lint)
# 3. go vet (http://golang.org/cmd/vet)
# 4. gosimple (https://github.com/dominikh/go-simple)
# 5. unconvert (https://github.com/mdempsky/unconvert)
# 6. goimports (https://github.com/bradfitz/goimports)
# 7. race detector (http://blog.golang.org/race-detector)
# 8. test coverage (http://blog.golang.org/cover)

set -e
set -ex

# Automatic checks
cd xdr2
test -z "$(gofmt -l -w . | tee /dev/stderr)"
test -z "$(goimports -l -w . | tee /dev/stderr)"
test -z "$(golint . | tee /dev/stderr)"
go vet ./...

# run tests
env GORACE="halt_on_error=1" go test -v -race ./...

# golangci-lint (github.com/golangci/golangci-lint) is used to run each each
# static checker.

# check linters
golangci-lint run --disable-all --deadline=10m \
--enable=gofmt \
--enable=golint \
--enable=vet \
--enable=gosimple \
--enable=unconvert \
--enable=ineffassign \
--enable=goimports

# Run test coverage on each subdirectories and merge the coverage profile.

echo "mode: count" > profile.cov
Expand Down
12 changes: 5 additions & 7 deletions xdr2/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ func TestUnmarshal(t *testing.T) {
// float64 - XDR Double-precision Floating-Point
{[]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, float64(0), 8, nil},
{[]byte{0x40, 0x09, 0x21, 0xfb, 0x54, 0x44, 0x2d, 0x18}, float64(3.141592653589793), 8, nil},
{[]byte{0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, float64(math.Inf(-1)), 8, nil},
{[]byte{0x7F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, float64(math.Inf(0)), 8, nil},
{[]byte{0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, math.Inf(-1), 8, nil},
{[]byte{0x7F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, math.Inf(0), 8, nil},
// Expected Failures -- not enough bytes
{[]byte{0xff, 0xff, 0xff}, float64(0), 3, &UnmarshalError{ErrorCode: ErrIO}},
{[]byte{0xff, 0x00, 0xff, 0x00}, float64(0), 4, &UnmarshalError{ErrorCode: ErrIO}},
Expand Down Expand Up @@ -470,8 +470,8 @@ func TestDecoder(t *testing.T) {
// Double
{fDecodeDouble, []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, float64(0), 8, 0, nil},
{fDecodeDouble, []byte{0x40, 0x09, 0x21, 0xfb, 0x54, 0x44, 0x2d, 0x18}, float64(3.141592653589793), 8, 0, nil},
{fDecodeDouble, []byte{0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, float64(math.Inf(-1)), 8, 0, nil},
{fDecodeDouble, []byte{0x7F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, float64(math.Inf(0)), 8, 0, nil},
{fDecodeDouble, []byte{0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, math.Inf(-1), 8, 0, nil},
{fDecodeDouble, []byte{0x7F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, math.Inf(0), 8, 0, nil},

// Enum
{fDecodeEnum, []byte{0x00, 0x00, 0x00, 0x00}, int32(0), 4, 0, nil},
Expand Down Expand Up @@ -572,9 +572,7 @@ func TestDecoder(t *testing.T) {
}
for _, decoder := range decoders {
for i, test := range tests {
err = nil
var dec *Decoder
dec = decoder(test)
dec := decoder(test)
switch test.f {
case fDecodeBool:
rv, n, err = dec.DecodeBool()
Expand Down
4 changes: 2 additions & 2 deletions xdr2/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (enc *Encoder) EncodeEnum(v int32, validEnums map[int32]bool) (int, error)
// Represented as an XDR encoded enumeration where 0 is false and 1 is true
func (enc *Encoder) EncodeBool(v bool) (int, error) {
i := int32(0)
if v == true {
if v {
i = 1
}
return enc.EncodeInt(i)
Expand Down Expand Up @@ -383,7 +383,7 @@ func (enc *Encoder) encodeFixedArray(v reflect.Value, ignoreOpaque bool) (int, e
// copying the array into a new slice. This is rather ugly, but
// the inability to create a constant slice from an
// unaddressable array is a limitation of Go.
slice := make([]byte, v.Len(), v.Len())
slice := make([]byte, v.Len())
reflect.Copy(reflect.ValueOf(slice), v)
return enc.EncodeFixedOpaque(slice)
}
Expand Down
9 changes: 4 additions & 5 deletions xdr2/encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ func TestMarshal(t *testing.T) {
// float64 - XDR Double-precision Floating-Point
{float64(0), []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 8, nil},
{float64(3.141592653589793), []byte{0x40, 0x09, 0x21, 0xfb, 0x54, 0x44, 0x2d, 0x18}, 8, nil},
{float64(math.Inf(-1)), []byte{0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 8, nil},
{float64(math.Inf(0)), []byte{0x7F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 8, nil},
{math.Inf(-1), []byte{0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 8, nil},
{math.Inf(0), []byte{0x7F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 8, nil},
// Expected Failure -- Short write
{float64(3.141592653589793), []byte{0x40, 0x09, 0x21, 0xfb, 0x54, 0x44, 0x2d}, 7, &MarshalError{ErrorCode: ErrIO}},

Expand Down Expand Up @@ -404,8 +404,8 @@ func TestEncoder(t *testing.T) {
// Double
{fEncodeDouble, float64(0), []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 8, nil},
{fEncodeDouble, float64(3.141592653589793), []byte{0x40, 0x09, 0x21, 0xfb, 0x54, 0x44, 0x2d, 0x18}, 8, nil},
{fEncodeDouble, float64(math.Inf(-1)), []byte{0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 8, nil},
{fEncodeDouble, float64(math.Inf(0)), []byte{0x7F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 8, nil},
{fEncodeDouble, math.Inf(-1), []byte{0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 8, nil},
{fEncodeDouble, math.Inf(0), []byte{0x7F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 8, nil},
// Expected Failure -- Short write
{fEncodeDouble, float64(3.141592653589793), []byte{0x40, 0x09, 0x21, 0xfb, 0x54, 0x44, 0x2d}, 7, &MarshalError{ErrorCode: ErrIO}},

Expand Down Expand Up @@ -493,7 +493,6 @@ func TestEncoder(t *testing.T) {
var n int

for i, test := range tests {
err = nil
data := newFixedWriter(test.wantN)
enc := NewEncoder(data)
switch test.f {
Expand Down
2 changes: 1 addition & 1 deletion xdr2/fixedIO_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (w *fixedWriter) Bytes() []byte {
// newFixedWriter returns a new io.Writer that will error once more bytes than
// the specified max have been written.
func newFixedWriter(max int) *fixedWriter {
b := make([]byte, max, max)
b := make([]byte, max)
fw := fixedWriter{b, 0}
return &fw
}
1 change: 1 addition & 0 deletions xdr2/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module github.com/davecgh/go-xdr/xdr2