Skip to content

Fluent assertion library for Rust with readable messages.

License

Notifications You must be signed in to change notification settings

vegardgs-ksat/assertor

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

87 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Assertor

Assertor makes test assertions and failure messages more human-readable.

crates.io license docs.rs OpenSSF Scorecard

Assertor is heavily affected by Java Truth in terms of API design and error messages, but this is a totally different project from Java Truth.

Disclaimer

This is not an official Google product, it is just code that happens to be owned by Google.

⚠ The API is not fully stable and may be changed until version 1.0.

Example

use assertor::*;

#[test]
fn test_it() {
    assert_that!("foobarbaz").contains("bar");
    assert_that!("foobarbaz").ends_with("baz");

    assert_that!(0.5).with_abs_tol(0.2).is_approx_equal_to(0.6);

    assert_that!(vec!["a", "b"]).contains("a");
    assert_that!(vec!["a", "b"]).has_length(2);
    assert_that!(vec!["a", "b"]).contains_exactly(vec!["a", "b"]);

    assert_that!(Option::Some("Foo")).has_value("Foo");
}

Failure cases

use assertor::*;

fn test_it() {
    assert_that!(vec!["a", "b", "c"]).contains_exactly(vec!["b", "c", "d"]);
    // missing (1)   : ["d"]
    // unexpected (1): ["a"]
    // ---
    // expected      : ["b", "c", "d"]
    // actual        : ["a", "b", "c"]
}

Feature ideas

  • Color / Bold
  • Better diff: vec
  • Better diff: set
  • Better diff: HashMap

About

Fluent assertion library for Rust with readable messages.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%