Skip to content

Releases: maxatome/go-testdeep

v1.14.0

27 Dec 17:39
Compare
Choose a tag to compare

Features

Fixes

  • in error reports, the origin operator was sometimes missing and sometimes wrong when using JSON, SubJSONOf and SuperJSONOf operators;
  • fix JSON, SubJSONOf and SuperJSONOf panic when using a bad placeholder several times in the same operator.

What's Changed in details

New Contributors

Full Changelog: v1.13.0...v1.14.0

v1.13.0

18 Mar 22:29
Compare
Choose a tag to compare

Features

  • New operators:
    • ErrorIs to check the data is an error and matches a wrapped error (uses errors.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 and td.Anchor, the generic versions of td.T.A and td.T.Anchor;
  • td.Flatten now accepts an optional function to filter and/or transform the items before flattening them;
  • *td.T gains Assert and Require methods, to be consistent with existing td.Assert and td.Require;
  • introduce td.S function, to produce strings without needing fmt, shorter to write and following the same calling convention as test names (in other words auto-detecting Printf 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) including td.T.TestDeepInGotOK method;
  • tdhttp package:

As usual: enjoy! :)

What's changed in details

Full Changelog: v1.12.0...v1.13.0

v1.12.0

07 Aug 17:50
Compare
Choose a tag to compare

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 as Cmp* first parameter now allows to inherit its configuration.
    td.Cmp(td.Require(t), got, 42)
    is the same as:
    td.Require(t).Cmp(got, 42)

Fixes

Miscellaneous

  • enhance & refactor doc comments with new go 1.19 features;
  • documentation now uses any instead of interface{};
  • fix typos.

As usual: enjoy! :)

v1.11.0

05 Jan 08:32
Compare
Choose a tag to compare

New features

  • JSON, SubJSONOf and SuperJSONOf operators:
    • Now:
      td.JSON(`{"foo": $1}`, td.Between(12, 34))
      td.JSON(`{"foo": Between($1, $2)}`, 12, 34)
      act the same way. Since v1.10.1 rework, the second was not working as expected.
      At the same time:
      td.JSON(`{"foo": Between(12, 34, $1)}`, td.BoundsOutIn)
      now works as expected. It was rejected before,
    • 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;
  • Between operator accepts time.Duration as TO when FROM is a time.Time;
  • Between, Gt, Gte, Lt and Lte operators:
    • now handle values implementing Compare or Less methods:
      Compare and/or Less methods signatures follow:
      func (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
      for example, the new go1.18 net/netip.Addr implements both,
    • failure reports display numbers as elsewhere,
    • some docs have been fixed;
  • 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 and FatalTrace;
  • 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 from int.

Fixes

  • Contains: slice in slice search didn't work at end of slice;
  • JSON, SubJSONOf and SuperJSONOf operators panicked when using All+JSON-operator+embeddedOp+$1;
  • anchoring 2 slices at the same time didn't work.

Miscellaneous

And happy new year!

v1.10.1

27 Sep 19:55
bc3f765
Compare
Choose a tag to compare

Fixes:

  • Len and Cap could not be embedded in JSON, SubJSONOf and SuperJSONOf. Fixed;
  • Bag and Set didn't implement TypeBehind() method. Fixed;
  • JSONPointer expectedValue and JSON placeholders didn't have the same behavior. Now the pointed data is JSON-unmarshaled into a value using the same type of expectedValue (for JSONPointer) or any placeholder (for JSON) 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

31 Aug 21:35
Compare
Choose a tag to compare

New features:

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 skew Failed() result.

Enjoy!

v1.9.2

18 Mar 20:37
9a7d694
Compare
Choose a tag to compare

Fixes:

v1.9.1

16 Mar 07:46
53a4920
Compare
Choose a tag to compare

Fixes:

  • traces displayed when a Cmp failure occurs, are now properly stripped to ignore testing, td, tdhttp and tdsuite internal calls;
  • JSON unmarshal bug when \uxxxx is first escaping sequence in a string.

v1.9.0

09 Mar 22:21
a1d04bd
Compare
Choose a tag to compare

New features:

  • introducing new tdsuite helper, allowing to easily create testing suites, fully integrated with go-testdeep;
  • JSON, SubJSONOf and SuperJSONOf 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 and ReAll capture parameter can now be a []interface{} (only []string until now);
  • Flatten is now able to flatten maps, can be useful when creating request using tdhttp 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 containing nil could produce wrong comparisons.

Enjoy!

v1.8.0

17 Dec 08:00
c62e308
Compare
Choose a tag to compare

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 its td.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 with td.Flatten().

Fixes:

Enjoy!