diff --git a/.travis.yml b/.travis.yml index 736f045..7dfe24e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/conn_test.go b/conn_test.go index 215fb02..f5f1028 100644 --- a/conn_test.go +++ b/conn_test.go @@ -3,9 +3,10 @@ package irc import ( "bytes" "io" - "reflect" "strings" "testing" + + "github.com/stretchr/testify/assert" ) type testReadWriteCloser struct { @@ -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 } @@ -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 @@ -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") @@ -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") } diff --git a/parser.go b/parser.go index cf1763e..ebd013a 100644 --- a/parser.go +++ b/parser.go @@ -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] } diff --git a/parser_test.go b/parser_test.go index 0e8146c..d5fad32 100644 --- a/parser_test.go +++ b/parser_test.go @@ -3,6 +3,8 @@ package irc import ( "reflect" "testing" + + "github.com/stretchr/testify/assert" ) var messageTests = []struct { @@ -34,6 +36,7 @@ var messageTests = []struct { { Prefix: "server.kevlar.net", Cmd: "PING", + Params: []string{}, Name: "server.kevlar.net", @@ -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) } }