#testing #code-gen #proc-macro

testgen

一个用于生成各种测试函数的过程宏crate

2个不稳定版本

使用旧的Rust 2015

0.1.0 2018年11月18日
0.0.1 2018年11月17日

#695 in #test

MIT/Apache

14KB
269

testgen

Build Status crates.io Released API docs

此库仍处于非常早期的发展阶段!

使用testgen生成简单的测试!

示例

extern crate testgen;
use testgen::{fail, multi_fail, multi_pass, pass};

#[pass(name="optional", 1 => 2)]
#[multi_fail(1 => 1, 2 => 2, 3 => 3)]
fn add_one(n: i32) -> i32 {
    n + 1
}

// Multiple arguments are passed in like a tuple.
// Though to use an actual tuple use `((a, b))`.
// Single-argument functions can have the parenthesis elided in most cases.
#[multi_pass((1, 2) => 3, (3, 4) => 7)]
#[fail((1, 2) => 10)]
fn add(n: i32, m: i32) -> i32 {
    n + m
}

fn main() {}

输出

   Compiling testgen v0.0.1 (/mnt/F/Development/Rust/testgen)
    Finished dev [unoptimized + debuginfo] target(s) in 1.05s
     Running target/debug/examples/doc_example-79f4317fab9ffdf5

running 4 tests
test add_multitest_pass ... ok
test optional ... ok
test add_one_multitest_fail ... ok
test add_test_fail ... ok

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

许可证

testgen受MIT和Apache 2.0双重许可

依赖项

~2MB
~46K SLoC