Releases: maxatome/go-testdeep
Releases · maxatome/go-testdeep
v1.14.0
Features
ErrorIs
becomes a smuggler operator usingerrors.As
behind the scene;Struct
andSStruct
introduce lazy-model feature, i.e. the model is guessed at run-time.
Fixes
- in error reports, the origin operator was sometimes missing and sometimes wrong when using
JSON
,SubJSONOf
andSuperJSONOf
operators; - fix
JSON
,SubJSONOf
andSuperJSONOf
panic when using a bad placeholder several times in the same operator.
What's Changed in details
- test: fix empty GOPROXY when testing with tip by @maxatome in #240
- fix(JSON): errors with wrong origin operator by @maxatome in #239
- ci: add workflow_dispatch as event trigger by @maxatome in #241
- feat(ErrorIs): becomes a smuggler operator with errors.As feature by @maxatome in #242
- refactor: make golangci-lint v1.52.2 happy by @maxatome in #243
- ci: switch to install-go v3.4 by @maxatome in #244
- Minor fixes by @maxatome in #246
- feat(Struct): introduce lazy-Struct & lazy-SStruct by @maxatome in #247
- test: use go 1.21 & golangci-lint 1.54.1 in CI by @maxatome in #248
- Correct spelling least by @aktasfatih in #249
- docs: clarify panic(nil) case since go 1.21 introduced a change by @maxatome in #250
- Fix json panic by @maxatome in #251
- fix(tdsuite): verbose tests raised an error by @maxatome in #253
New Contributors
- @aktasfatih made their first contribution in #249
Full Changelog: v1.13.0...v1.14.0
v1.13.0
Features
- New operators:
ErrorIs
to check the data is an error and matches a wrapped error (useserrors.Is
behind the scene),First
to find the first matching item of a slice or an array then compare its content,Grep
to reduce a slice or an array before comparing its content,Last
to find the last matching item of a slice or an array then compare its content,Recv
to read from a channel and test value;
- rework of
JSON
parsing:- introduction of raw strings,
- literal
\n
,\r
&\t
accepted in strings, $^Operator(params...)
is possible,"$^Operator(params...)"
is possible,Operator
(without parenthesis) is possible,- accepts
json.RawMessage
;
- anchoring is now possible using
td.A
andtd.Anchor
, the generic versions oftd.T.A
andtd.T.Anchor
; td.Flatten
now accepts an optional function to filter and/or transform the items before flattening them;*td.T
gainsAssert
andRequire
methods, to be consistent with existingtd.Assert
andtd.Require
;- introduce
td.S
function, to produce strings without needingfmt
, shorter to write and following the same calling convention as test names (in other words auto-detectingPrintf
like format); - new
TestDeepInGotOK
config to allow to test go-testdeep operators (is forbidden by default, but useful when go-testdeep is used outside golang tests) includingtd.T.TestDeepInGotOK
method; tdhttp
package:tdhttp.TestAPI
can now test HTTP responses as a whole (CmpResponse
) as well as HTTP trailer (CmpTrailer
),tdhttp.PostForm
andtdhttp.TestAPI.PostForm
now also accepttdhttp.Q
as data.
As usual: enjoy! :)
What's changed in details
- docs(README): v1.12.0 release announce by @maxatome in #212
- fix(doc,tdhttp): typo by @Linkid in #213
- Some refactoring by @maxatome in #214
- docs: fix typo by @maxatome in #215
- Grep, First & Last operators by @maxatome in #216
- refactor: go1.16 required now, so drop support for go1.9 to go1.15 by @maxatome in #221
- feat: add ErrorIs operator by @maxatome in #220
- fix(Recv): timeout can mask expected value by @maxatome in #222
- feat(tdhttp): add TestAPI's CmpResponse & CmpTrailer by @maxatome in #219
- feat: replacing bytes.Buffer instances used only to generate strings with strings.Builder. by @ellisonleao in #224
- feat(JSON): operators possible in JSON strings by @maxatome in #217
- refactor: Replace(a, b, -1) → ReplaceAll(a, b) by @maxatome in #226
- feat: go1.20 introduces slice to array convertibility by @maxatome in #227
- feat(tdhttp): allow usage of tdhttp.Q when using PostForm helpers by @c-roussel in #228
- fix(internal/json): avoid data race by @maxatome in #229
- feat: add TestDeepInGotOK allowing to test td.TestDeep operators by @maxatome in #230
- feat(internal): add (*ctxerr.Error).ErrorWithoutColors method by @maxatome in #231
- feat: add generic functions td.Anchor and td.A, another way to anchor by @maxatome in #232
- ci: test with go1.20 by @maxatome in #233
- style: remove useless comment by @maxatome in #234
- docs: fix README typo by @maxatome in #235
- feat(JSON): accept json.RawMessage as input by @deathiop in #237
- Flatten++ by @maxatome in #236
- chore: cosmetic changes before the release by @maxatome in #238
Full Changelog: v1.12.0...v1.13.0
v1.12.0
New features
Struct
&SStruct
can override model fields in expectedFields, as in:td.Cmp(t, got, td.Struct( Person{ Name: "John Doe", Age: 23, Children: 4, }, td.StructFields{ "> Age": td.Between(40, 45), ">Children": 0, // spaces after ">" are optional }), )
Struct
&SStruct
expectedFields is now optional or multiple. If multiple, all maps are merged from left to right;- try to detect wrongly defined hooks in
tdsuite
@deathiop
Given the 5 hooks: - try to detect possible
tdsuite.Run()
misuse, warn the user when it is called with a non-pointer suite, and some key methods are only available via a pointer suite; - add
tdhttp.Options
function &tdhttp.TestAPI.Options
method; Code
can now officially delegate its comparison, using two new kinds of function:func(t *td.T, arg)
func(assert, require *td.T, arg)
this way the usage of*td.T
methods is secure. Note that these functions do not return anything;
- using a
*td.T
instance asCmp*
first parameter now allows to inherit its configuration.is the same as:td.Cmp(td.Require(t), got, 42)
td.Require(t).Cmp(got, 42)
Fixes
Helper()
was not called inT.LogTrace
,T.ErrorTrace
andT.FatalTrace
methods. Fixed;UseEqual
& anchoring feature didn't play well together. Fixed;- panic when comparing nested maps using private fields as key. Fixed.
Miscellaneous
- enhance & refactor doc comments with new go 1.19 features;
- documentation now uses
any
instead ofinterface{}
; - fix typos.
As usual: enjoy! :)
v1.11.0
New features
JSON
,SubJSONOf
andSuperJSONOf
operators:- Now:
act the same way. Since v1.10.1 rework, the second was not working as expected.
td.JSON(`{"foo": $1}`, td.Between(12, 34)) td.JSON(`{"foo": Between($1, $2)}`, 12, 34)
At the same time:now works as expected. It was rejected before,td.JSON(`{"foo": Between(12, 34, $1)}`, td.BoundsOutIn)
int_lit
&float_lit
numbers, as defined in go specification, are now accepted in JSON, allowing, for example, to embed hexadecimal numbers in expected JSON;
- Now:
Between
operator acceptstime.Duration
asTO
whenFROM
is atime.Time
;Between
,Gt
,Gte
,Lt
andLte
operators:- now handle values implementing
Compare
orLess
methods:
Compare
and/orLess
methods signatures follow:for example, the new go1.18func (a T) Less(b T) bool // returns true if a < b func (a T) Compare(b T) int // returns -1 if a < b, 1 if a > b, 0 if a == b
net/netip.Addr
implements both, - failure reports display numbers as elsewhere,
- some docs have been fixed;
- now handle values implementing
Smuggle
can now cast values, allowing such things:// A string containing JSON got := `{ "foo": 123 }` td.Cmp(t, got, td.Smuggle(json.RawMessage{}, td.JSON(`{"foo":123}`)) // or td.Cmp(t, got, td.Smuggle((json.RawMessage)(nil), td.JSON(`{"foo":123}`))
- in report failures, the stack trace was displayed if it contained at least 2 levels. Now it is also displayed if it contains one level BUT the source file path contains a directory. It helps to localize quickly the errors in large repositories;
td.T
gains 3 new methods to log with a stack trace:LogTrace
,ErrorTrace
andFatalTrace
;- handle go1.17
[]T
→*[n]T
convertibility edge case; - in failure reports
(float64)
type is now omitted (like(int)
and(bool)
already were), but the value always contains a "." (except if±Inf
,NaN
or with exponent) to distinguish them fromint
.
Fixes
Contains
: slice in slice search didn't work at end of slice;JSON
,SubJSONOf
andSuperJSONOf
operators panicked when usingAll
+JSON-operator+embeddedOp+$1
;- anchoring 2 slices at the same time didn't work.
Miscellaneous
- CI build:
- now uses
install-go.pl
v3.0, sotip
test is very fast most of the time, - golangci-lint upgraded to v1.43.0,
- uses bidichk linter;
- now uses
//go:build
line added when// +build
was already present, since go1.17 changes;//nolint:
pragmas uniformized.
And happy new year!
v1.10.1
Fixes:
Len
andCap
could not be embedded inJSON
,SubJSONOf
andSuperJSONOf
. Fixed;Bag
andSet
didn't implementTypeBehind()
method. Fixed;JSONPointer
expectedValue andJSON
placeholders didn't have the same behavior. Now the pointed data is JSON-unmarshaled into a value using the same type of expectedValue (forJSONPointer
) or any placeholder (forJSON
) before comparison;Catch
TypeBehind()
method didn't use the type of target when the type behind expectedValue could not be determined. Fixed;(*tdhttp.TestApi).CmpJSONBody(nil)
panicked. Fixed;- and some typos fixed.
Enjoy!
v1.10.0
New features:
- add
SuperSliceOf
operator, to compare only parts of slices/arrays; - JSON parser of
JSON
,SubJSONOf
andSuperJSONOf
is now more lax:are allowed (comma just before "}" or "]" for non-empty {…} and […]);{"foo": "bar",} [ 1, 2, 3, ]
Smuggle
fields-path param can now dereference maps, arrays & slices:Contrary totd.Smuggle("Group.Persons[3].Age", td.Between(23, 32))
JSONPointer
operator, private fields can be followed;Struct
&SStruct
now understand shell patterns & regexps to match struct fields;- add
IgnoreUnexported
feature and reworkUseEqual
: they both can now be scoped to some types.Struct
&SStruct
comply with the newIgnoreUnexported
; - add
(*td.T).Parallel()
method (@abhinav); - do not panic on operator misuses anymore, but raise an error on operator use. So it is easier to understand;
- introduce
nocolor
helper to easily disable coloring output of failure reports, typically useful in golang playground; tdhttp
package:- introduce multipart requests as defined in RFC 2046, see
(*tdhttp.TestAPI).PostMultipartFormData()
,tdhttp.PostMultipartFormData()
andtdhttp.MultipartBody
type; - headers handle
http.Cookie
out-of-the-box, seetdhttp.NewRequest()
documentation for details; - new
tdhttp.BasicAuthHeader()
function allows to easily inject Basic Authorization header; - add
(*tdhttp.TestAPI).CmpCookies()
to easily compare cookies content (@Julien2313); - add
tdhttp.Q
type to easily declare query parameters in requests, seetdhttp.NewRequest()
documentation for details. Note thaturl.Values
type is now supported as well.
- introduce multipart requests as defined in RFC 2046, see
Fixes:
- multi-lines colored text → color-off \n color-on for each line (@siadat);
JSON
TypeBehind()
method is now delegated when an operator is at the root of the JSON;tdhttp
package:- chaining of
Cmp*
methods can lead to skewFailed()
result.
- chaining of
Enjoy!
v1.9.2
Fixes:
- deeply nested operators in
JSON
params was json.Marshal()led. It is now detected and avoided; - a specific error message is provided to the user when he tries to wrongly use
td.JSON()
as body in(*tdhttp.TestAPI).XxxJSON()
calls; - in
tdsuite
,Cleanup()
was sometimes incorrectly called inPreTest
/PostTest
hooks.
v1.9.1
v1.9.0
New features:
- introducing new
tdsuite
helper, allowing to easily create testing suites, fully integrated with go-testdeep; JSON
,SubJSONOf
andSuperJSONOf
now accept almost all operators embedded directly in JSON thanks to our new custom JSON decoder:td.Cmp(t, got, td.JSON(`{"name": HasPrefix("Bob"), "age": Between(20, 25)}`), )
Re
andReAll
capture parameter can now be a[]interface{}
(only[]string
until now);Flatten
is now able to flatten maps, can be useful when creating request usingtdhttp
package;- when a
Cmp
failure occurs outside the root of a test function, a trace of all successive function calls is displayed to help the user to understand/locate the error; - in
tdhttp
helper (aka the ultimate HTTP API tester),tdhttp.TestAPI
gains several methods:AutoDumpResponse
allows to dump the HTTP response when the first error is encountered after a request,OrDumpResponse
dumps the response if at least one previous test failed,Run
runs a subtest,T
returns the internal instance of*td.T
,With
creates a new*TestAPI
instance.
Fixes:
reflect.Interface
containingnil
could produce wrong comparisons.
Enjoy!
v1.8.0
New features:
- add new
JSONPointer
operator following RFC 6901; - when 2 types differ but have the same short name, use full pkg name in error report;
- add Cmp and Smuggle hooks feature;
- new
td.Tuple
type added and itstd.TupleFrom()
builder. Useful to quickly test functions returning several values as in:price := func(p float64) (float64, string, error) { if p < 0 { return 0, "", errors.New("negative price not supported") } return p * 1.2, "€", nil } td.Cmp(t, td.TupleFrom(price(10)), td.TupleFrom(float64(12), "€", nil), ) td.Cmp(t, td.TupleFrom(price(-10)), td.TupleFrom(float64(0), "", td.Not(nil)), )
- when calling
tdhttp.NewRequest()
(and all other request builder methods) headers can be flattened withtd.Flatten()
.
Fixes:
- missing lock when resolving anchors;
BeLax
flag (set byLax
andJSON
operators) was not taken into account for operatorsAny
,Bag
,Code
,Contains
,None
,NotAny
,Set
,SubBagOf
,SubSetOf
,SuperBagOf
andSuperSetOf
.
Enjoy!