Features
- go-testdeep is now dependency-free!
- add
Listoperator to compare an array or a slice in strict order (can be seen as a lighter alternative toArrayandSlice):td.Cmp(t, []int{1, 9, 5}, td.List(1, 9, 5)) // works with slices/arrays of any type td.Cmp(t, personSlice, td.List( Person{Name: "Bob", Age: 32}, Person{Name: "Alice", Age: 26}, ))
- add
Sortoperator to sort an array or slice before comparing its content (can be seen as an alternative toBag):td.Cmp(intSlice, td.Sort(-1, []int{4, 5, 9, 10})) // check intSlice content after sorting it in descending order // the key(s) on which the sorting applies can be quite complex type A struct{ props map[string]int } p12 := A{props: map[string]int{"priority": 12}} p23 := A{props: map[string]int{"priority": 23}} p34 := A{props: map[string]int{"priority": 34}} got := []A{p23, p12, p34} td.Cmp(t, got, td.Sort("-props[priority]", []A{p34, p23, p12})) // can be used inside JSON operator got := map[string][]string{"labels": {"c", "a", "b"}} td.Cmp(t, got, td.JSON(`{ "labels": Sort(1, ["a", "b", "c"]) }`)) // or more complex td.Cmp(t, got, td.JSON(`{ "people": Sort([ "-age", "name" ], [ // sort by age desc, then by name asc {"name": "Marcel", "age": 25}, {"name": "Brian", "age": 22}, {"name": "Alice", "age": 20}, {"name": "Bob", "age": 19}, {"name": "Stephen", "age": 19}, ]) }`))
- add
Sortedoperator to check an array or slice is sorted, examples:td.Cmp(t, aSlice, td.Sorted()) // checks aSlice is sorted in ascending order td.Cmp(t, aStructSlice, td.Sorted("-FieldName")) // checks aStructSlice is sorted in descending order // can be used inside JSON operator got := map[string][]string{"labels": {"a", "b", "c"}} td.Cmp(t, got, td.JSON(`{ "labels": Sorted }`))
- new
Must,Must2&Must3functions allowing to do:// before val, err := myfunction() td.Require(t).CmpNoError(err) // now val := td.Must(myfunction())
Smugglefields-path can now contains method calls, allowing to dotd.Smuggle("A.B.C.MethodName().D.E", expected)for example, and referencemap[string]...using.keyinstead of[key]before;Map,SubMapOf,SuperMapOf,Array,Slice&SuperSliceOfexpectedEntriesparameter is now optional or multiple;Flattennow acceptsfunc(T, X...) V|(V, bool)function signatures as well as an int to produce an int range;- regexp or shell pattern fields of
Struct&SStructnow appear clearly in failure report; tdhttp.TestAPI: addClone,DefaultRequestParams&AddDefaultRequestParamsmethods;tdhttp.TestAPInow setsHostfield;tdhttp.NewRequestand all other functions +tdhttp.TestAPImethods building HTTP requests also accept hook asfunc(*http.Request) error;tdhttp.TestAPI: addDefaultHeader&DefaultHookmethods to define header values & automatically called hook for each future requests sent bytdhttp.TestAPI;- add
tdsynctesthelper package, a simple wrapper aroundtesting/synctestpowered by go-testdeep; - new
tdutil.CmpValuesFuncfunction is able to sort[]reflect.Valueslices thanks toslices.SortFunc; tdutil.SortableValuesnow usesT.Compare(T) intmethod when it is available.
Fixes
- operators errors are no longer hidden when used inside another operator;
tdutilinternal tests for go1.25 was broken;Grep,Last&FirstString()method now shows the expected value;- in some cases, tests continued after a failure instead of stopping immediately;
Grep: if got is a specific named slice type, then expect this type .
What's Changed in details
- docs(README): v1.14.0 release announce by @maxatome in #254
- docs(ErrorIs): fix typo by @maxatome in #255
- docs: fix typos by @maxatome in #256
- Add tdhttp.TestAPI's DefaultRequestParams & AddDefaultRequestParams by @maxatome in #258
- feat(tdhttp): add testAPI.Clone feature by @c-roussel in #259
- Switch CI to go 1.22 & golangci-lint 1.55.2 by @maxatome in #260
- feat(tdhttp): request creation methods/functions init Host field by @maxatome in #261
- fix: smuggle hooks can return interface, as the doc always said by @maxatome in #262
- Delay type checks by @maxatome in #264
- feat(tdhttp): request creation accepts hooks by @maxatome in #263
- feat(Smuggle): fields-path param can contain method calls by @maxatome in #265
- chore: switch CI to go 1.23 & golangci-lint 1.60.1 by @maxatome in #266
- chore: switch CI to go 1.24 & golangci-lint 2.0.2 by @maxatome in #268
- docs: fix typo by @maxatome in #270
- fix: operators errors are no longer hidden when used inside another operator by @maxatome in #271
- test: add td.Smuggle tests by @maxatome in #272
- Prepare the ground for upcoming Sort & Sorted operators by @maxatome in #273
- Add Sort & Sorted operators by @maxatome in #267
- feat(tdutil): add new function CmpValuesFunc for slices.SortFunc by @maxatome in #274
- Support go1.25 by @maxatome in #275
- docs: add references to Sort & Sorted by @maxatome in #276
- Import go spew by @maxatome in #277
- chore: tools/gen_funcs.pl computes go lines by @maxatome in #278
- docs: add cross references by @maxatome in #280
- feat: add tdsynctest helper, a wrapper around testing/synctest by @maxatome in #281
- feat: add List operator by @maxatome in #282
- feat(Flatten): allow func(T, X...) V|(V, bool) function signatures by @maxatome in #284
- add location unit tests by @plutov in #285
- feat(Flatten): Flatten accepts an int to produce an int range by @maxatome in #286
- Some features before the release by @maxatome in #287
New Contributors
Full Changelog: v1.14.0...v1.15.0