Skip to content

Commit

Permalink
Ellide test context string, if long.
Browse files Browse the repository at this point in the history
  • Loading branch information
oubiwann committed Oct 11, 2019
1 parent 9a61448 commit 5368d3a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions ltest/src/ltest/constants.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
(def assertion-indent (string/join (repeat 6 " ")))

(def max-len 80)
(def max-len-assertion-str 26)
(def min-elide 3)
(def elide-space 2)
(def status-brackets 2)
Expand Down
18 changes: 13 additions & 5 deletions ltest/src/ltest/runner.clj
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,26 @@
(string/join (repeat elide-count ".")))
(color-status status))))

(defn contexts-str
[]
(let [ctx-str (test/testing-contexts-str)
len-ctx-str (count ctx-str)
max-len const/max-len-assertion-str
len (if (< len-ctx-str max-len) len-ctx-str max-len)
ctx-abbr (subs ctx-str 0 len)
ellip (if (< len len-ctx-str) " ..." "")]
(if (empty? ctx-abbr)
""
(format " (%s%s)" ctx-abbr ellip))))

(defn line-format
"Sadly, padded string support in `format` isn't quite as flexible as we
would like, thus this function. This might be possible to do more elgantly
with Clojure's Common-Lisp-inspired `cl-format` ..."
([prefix idx status]
(line-format prefix idx "" status))
([prefix idx postfix status]
(let [ctx-str (test/testing-contexts-str)
line (format "%s assertion %s%s"
prefix
idx
(if (empty? ctx-str) "" (str " (" ctx-str ")")))
(let [line (format "%s assertion %s%s" prefix idx (contexts-str))
len (+ (count line)
(count postfix)
const/elide-space
Expand Down

0 comments on commit 5368d3a

Please sign in to comment.