Announcing test-generator - the test function generator

#1

Announcing the small crate “test-generator”
https://crates.io/crates/test-generator

Background

Often I have got the situation writing a Rusty IO operation and I would like to test the functionality against multiple test-vectors (in,out).

In the past this required two steps to add a test-case: 1) setting up a test-set in filesystem (in,out) storing some network traces etc. and 2) defining a test-function reading from that location, performing the operation and verifying the result. Often the test-sets are organized using files in directories. And often the test-functions are almost identical, except for the function name and the location of the input-file.

The macro “test_generator::glob_expand!” will eliminate step 2).
The user will be able to specify a generic test-function and a glob file-pattern such as “data/*”
The macro will expand this glob-pattern and will enumerate all entries. For each entry a test-function will be generated invoking the generic test-function of the user.

This will simplify the management of larger sets of test-vectors for a specific functionality.

Example
The following statement will generate a test-function for each entry in “data/*”

extern crate test_generator;

#[cfg(test)]
mod tests {
    use test_generator::glob_expand;
    use std::path::Path;
    use std::fs::File;
    use std::io::Read;

    // 
    // macro expanding tests
    glob_expand! { "data/*"; generic_test }
    
    //
    // test reading test-data from specific dir_name
    fn generic_test(dir_name: &str) {
        // Verify the specific test-set directory exists
        assert!( Path::new(dir_name).exists());
    }
}

The output of build test might look like:

     Running target/debug/deps/test_generator_example-36aa9ae6846d8e41

running 2 tests
test tests::gen_data_testset1 ... ok
test tests::gen_data_testset2 ... ok

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Enjoy!