Skip to content

Commit 96319b4

Browse files
committed
Add docstrings to test helper fns
1 parent 778439f commit 96319b4

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

src/test/clojure/clojure/tools/test_logging.clj

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,41 @@
77
[clojure.tools.logging.test :as log-test :refer [logged?
88
matches]]))
99

10-
; TODO: Improve tools.logging.test so that the ability to check the thread is
11-
; not so hacky/out-of-band from the normal flow.
1210

13-
14-
(defn log-entry-with-thread [logger-ns level throwable message]
11+
(defn log-entry-with-thread
12+
"Returns a log entry that also captures the current thread."
13+
[logger-ns level throwable message]
1514
(assoc (log-test/->LogEntry logger-ns level throwable message)
1615
::thread (Thread/currentThread)))
1716

18-
(defn same-thread? [log-entry]
17+
(defn same-thread?
18+
"Returns true if the thread that created the log entry is the current thread."
19+
[log-entry]
20+
(when-not (::thread log-entry)
21+
(throw (ex-info "Log entry does not have a thread." log-entry)))
1922
(identical? (::thread log-entry)
2023
(Thread/currentThread)))
2124

22-
(defn direct-logged? [logger-ns level throwable message]
25+
(defn direct-logged?
26+
"Returns true if there is a matching entry that also was created with the
27+
current thread, i.e., not via an agent."
28+
[logger-ns level throwable message]
2329
(->> (log-test/matches logger-ns level throwable message)
2430
(filter same-thread?)
2531
seq
2632
boolean))
2733

28-
(defn agent-logged? [logger-ns level throwable message]
34+
(defn agent-logged?
35+
"Returns true if there is a matching entry that also was created with a thread
36+
other than the current thread, i.e., via an agent."
37+
[logger-ns level throwable message]
2938
(->> (log-test/matches logger-ns level throwable message)
3039
(remove same-thread?)
3140
seq
3241
boolean))
3342

34-
(defmacro with-log [& body]
43+
(defmacro with-log
44+
[& body]
3545
`(let [stateful-log# (log-test/atomic-log log-entry-with-thread)
3646
logger-factory# (log-test/logger-factory stateful-log# (constantly true))]
3747
(binding [log-test/*stateful-log* stateful-log#

0 commit comments

Comments
 (0)