|
| 1 | +# internal, do not use |
1 | 2 | (let _runner (fun (_name _callable) { |
2 | 3 | (mut _passed 0) |
3 | 4 | (mut _failed 0) |
|
25 | 26 |
|
26 | 27 | [_passed _failed]})) |
27 | 28 |
|
| 29 | +# internal, do not use |
28 | 30 | (let _report_error (fun (_lhs _rhs _lhs_repr _rhs_repr) { |
29 | 31 | (set _failed (+ 1 _failed)) |
30 | 32 | (append! _failures (str:format "{} was not equal to {}" _lhs_repr _rhs_repr)) |
|
34 | 36 | (append! _failures (str:format (+ "{: <" (toString _rhs_start) "}{:~<" (toString _rhs_align) "} {}") "|" "\\" _lhs)) |
35 | 37 | (append! _failures (str:format (+ "{:~<" (toString _lhs_align) "} {}") "\\" _rhs))})) |
36 | 38 |
|
| 39 | +# internal, do not use |
37 | 40 | (let _report_success (fun () (set _passed (+ 1 _passed)))) |
38 | 41 |
|
| 42 | +# @brief Given a value or function call returning a boolean, generate a test case |
| 43 | +# @param _cond the value to test for truthiness |
| 44 | +# =begin |
| 45 | +# (test:suite name { |
| 46 | +# (test:expect (my_function 1 2 3))}) |
| 47 | +# =end |
| 48 | +# @author https://github.com/SuperFola |
39 | 49 | ($ test:expect (_cond) { |
40 | 50 | (if (!= true _cond) |
41 | 51 | { |
42 | 52 | (set _failed (+ 1 _failed)) |
43 | 53 | (append! _failures (str:format "{} was not true but {}" ($repr _cond) _cond)) } |
44 | 54 | (_report_success))}) |
45 | 55 |
|
| 56 | +# @brief Compare two values that should be equal and generate a test case |
| 57 | +# @param _lhs the first value |
| 58 | +# @param _rhs the second value |
| 59 | +# =begin |
| 60 | +# (test:suite name { |
| 61 | +# (test:eq 6 (my_function 1 2 3))}) |
| 62 | +# =end |
| 63 | +# @author https://github.com/SuperFola |
46 | 64 | ($ test:eq (_lhs _rhs) { |
47 | 65 | (if (= _lhs _rhs) |
48 | 66 | (_report_success) |
49 | 67 | (_report_error _lhs _rhs ($repr _lhs) ($repr _rhs)))}) |
50 | 68 |
|
| 69 | +# @brief Compare two values that should **not** be equal and generate a test case |
| 70 | +# @param _lhs the first value |
| 71 | +# @param _rhs the second value |
| 72 | +# =begin |
| 73 | +# (test:suite name { |
| 74 | +# (test:neq 0 (my_function 1 2 3))}) |
| 75 | +# =end |
| 76 | +# @author https://github.com/SuperFola |
51 | 77 | ($ test:neq (_lhs _rhs) { |
52 | 78 | (if (!= _lhs _rhs) |
53 | 79 | (_report_success) |
54 | 80 | (_report_error _lhs _rhs ($repr _lhs) ($repr _rhs)))}) |
55 | 81 |
|
| 82 | +# @brief Generate the code for a test suite |
| 83 | +# @details Create two variables: _name-output (a list: [successes, failures]) and _name-status (boolean, true on success) |
| 84 | +# @param _name test name, as an identifier |
| 85 | +# @param _body body of the test, a begin block |
| 86 | +# =begin |
| 87 | +# (test:suite name { |
| 88 | +# (test:eq 6 (my_function 1 2 3)) |
| 89 | +# (test:eq 128 (* 8 16))}) |
| 90 | +# =end |
| 91 | +# @author https://github.com/SuperFola |
56 | 92 | ($ test:suite (_name _body) { |
57 | 93 | (let (symcat _name "-output") (_runner ($repr _name) (fun () {_body}))) |
58 | 94 | (let (symcat _name "-status") (= 0 (@ (symcat _name "-output") 1)))}) |
0 commit comments