Skip to content
aaa2pppPublic

About

This package shows how you can extend the functionality of [be](https://github.com/nalgeon/be) without modifying the original package.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

be-tb: Decorators for testing.TB

This package shows how you can extend the functionality of be without modifying the original package.

What it does

Decorator Effect
tb.Diff Pretty-prints differences with cmp.Diff
tb.JSON Shows values as JSON
tb.Require Turns Error into Fatal (stop test on failure)

All decorators work by wrapping testing.TB, so original be stays untouched.

Installation

go get github.com/yourusername/be-tb@latest

Usage

Pretty diff with cmp.Diff

be.Equal(tb.Diff(t), got, want)

Output:

diff (-want +got):
  model.Subscription{
    UserID: uuid.UUID{
-     0x2b,
+     0x3b,
    },
-   EndDate: model.MonthYear{Time: s"2025-12-01 00:00:00 +0000 UTC"},
+   EndDate: model.MonthYear{Time: s"2025-11-01 00:00:00 +0000 UTC"},
  }

NOTE: tb.Diff works only with a single want and requires matching types. Falls back to standard formatting otherwise.

JSON output

be.Equal(tb.JSON(t), got, want)

Output:

>>>>>>> got
{
  "user_id": "60601fee-3bf1-4721-ae6f-7636e79a0cba",
  "end_date": "11-2025"
}
=======
{
  "user_id": "60601fee-2bf1-4721-ae6f-7636e79a0cba",
  "end_date": "12-2025"
}
<<<<<<< want

Require-style assertions

be.True(tb.Require(t), condition)
be.Equal(tb.Require(t), got, want)

ATTENTION: The entrance to the rabbit hole :)

be.True(tb.Require(tb.Diff(t)), condition)

Example

See example_test.go and example_test.out for a complete example.

About

This package shows how you can extend the functionality of [be](https://github.com/nalgeon/be) without modifying the original package.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages