Advertisement
Guest User

Untitled

a guest
Apr 26th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. struct TestOptions {
  2.  
  3. }
  4.  
  5. type TestResult = u32;
  6.  
  7. struct TestCase {
  8. options : TestOptions,
  9. expected : TestResult,
  10. test : fn(&TestOptions) -> TestResult,
  11. }
  12.  
  13. fn consider_setup(_: &TestOptions) {
  14. }
  15.  
  16. fn consider_cleanup(_: &TestOptions) {
  17. }
  18.  
  19. fn run_test(t: &TestCase) {
  20. let options = &t.options;
  21. let expected = t.expected;
  22. consider_setup(options);
  23. let result = (t.test)(options);
  24. consider_cleanup(options);
  25. assert_eq!(expected, result);
  26. }
  27.  
  28. fn run_all_tests(ts: &Vec<TestCase>) {
  29. for test in ts.iter() {
  30. run_test(test);
  31. }
  32. }
  33.  
  34. fn function_to_test1(_: &TestOptions) -> TestResult {
  35. 12
  36. }
  37.  
  38. fn function_to_test2(_: &TestOptions) -> TestResult {
  39. 14
  40. }
  41.  
  42. fn main() {
  43. let mut tests : Vec<TestCase> = Vec::new();
  44.  
  45. {
  46. let t1 = TestCase {
  47. options: TestOptions{},
  48. expected: 12,
  49. test: function_to_test1
  50. };
  51. tests.push(t1);
  52. }
  53.  
  54. {
  55. let t2 = TestCase {
  56. options: TestOptions{},
  57. expected: 15, // this will raise an error
  58. test: function_to_test2
  59. };
  60. tests.push(t2);
  61. }
  62.  
  63. run_all_tests(&tests);
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement