Crate assertables

source ·
Expand description

§Assertables: Rust crate of assert macros for testing

The assertables Rust crate provides many assert macros to improve your compile-time tests and run-time reliability.

§Introduction

The Rust programming language provides a few built-in assert macros to test code:

The Rust programming language provides assert macros to test code:

The assertables crate provides many more, so you can write smarter tests.

For values:

For strings:

For matching:

For infix operators:

For numbers:

For Result:

For Option:

For Poll:

For collections such as arrays, vectors, maps, sets:

For file system paths and input/output readers:

For command capture of standard output and standard error:

There are many more macros that are grouped into modules.

Modules for enums:

Modules for collections, such as arrays, vectors, lists, maps:

Modules for functions:

Modules for readers:

Modules for external calls:

§Benefits

  • Your tests are more purposeful and powerful. This helps your code be more reliable.

  • Your assert failures provide more information. This helps you troubleshoot faster.

  • You gain runtime asserts. This helps you with validations and verifications.

§Features

  • Easy to use: each macro is well-documented with runnable examples and tests.

  • Zero overhead: if you don’t use a macro, then it’s never compiled into your code.

  • Zero dependencies: the crate has no release dependencies, and just a short list of development dependencies.

§Forms

§Forms for panic versus error

All the assert macros have 3 forms for different purposes:

  • Panic form for typical tests.
  • Debug form for debugging runtimes.
  • Result form for runtime checks, verifications, validations, etc.

Examples:

§Forms for messages

All the assert macros have 2 forms for messages.

  • Default message form.
  • Custom message form.

Examples:

§Forms for other versus expression

Many of the assert macros have 2 forms for comparing left hand side and right hand side.

  • Comparing a LHS item to a RHS other of the same type.
  • Comparing a LHS item to a RHS expression.

Examples:

§Tracking

  • Package: assertables-rust-crate
  • Version: 8.7.0
  • Created: 2021-03-30T15:47:49Z
  • Updated: 2024-09-18T14:51:06Z
  • License: MIT or Apache-2.0 or GPL-2.0 or GPL-3.0 or contact us for more
  • Contact: Joel Parker Henderson (joel@sixarm.com)

Modules§

Macros§