|
6 | 6 | (let _case_desc "")
|
7 | 7 | (mut _cases [])
|
8 | 8 | (mut _case_pointer 0)
|
| 9 | + (mut display_cases_success false) |
9 | 10 |
|
10 | 11 | (let _start_time (time))
|
11 | 12 | # run test
|
|
29 | 30 |
|
30 | 31 | [_passed _failed]}))
|
31 | 32 |
|
32 |
| -(let _case_description (fun (_desc) |
| 33 | +(let _test_desc (fun (_desc) |
33 | 34 | (if (empty? _desc)
|
34 | 35 | ""
|
35 |
| - (str:format " for case '{}'" (head _desc))))) |
| 36 | + (str:format " for test '{}'" (head _desc))))) |
36 | 37 |
|
37 | 38 | # internal, do not use
|
38 | 39 | # Has a _case_desc which also exists (empty) inside _runner so that tests without a
|
|
61 | 62 | ($ test:case (_desc _body)
|
62 | 63 | (_case _desc (fun () {_body})))
|
63 | 64 |
|
| 65 | +# internal, do not use |
| 66 | +# Until _case_pointer isn't at the end of the pile (where our failing test case's is), |
| 67 | +# iterate on the list, writing the case name in a cascade pattern. |
| 68 | +# This way if we have CASE A>CASE B>CASE C and no test crashed in A nor in A>B, |
| 69 | +# we are still able to display the cascade A>B>C with the correct indentation. |
| 70 | +(let _add_case (fun () { |
| 71 | + (let _target_len (len _cases)) |
| 72 | + (while (< _case_pointer _target_len) { |
| 73 | + (mut _indent (* 2 _case_pointer)) |
| 74 | + (mut _fmt (if (> _indent 0) (+ "{: <" (toString _indent) "}{}") "{}{}")) |
| 75 | + (append! _failures (str:format _fmt "" (@ _cases _case_pointer))) |
| 76 | + (set _case_pointer (+ 1 _case_pointer))})})) |
| 77 | + |
64 | 78 | # internal, do not use
|
65 | 79 | # This can only be used within a (nested or not) call to test:suite
|
66 | 80 | # because it updates _failed and _failures, which are defined by
|
67 | 81 | # test:suite call to _runner
|
68 | 82 | (let _report_error (fun (_lhs _rhs _lhs_repr _rhs_repr _desc) {
|
69 | 83 | (set _failed (+ 1 _failed))
|
70 | 84 |
|
71 |
| - # Until _case_pointer isn't at the end of the pile (where our failing test case's is), |
72 |
| - # iterate on the list, writing the case name in a cascade pattern. |
73 |
| - # This way if we have CASE A>CASE B>CASE C and no test crashed in A nor in A>B, |
74 |
| - # we are still able to display the cascade A>B>C with the correct indentation. |
75 |
| - (let _add_case (fun () { |
76 |
| - (let _target_len (len _cases)) |
77 |
| - (while (< _case_pointer _target_len) { |
78 |
| - (mut _indent (* 2 _case_pointer)) |
79 |
| - (mut _fmt (if (> _indent 0) (+ "{: <" (toString _indent) "}{}") "{}{}")) |
80 |
| - (append! _failures (str:format _fmt "" (@ _cases _case_pointer))) |
81 |
| - (set _case_pointer (+ 1 _case_pointer))})})) |
82 |
| - |
83 | 85 | # If we have a case description AND the pointer isn't up to date, display the case(s)' names
|
84 | 86 | (if (and (not (empty? _case_desc)) (!= _case_pointer (len _cases)))
|
85 | 87 | (_add_case))
|
|
90 | 92 | (str:format (+ "{: <" (toString _indent_case_len) "}") "")
|
91 | 93 | ""))
|
92 | 94 | # Add the error message
|
93 |
| - (append! _failures (str:format "{}expected '{}' but got '{}'{}" _indent _lhs_repr _rhs_repr (_case_description _desc))) |
| 95 | + (append! _failures (str:format "{}expected '{}' but got '{}'{}" _indent _lhs_repr _rhs_repr (_test_desc _desc))) |
94 | 96 |
|
95 | 97 | (let _rhs_start (+ (len _lhs_repr) (len "expected ''")))
|
96 | 98 | (let _lhs_align (len _lhs_repr))
|
|
121 | 123 | # internal, do not use
|
122 | 124 | # This can only be used within a (nested or not) call to test:suite
|
123 | 125 | # because it updates _passed, which is defined by test:suite call to _runner
|
124 |
| -(let _report_success (fun () (set _passed (+ 1 _passed)))) |
| 126 | +(let _report_success (fun () { |
| 127 | + (set _passed (+ 1 _passed)) |
| 128 | + (if display_cases_success |
| 129 | + (_add_case)) |
| 130 | +})) |
125 | 131 |
|
126 | 132 | # @brief Given a value or function call returning a boolean, generate a test case
|
127 | 133 | # @param _cond the value to test for truthiness
|
|
136 | 142 | (if (!= true _cond)
|
137 | 143 | {
|
138 | 144 | (set _failed (+ 1 _failed))
|
139 |
| - (append! _failures (str:format "{} returned {}{}" ($repr _cond) _cond) (_case_description _desc))} |
| 145 | + (append! _failures (str:format "{} returned {}{}" ($repr _cond) _cond) (_test_desc _desc))} |
140 | 146 | (_report_success))})
|
141 | 147 |
|
142 | 148 | # @brief Compare two values that should be equal and generate a test case
|
|
174 | 180 | # @param _body body of the test, a begin block
|
175 | 181 | # =begin
|
176 | 182 | # (test:suite name {
|
| 183 | +# (set display_cases_success true) # default: false, when true, display all the cases names on success and failures |
177 | 184 | # (test:eq 6 (my_function 1 2 3))
|
178 | 185 | # (test:eq 128 (* 8 16))})
|
179 | 186 | # =end
|
|
0 commit comments