A minimalist property-based testing library based on the arbitrary crate.

Related tags

Testing arbtest
Overview

arbtest

A minimalist property-based testing library based on the arbitrary crate.

Maintainance Status

Arbitrary.

Example

) -> arbitrary::Result<()> { let mut xs = u.arbitrary::>()?; buggy_sort(&mut xs); Ok(()) } #[test] fn test() { arbtest::builder().budget_ms(50_000) .run(|u| prop(u)) } #[test] fn reproduce() { arbtest::builder().seed(0xde0ad94600000001) .run(|u| prop(u)) } #[test] fn minimize() { arbtest::builder().seed(0x2d5a75df00003e9a).minimize() .run(|u| prop(u)) } }">
pub fn buggy_sort(xs: &mut [u8]) {
    for i in 0..xs.len() {
        for j in 0..i {
            if xs[i] == xs[j] {
                panic!("BUG")
            }
        }
    }
    xs.sort()
}

#[cfg(test)]
mod tests {
    use super::*;

    use arbtest::arbitrary::{self, Unstructured};

    fn prop(u: &mut Unstructured<'_>) -> arbitrary::Result<()> {
        let mut xs = u.arbitrary::<Vec<u8>>()?;
        buggy_sort(&mut xs);
        Ok(())
    }

    #[test]
    fn test() {
        arbtest::builder().budget_ms(50_000)
            .run(|u| prop(u))
    }

    #[test]
    fn reproduce() {
        arbtest::builder().seed(0xde0ad94600000001)
            .run(|u| prop(u))
    }

    #[test]
    fn minimize() {
        arbtest::builder().seed(0x2d5a75df00003e9a).minimize()
            .run(|u| prop(u))
    }
}
You might also like...
Rnp - A simple cloud-friendly tool for testing network reachability.

Rnp - A simple cloud-friendly tool for testing network reachability. Release Status Crates.io Github release Nuget packages NOTE: This project is in e

Viceroy provides local testing for developers working with Compute@Edge.
Viceroy provides local testing for developers working with Compute@Edge.

Viceroy provides local testing for developers working with Compute@Edge. It allows you to run services written against the Compute@Edge APIs on your local development machine, and allows you to configure testing backends for your service to communicate with.

Simple goldenfile testing in Rust.

👑 Rust Goldenfile Simple goldenfile testing in Rust. Goldenfile tests generate one or more output files as they run. At the end of the test, the gene

Declarative Testing Framework

Demonstrate allows tests to be written without as a much repetitive code within the demonstrate! macro, which will generate the corresponding full tests.

Cucumber testing framework for Rust. Fully native, no external test runners or dependencies.

An implementation of the Cucumber testing framework for Rust. Fully native, no external test runners or dependencies.

🧵 Generate self-describing strings of a given length to help aid software testing
🧵 Generate self-describing strings of a given length to help aid software testing

rust-counter-strings Counter strings generator written in rust to help aid software testing What is a counterstring? "A counterstring is a graduated s

Loom is a concurrency permutation testing tool for Rust.

Loom is a testing tool for concurrent Rust code

Drill is an HTTP load testing application written in Rust  inspired by Ansible syntax
Drill is an HTTP load testing application written in Rust inspired by Ansible syntax

Drill is an HTTP load testing application written in Rust inspired by Ansible syntax

assay - A super powered testing macro for Rust

assay - A super powered testing macro for Rust as·say /ˈaˌsā,aˈsā/ noun - the testing of a metal or ore to determine its ingredients and quality. Rust

Comments
  • Supporting run with a closure

    Supporting run with a closure

    Hi, thanks for the nice library! I've started using it recently and now expanding it to my work related and private projects.

    What's desired

    Would it be possible to make builder.run() accept a real closure instead of

    pub type Property = fn(u: &mut Unstructured<'_>) -> arbitrary::Result<()>;
    

    In other words, something like:

    pub trait Property: FnMut(&mut Unstructured<'_>) -> arbitrary::Result<()> {
    }
    
    pub fn run<P: Property>(mut self, prop: P) {
        // implementation..
    }
    

    Why it would be useful

    One of my tests needs to be ran with some predefined IDs, that come from another place (in particular from DB).

    Why it's not possible at the moment

    I've tried to do the desired change and open a PR, but I see that it narrows down to catch_unwind, which I could not workaround:

        fn fails(&mut self, seed: Seed, prop: Property) -> bool {
            let this = AssertUnwindSafe(self);
            std::panic::catch_unwind(move || {            // <- FnMut cannot be moved here
                let that = this;
                that.0.single_run(seed, prop)
            })
            .is_err()
        }
    
    opened by greyblake 2
Owner
Aleksey Kladov
I AM THE SAURUS!
Aleksey Kladov
Hypothesis-like property testing for Rust

Proptest Introduction Proptest is a property testing framework (i.e., the QuickCheck family) inspired by the Hypothesis framework for Python. It allow

Jason Lingle 1.1k Jan 1, 2023
Very minimalist tmux status bar that displays used memory and CPU usage.

woot-bar Ultra minimalist status bar that displays used memory and CPU usage woot-bar is made for tmux but it is compatible with anything that eats st

Nicolas Gryman 3 Dec 27, 2022
The trait for generating structured data from arbitrary, unstructured input.

Arbitrary The trait for generating structured data from arbitrary, unstructured input. About The Arbitrary crate lets you construct arbitrary instance

Rust Fuzzing Authority 407 Dec 24, 2022
Simple assertion library for unit testing in python with a fluent API

Simple assertions library for unit testing in Python with a nice fluent API. Supports both Python 2 and 3.

snakedye 19 Sep 10, 2022
This is a tiny (but delightful!) utility library for exhaustive testing.

Exhaustigen This is a tiny (but delightful!) utility library for exhaustive testing. It is based (directly) on the idea and code in the following blog

Graydon Hoare 34 Dec 14, 2022
Rust testing library

K9 - Rust Testing Library Snapshot testing + better assertions Available test macros snapshot assert_equal assert_greater_than assert_greater_than_or_

Aaron Abramov 269 Dec 10, 2022
Rustress - stress testing library in Rust. For fun

rustress Simple network stress testing library. To get familiar with Rust Planned features (Subject to change) Multithreaded client/server Throughput

Hakan Sönmez 7 Sep 22, 2022
insta: a snapshot testing library for Rust

insta: a snapshot testing library for Rust Introduction Snapshots tests (also sometimes called approval tests) are tests that assert values against a

Armin Ronacher 1.4k Jan 1, 2023
ArchTest is a rule based architecture testing tool for rust

ArchTest is a rule based architecture testing tool. It applies static analyses on the specified rust project to extract use relationships.

Tom Dymel 7 Sep 26, 2021
Testing Framework for Rust

Polish Polish is Test-Driven Development done right Getting Started Installing the Package The crates.io package is kept up-to-date with all the major

Fadi Hanna Al-Kass 49 Dec 18, 2022