Skip to content

Commit c3520e8

Browse files
committed
feat: display all successful cases too when display_cases_success is true
1 parent 15e7534 commit c3520e8

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

Testing.ark

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
(let _case_desc "")
77
(mut _cases [])
88
(mut _case_pointer 0)
9+
(mut display_cases_success false)
910

1011
(let _start_time (time))
1112
# run test
@@ -29,10 +30,10 @@
2930

3031
[_passed _failed]}))
3132

32-
(let _case_description (fun (_desc)
33+
(let _test_desc (fun (_desc)
3334
(if (empty? _desc)
3435
""
35-
(str:format " for case '{}'" (head _desc)))))
36+
(str:format " for test '{}'" (head _desc)))))
3637

3738
# internal, do not use
3839
# Has a _case_desc which also exists (empty) inside _runner so that tests without a
@@ -61,25 +62,26 @@
6162
($ test:case (_desc _body)
6263
(_case _desc (fun () {_body})))
6364

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+
6478
# internal, do not use
6579
# This can only be used within a (nested or not) call to test:suite
6680
# because it updates _failed and _failures, which are defined by
6781
# test:suite call to _runner
6882
(let _report_error (fun (_lhs _rhs _lhs_repr _rhs_repr _desc) {
6983
(set _failed (+ 1 _failed))
7084

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-
8385
# If we have a case description AND the pointer isn't up to date, display the case(s)' names
8486
(if (and (not (empty? _case_desc)) (!= _case_pointer (len _cases)))
8587
(_add_case))
@@ -90,7 +92,7 @@
9092
(str:format (+ "{: <" (toString _indent_case_len) "}") "")
9193
""))
9294
# 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)))
9496

9597
(let _rhs_start (+ (len _lhs_repr) (len "expected ''")))
9698
(let _lhs_align (len _lhs_repr))
@@ -121,7 +123,11 @@
121123
# internal, do not use
122124
# This can only be used within a (nested or not) call to test:suite
123125
# 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+
}))
125131

126132
# @brief Given a value or function call returning a boolean, generate a test case
127133
# @param _cond the value to test for truthiness
@@ -136,7 +142,7 @@
136142
(if (!= true _cond)
137143
{
138144
(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))}
140146
(_report_success))})
141147

142148
# @brief Compare two values that should be equal and generate a test case
@@ -174,6 +180,7 @@
174180
# @param _body body of the test, a begin block
175181
# =begin
176182
# (test:suite name {
183+
# (set display_cases_success true) # default: false, when true, display all the cases names on success and failures
177184
# (test:eq 6 (my_function 1 2 3))
178185
# (test:eq 128 (* 8 16))})
179186
# =end

0 commit comments

Comments
 (0)