Repository navigation
Port tests from testify and frankban/quicktest to go-quicktest/qt - #85
Merged
Merged
Conversation
…st/qt
The tests used four assertion styles: testify's package functions,
testify's bound require.New(t) form, frankban's *qt.C wrapper, and
frankban's package-level qt.Assert(t, got, checker) form. This collapses
them onto go-quicktest/qt, the successor to frankban/quicktest, whose
generic checker functions are type-checked at compile time.
require.NoError(t, err) -> qt.Assert(t, qt.IsNil(err))
assert.Equal(t, want, got) -> qt.Check(t, qt.Equals(got, want))
assert.Len(t, v, n) -> qt.Check(t, qt.HasLen(v, n))
c.Assert(err, qt.IsNil) -> qt.Assert(t, qt.IsNil(err))
trailing msgAndArgs -> qt.Commentf(...)
Note the argument order flips: testify takes (expected, actual), qt takes
(got, want). assert.* becomes Check and require.* becomes Assert.
Three call sites needed more than a rename:
- require := require.New(t) has no equivalent; the binding is dropped and
t passed explicitly.
- TestMarshalCompactIPv4NodeAddrs assigned assert.NotPanics or
assert.Panics to a variable. qt checkers are values of a different
shape, so the closure is lifted into a local and the branch selects the
checker instead. qt has no NotPanics, so the negative case is
qt.Not(qt.PanicMatches(f, ".*")).
- qt.Contains is split by container type; the AddrMaybeIdsByDistance test
checks a slice, so it becomes qt.SliceContains.
qt.Equals is ==, so comparisons of slices, of krpc.Msg (its NodeAddr field
holds a net.IP, making Msg uncomparable), and of *krpc.Msg (where == would
compare addresses) use DeepEquals. int160.T.Bytes() returns a []byte
compared against a string constant, so that one converts explicitly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013BA3b7BbaJkPeeTYjhvi5g
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The test suite currently uses four assertion styles across 18 files:
require.NoError(t, err)require := require.New(t), thenrequire.NoError(err)*qt.Cwrapper —c := qt.New(t), thenc.Assert(err, qt.IsNil)qt.Check(t, got, qt.IsNil)This collapses all four onto
github.com/go-quicktest/qt(v1.102.0), the successor tofrankban/quicktest, whose generic checker functions are type-checked at compile time (rationale). Bothstretchr/testifyandfrankban/quicktestdrop out ofgo.mod.Translation applied
require.NoError(t, err)qt.Assert(t, qt.IsNil(err))assert.NoError(t, err)qt.Check(t, qt.IsNil(err))assert.Equal/EqualValues(t, want, got)qt.Check(t, qt.Equals(got, want))assert.Len(t, v, n)qt.Check(t, qt.HasLen(v, n))assert.True/False/Nil(t, x)qt.Check(t, qt.IsTrue/IsFalse/IsNil(x))require.EqualError(t, err, msg)qt.Assert(t, qt.ErrorMatches(err, regexp.QuoteMeta(msg)))c.Assert(err, qt.IsNil)qt.Assert(t, qt.IsNil(err))qt.Check(t, got, qt.IsNil)qt.Check(t, qt.IsNil(got))msgAndArgsqt.Commentf(...)Note the argument order flips: testify takes
(expected, actual), qt takes(got, want).assert.*→qt.Check(non-fatal),require.*→qt.Assert(fatal), preserving control flow.Three places needed more than a rename
require := require.New(t)(server_test.go,bep44/store_test.go) has no qt equivalent — qt has no bound form. The binding is dropped andtis passed explicitly at each call.TestMarshalCompactIPv4NodeAddrsassigned an assertion function to a variable:qt checkers are values of a different shape, so this can't carry over directly. The closure is lifted into a local and the branch picks the checker:
qt has no
NotPanics;qt.Not(qt.PanicMatches(f, ".*"))is exact, sincePanicMatchesfails whenfdoesn't panic and.*matches any panic value.qt.Containsis split by container type in the new API. TheAddrMaybeIdsByDistancetest checks a[]addrMaybeId, so it becomesqt.SliceContains.Where
Equalsisn't enoughqt.Equalsis==, which panics on uncomparable types and compares addresses for pointers. These useqt.DeepEqualsinstead:[]krpc.NodeInfo(nodes_file_test.go),f[:](msg_test.go),[]byteoutput (compact_test.go) — slices.krpc.Msg— itsIP NodeAddrfield holds anet.IP(a slice), soMsgis not comparable.qt.Equals(m, Msg{})compiles but would panic at runtime.*krpc.Msg(dht_test.go) —==would compare pointer addresses, not contents, and the test would have silently started failing.Separately,
int160.T.Bytes()returns a[]bytecompared against a string constant, whichqt.Equalscan't unify; that one converts explicitly withstring(...).Verification
All seven test packages pass —
dht/v2,bep44,containers,krpc,peer-store,traversal,types— matching the green baseline I took onmasterbefore starting.🤖 Generated with Claude Code
https://claude.ai/code/session_013BA3b7BbaJkPeeTYjhvi5g
Generated by Claude Code