Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct TestOptions {
- }
- type TestResult = u32;
- struct TestCase {
- options : TestOptions,
- expected : TestResult,
- test : fn(&TestOptions) -> TestResult,
- }
- fn consider_setup(_: &TestOptions) {
- }
- fn consider_cleanup(_: &TestOptions) {
- }
- fn run_test(t: &TestCase) {
- let options = &t.options;
- let expected = t.expected;
- consider_setup(options);
- let result = (t.test)(options);
- consider_cleanup(options);
- assert_eq!(expected, result);
- }
- fn run_all_tests(ts: &Vec<TestCase>) {
- for test in ts.iter() {
- run_test(test);
- }
- }
- fn function_to_test1(_: &TestOptions) -> TestResult {
- 12
- }
- fn function_to_test2(_: &TestOptions) -> TestResult {
- 14
- }
- fn main() {
- let mut tests : Vec<TestCase> = Vec::new();
- {
- let t1 = TestCase {
- options: TestOptions{},
- expected: 12,
- test: function_to_test1
- };
- tests.push(t1);
- }
- {
- let t2 = TestCase {
- options: TestOptions{},
- expected: 15, // this will raise an error
- test: function_to_test2
- };
- tests.push(t2);
- }
- run_all_tests(&tests);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement