vinegar 0.1.0

A collection of functions and macros to help testing Rust code
Documentation
  • Coverage
  • 0%
    0 out of 5 items documented0 out of 1 items with examples
  • Size
  • Source code size: 15.1 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.14 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • renatoathaydes/vinegar
    3 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • renatoathaydes

Vinegar

A collection of functions and macros to help testing Rust code.

Macros

  • expect checks a boolean condition, similar to assert.
  • expect_eq checks two values for equality, similar to assert_eq.

Functions

  • fn check<I>(expects: I) where I: IntoIterator<Item=Result<(), String>>

Takes a collection of Result<(), String>, which happens to be the type of values returned by the expectation macros.

So, the check function is, basically, meant to check the assertions made with the expect macros.

Usage

Example usage:

use vinegar::check;

#[test]
fn use_check() {
    // simple test: just check some expectations:
    check(vec![
        expect_eq!(2 + 2, 4),
        expect!(2 + 2 == 4),
        expect_eq!("hi", "hi"),
    ]);

    // simple example-based test
    let examples = [1, 2, 3, ];

    check(examples.iter().map(|&ex| expect!(ex > 0)));

    // example-based test with both input and assertion as examples
    let examples = vec![
        // (input, expected result)
        (1, 2),
        (2, 4),
        (3, 6),
    ];

    check(examples.iter().map(|&(input, expected)| {
        let result = input * 2;
        expect_eq!(result, expected)
    }));
}