Skip to content

Commit

Permalink
Switch to gometalinter for linting
Browse files Browse the repository at this point in the history
  • Loading branch information
belak committed Jul 18, 2016
1 parent 8f71d74 commit ec9c1fd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 42 deletions.
9 changes: 6 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ before_install:
- go get github.com/axw/gocov/gocov
- go get github.com/mattn/goveralls
- go get golang.org/x/tools/cmd/cover
- go get github.com/golang/lint/golint
# Test deps
- go get github.com/stretchr/testify
# Linting deps
- go get github.com/alecthomas/gometalinter
- gometalinter --install

script:
- go vet -x ./...
- $HOME/gopath/bin/golint ./...
- gometalinter --fast ./...
- go test -v ./...
- go test -covermode=count -coverprofile=profile.cov

Expand Down
31 changes: 9 additions & 22 deletions conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package irc
import (
"bytes"
"io"
"reflect"
"strings"
"testing"

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

type testReadWriteCloser struct {
Expand Down Expand Up @@ -35,9 +36,7 @@ func (t *testReadWriteCloser) Close() error {

func testReadMessage(t *testing.T, c *Conn) *Message {
m, err := c.ReadMessage()
if err != nil {
t.Error(err)
}
assert.NoError(t, err)
return m
}

Expand All @@ -48,15 +47,11 @@ func testLines(t *testing.T, rwc *testReadWriteCloser, expected []string) {
line, expected = expected[0], expected[1:]
clientLine, lines = lines[0], lines[1:]

if line != clientLine {
t.Errorf("Expected %s != Got %s", line, clientLine)
}
assert.Equal(t, line, clientLine)
}

for _, line := range lines {
if strings.TrimSpace(line) != "" {
t.Errorf("Extra non-empty lines: %s", line)
}
assert.Equal(t, "", strings.TrimSpace(line), "Extra non-empty lines")
}

// Reset the contents
Expand Down Expand Up @@ -85,9 +80,7 @@ func TestClient(t *testing.T) {
rwc.server.WriteString(m.String() + "\r\n")
m2 := testReadMessage(t, c)

if !reflect.DeepEqual(m, m2) {
t.Errorf("Message returned by client did not match input")
}
assert.EqualValues(t, m, m2, "Message returned by client did not match input")

// Test welcome message
rwc.server.WriteString("001 test_nick\r\n")
Expand All @@ -96,18 +89,12 @@ func TestClient(t *testing.T) {
// Ensure CTCP messages are parsed
rwc.server.WriteString(":world PRIVMSG :\x01VERSION\x01\r\n")
m = testReadMessage(t, c)
if m.Command != "CTCP" {
t.Error("Message was not parsed as CTCP")
}
if m.Trailing() != "VERSION" {
t.Error("Wrong CTCP command")
}
assert.Equal(t, "CTCP", m.Command, "Message was not parsed as CTCP")
assert.Equal(t, "VERSION", m.Trailing(), "Wrong CTCP command")

// This is an odd one... if there wasn't any output, it'll hit
// EOF, so we expect an error here so we can test an error
// condition.
_, err := c.ReadMessage()
if err != io.EOF {
t.Error("Didn't get expected EOF error")
}
assert.Equal(t, io.EOF, err, "Didn't get expected EOF")
}
2 changes: 1 addition & 1 deletion parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func ParseMessage(line string) *Message {
}

// Parse the identity, if there was one
c.Prefix = ParsePrefix(string(split[0][1:]))
c.Prefix = ParsePrefix(split[0][1:])
line = split[1]
}

Expand Down
25 changes: 9 additions & 16 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package irc
import (
"reflect"
"testing"

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

var messageTests = []struct {
Expand Down Expand Up @@ -34,6 +36,7 @@ var messageTests = []struct {
{
Prefix: "server.kevlar.net",
Cmd: "PING",
Params: []string{},

Name: "server.kevlar.net",

Expand Down Expand Up @@ -130,28 +133,18 @@ var messageTests = []struct {
func TestParseMessage(t *testing.T) {
for i, test := range messageTests {
m := ParseMessage(test.Expect)
if m == nil && !test.IsNil {
t.Errorf("%d. Got nil for valid message", i)
} else if m != nil && test.IsNil {
t.Errorf("%d. Didn't get nil for invalid message", i)
if test.IsNil {
assert.Nil(t, m, "%d. Didn't get nil for invalid message.", i)
} else {
assert.NotNil(t, m, "%d. Got nil for valid message.", i)
}

if m == nil {
continue
}

if test.Cmd != m.Command {
t.Errorf("%d. command = %q, want %q", i, m.Command, test.Cmd)
}
if len(test.Params) != len(m.Params) {
t.Errorf("%d. args = %v, want %v", i, m.Params, test.Params)
} else {
for j := 0; j < len(test.Params) && j < len(m.Params); j++ {
if test.Params[j] != m.Params[j] {
t.Errorf("%d. arg[%d] = %q, want %q", i, j, m.Params[j], test.Params[j])
}
}
}
assert.Equal(t, test.Cmd, m.Command, "%d. Command doesn't match.", i)
assert.EqualValues(t, test.Params, m.Params, "%d. Params don't match.", i)
}
}

Expand Down

0 comments on commit ec9c1fd

Please sign in to comment.