@@ -32,32 +32,53 @@ var (
3232// Assert is a helper to test circuits
3333type Assert struct {
3434 t * testing.T
35+ b * testing.B
3536 * require.Assertions
3637}
3738
38- // NewAssert returns an Assert helper embedding a testify/require object for convenience
39+ // NewAssert returns an Assert helper embedding a testify/require object for convenience.
40+ // It accepts either a *testing.T or *testing.B object.
3941//
40- // The Assert object caches the compiled circuit:
41- //
42- // the first call to assert.ProverSucceeded/Failed will compile the circuit for n curves, m backends
43- // and subsequent calls will re-use the result of the compilation, if available.
44- func NewAssert (t * testing.T ) * Assert {
45- return & Assert {t : t , Assertions : require .New (t )}
42+ // The Assert object caches the compiled circuit. This means that the first call
43+ // to [Assert.CheckCircuit] will compile the circuit for n curves, m
44+ // backends and subsequent calls will re-use the result of the compilation, if
45+ // available. Be careful when benchmarking!
46+ func NewAssert (tb testing.TB ) * Assert {
47+ switch t := (tb ).(type ) {
48+ case * testing.T :
49+ return & Assert {t : t , Assertions : require .New (t )}
50+ case * testing.B :
51+ return & Assert {b : t , Assertions : require .New (t )}
52+ default :
53+ panic ("unknown testing type" )
54+ }
4655}
4756
4857// Run runs the test function fn as a subtest. The subtest is parametrized by
4958// the description strings descs.
5059func (assert * Assert ) Run (fn func (assert * Assert ), descs ... string ) {
5160 desc := strings .Join (descs , "/" )
52- assert .t .Run (desc , func (t * testing.T ) {
53- assert := & Assert {t , require .New (t )}
54- fn (assert )
55- })
61+ if assert .b != nil {
62+ assert .b .Run (desc , func (b * testing.B ) {
63+ assert := & Assert {b : b , Assertions : require .New (b )}
64+ fn (assert )
65+ })
66+ } else {
67+ assert .t .Run (desc , func (t * testing.T ) {
68+ assert := & Assert {t : t , Assertions : require .New (t )}
69+ fn (assert )
70+ })
71+ }
5672}
5773
5874// Log logs using the test instance logger.
5975func (assert * Assert ) Log (v ... interface {}) {
60- assert .t .Log (v ... )
76+ if assert .b != nil {
77+ assert .b .Log (v ... )
78+ return
79+ } else {
80+ assert .t .Log (v ... )
81+ }
6182}
6283
6384// ProverSucceeded is deprecated: use [Assert.CheckCircuit] instead
0 commit comments