Documentation
¶
Overview ¶
Package testpredicate -- Predicate-base test assertions library for Go
Package go-testpredicate is a test assertions library exposing a predicate-like syntax that works with Go testing support to provide extensive diagnostics output and reduces the need to use a debugger on every failing test.
The library contains an extensive collection of built-in predicates covering:
- basic tests for nil, true, false
- equality between any type of value
- ordered comparison on numeric, string and sequence values
- regexp match on strings
- sub-sequences match on strings and sequences
- set conditions on unordered collections
- panic conditions on code fragment execution
Installation
go get github.com/maargenton/go-testpredicate
Usage
package examples_test
import (
"testing"
"github.com/maargenton/go-testpredicate/pkg/require"
"github.com/maargenton/go-testpredicate/pkg/verify"
)
func TestExample(t *testing.T) {
t.Run("Given ", func(t *testing.T) {
require.That(t, 123).ToString().Length().Eq(3)
t.Run("when ", func(t *testing.T) {
t.Run("then ", func(t *testing.T) {
verify.That(t, "123").Eq(123)
verify.That(t, 123).ToString().Length().Eq(4)
})
})
})
}
Output
--- FAIL: TestExample (0.00s) --- FAIL: TestFoo/Given_ (0.00s) --- FAIL: TestFoo/Given_/when_ (0.00s) --- FAIL: TestFoo/Given_/when_/then_ (0.00s) usage_test.go:16: expected: value == 123 error: values of type 'string' and 'int' are never equal value: "123" usage_test.go:17: expected: length(value.String()) == 4 value: 123 string: "123" length: 3
Directories
¶
| Path | Synopsis |
|---|---|
|
pkg
|
|
|
bdd
Package bdd defines a BDD-style bifurcated evaluation context, compatible with the build-in testing package.
|
Package bdd defines a BDD-style bifurcated evaluation context, compatible with the build-in testing package. |
|
require
Package require starts a predicate chain that will fail the current test if the assertions fails.
|
Package require starts a predicate chain that will fail the current test if the assertions fails. |
|
slogtest
Package slogtest provides support for recording structured log slog messages during tests and verifying that the expected messages have been emitted.
|
Package slogtest provides support for recording structured log slog messages during tests and verifying that the expected messages have been emitted. |
|
subexpr
Package subexpr starts an unevaluated predicate chain that is captured an outer predicate responsible for evaluating the condition on one or more values of a collection.
|
Package subexpr starts an unevaluated predicate chain that is captured an outer predicate responsible for evaluating the condition on one or more values of a collection. |
|
utils/builder
Package builder is main underlying package in the implementation of `verify.That()` and `require.That()`, with the `Builder` type providing the core functionality of the predicate builder.
|
Package builder is main underlying package in the implementation of `verify.That()` and `require.That()`, with the `Builder` type providing the core functionality of the predicate builder. |
|
utils/codegen
Package codegen is a small package intended to help with integrating custom code generation tools in your project.
|
Package codegen is a small package intended to help with integrating custom code generation tools in your project. |
|
utils/codegen/forward_api
command
|
|
|
utils/predicate
Package predicate defines both `Predicate“ and `Transform` types and handles the predicate evaluation process.
|
Package predicate defines both `Predicate“ and `Transform` types and handles the predicate evaluation process. |
|
utils/predicate/impl
Package impl defines all the support predicates and transformation function as individual functions that are then forwarded through code generation to the Builder type.
|
Package impl defines all the support predicates and transformation function as individual functions that are then forwarded through code generation to the Builder type. |
|
utils/prettyprint
Package prettyprint formats any go value in a way that is similar to the equivalent literal in a go source file.
|
Package prettyprint formats any go value in a way that is similar to the equivalent literal in a go source file. |
|
utils/value
Package value defines helper functions to compare numeric and other value types as either ordered or unordered.
|
Package value defines helper functions to compare numeric and other value types as either ordered or unordered. |
|
verify
Package verify starts a predicate chain that will let the current test continue even if the assertions fails.
|
Package verify starts a predicate chain that will let the current test continue even if the assertions fails. |
Click to show internal directories.
Click to hide internal directories.