Skip to content

Commit

Permalink
Show errors from all levels (suite, test, or step)
Browse files Browse the repository at this point in the history
Now that suites and tests can throw exceptions, we switch to recording
the error on the suite, test, or step as appropriate (previously the
step errors were bubbled up and also assoc'd to the test).

To support this, we summarize errors at all levels in our summary before
displaying the list to the user. As an improvement, we also show where
the error came from (previously the user had to infer which step caused
the failure).
  • Loading branch information
jonsmock committed Oct 8, 2024
1 parent 4f5a5d9 commit 797bf33
Showing 1 changed file with 37 additions and 22 deletions.
59 changes: 37 additions & 22 deletions src/dctest/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,6 @@ Options:
(update :name #(interpolate-any context %))
(->> (execute-steps context))
pass!)

test (if-let [error (first (keep :error (:steps test)))]
(assoc test :error error)
test)
_ (log opts " " (short-outcome test) (:name test))]

(select-keys test [:id :name :outcome :steps :error])))
Expand Down Expand Up @@ -337,9 +333,29 @@ Options:

(def VERBOSE-SUMMARY-KEYS [:code :signal :stdout :stderr])

(defn summarize-errors [suites]
(let [step-error (fn [path step]
(let [path (conj path (:name step))]
(when-let [error (:error step)]
(assoc error :path path))))
test-errors (fn [path test]
(let [path (conj path (:name test))
errors (when-let [error (:error test)]
[(assoc error :path path)])]
(into errors
(keep #(step-error path %) (:steps test)))))
suite-errors (fn [suite]
(let [path [(:name suite)]
errors (when-let [error (:error suite)]
[(assoc error :path path)])]
(into errors
(mapcat #(test-errors path %) (:tests suite)))))]
(vec (mapcat suite-errors suites))))

(defn summarize [results verbose-results]
(let [overall (if (some failure? results) :fail :pass)
test-totals (frequencies (map :outcome (mapcat :tests results)))
errors (summarize-errors results)
results-data (if verbose-results
results
(postwalk #(if (map? %)
Expand All @@ -348,26 +364,25 @@ Options:
results))]
(merge {:pass 0 :fail 0}
test-totals
{:outcome overall :results results-data})))
{:outcome overall :results results-data :errors errors})))

(defn print-results [opts summary]
(doseq [suite (:results summary)]
(doseq [[index {test-name :name
error :error}]
, (->> (:tests suite)
(filter failure?)
(map-indexed vector))]
(log opts)
(log opts " " (inc index) ")" test-name)
(log opts " " (:message error))

(let [columns ["reference" "value"]
details (:debug error)]
(when details
(log opts
(indent-print-table-str columns
(map #(zipmap columns %) details)
" "))))))
(when (seq (:errors summary))
(log opts)
(log opts " Errors:"))

(doseq [[index error] (map-indexed vector (:errors summary))]
(log opts)
(log opts " " (inc index) ")" (:message error))
(log opts " in:" (S/join " > " (:path error)))

(let [columns ["reference" "value"]
details (:debug error)]
(when details
(log opts
(indent-print-table-str columns
(map #(zipmap columns %) details)
" ")))))

(log opts)
(log opts
Expand Down

0 comments on commit 797bf33

Please sign in to comment.