doc.gno

1.35 Kb ยท 44 lines
 1// Package expect provides testing support for packages and realms.
 2//
 3// The opinionated approach taken on this package for testing is to use function chaining and
 4// semanthics to hopefully make unit and file testing fun. Focus is not on speed as there are
 5// other packages that would run tests faster like the official `uassert` or `urequire` packages.
 6//
 7// Values can be asserted using the `Value()` function, for example:
 8//
 9//	func TestFoo(t *testing.T) {
10//	  got := 42
11//	  expect.Value(t, got).ToEqual(42)
12//	  expect.Value(t, got).Not().ToEqual(0)
13//
14//	  expect.Value(t, "foo").ToEqual("foo")
15//	  expect.Value(t, 42).AsInt().Not().ToBeGreaterThan(50)
16//	  expect.Value(t, "TRUE").AsBoolean().ToBeTruthy()
17//	}
18//
19// Functions can also be used to assert returned values, errors or panics.
20//
21// Package supports four type of functions:
22//
23//   - func()
24//   - func() any
25//   - func() error
26//   - func() (any, error)
27//
28// Functions can be asserted using the `Func()` function, for example:
29//
30//	func TestFoo(t *testing.T) {
31//	  expect.Func(t, func() {
32//	    panic("Boom!")
33//	  }).ToPanic().WithMessage("Boom!")
34//
35//	  wantErr := errors.New("Boom!")
36//	  expect.Func(t, func() error {
37//	    return wantErr
38//	  }).ToFail().WithMessage("Boom!")
39//
40//	  expect.Func(t, func() error {
41//	    return wantErr
42//	  }).ToFail().WithError(wantErr)
43//	}
44package expect