summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStuart Halloway <stu@thinkrelevance.com>2010-04-29 09:50:36 -0400
committerStuart Halloway <stu@thinkrelevance.com>2010-04-29 11:02:48 -0400
commitc1c39162608551d50cfb18998d015974b11cfecc (patch)
tree78457a76ed2890b0f2ec44547c6b1069501d962f
parent1e156ebe7f55983bf9fed42c497fd336cfe46d43 (diff)
metadata for :added
- after docstring for doc-ed vars - do not add to private or undoc-ed vars Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
-rw-r--r--src/clj/clojure/core.clj89
-rw-r--r--src/clj/clojure/core_deftype.clj16
-rw-r--r--src/clj/clojure/stacktrace.clj8
-rw-r--r--src/clj/clojure/test.clj38
-rw-r--r--src/clj/clojure/test/junit.clj1
-rw-r--r--src/clj/clojure/test/tap.clj5
-rw-r--r--src/clj/clojure/walk.clj10
7 files changed, 143 insertions, 24 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj
index 89a4ca6e..df319026 100644
--- a/src/clj/clojure/core.clj
+++ b/src/clj/clojure/core.clj
@@ -314,6 +314,7 @@
(defn sorted-set-by
"Returns a new sorted set with supplied keys, using the supplied comparator."
+ {:added "1.1"}
([comparator & keys]
(clojure.lang.PersistentTreeSet/create comparator keys)))
@@ -1150,6 +1151,7 @@
last item in the first form, making a list of it if it is not a
list already. If there are more forms, inserts the first form as the
last item in second form, etc."
+ {:added "1.1"}
([x form] (if (seq? form)
(with-meta `(~(first form) ~@(next form) ~x) (meta form))
(list form x)))
@@ -1206,6 +1208,7 @@
(defn remove-all-methods
"Removes all of the methods of multimethod."
+ {:added "1.2"}
[^clojure.lang.MultiFn multifn]
(.reset multifn))
@@ -1288,18 +1291,21 @@
...
(finally
(pop-thread-bindings)))"
+ {:added "1.1"}
[bindings]
(clojure.lang.Var/pushThreadBindings bindings))
(defn pop-thread-bindings
"Pop one set of bindings pushed with push-binding before. It is an error to
pop bindings without pushing before."
+ {:added "1.1"}
[]
(clojure.lang.Var/popThreadBindings))
(defn get-thread-bindings
"Get a map with the Var/value pairs which is currently in effect for the
current thread."
+ {:added "1.1"}
[]
(clojure.lang.Var/getThreadBindings))
@@ -1332,6 +1338,7 @@
"Takes a map of Var/value pairs. Installs for the given Vars the associated
values as thread-local bindings. Then calls f with the supplied arguments.
Pops the installed bindings after f returned. Returns whatever f returns."
+ {:added "1.1"}
[binding-map f & args]
(push-thread-bindings binding-map)
(try
@@ -1343,6 +1350,7 @@
"Takes a map of Var/value pairs. Installs for the given Vars the associated
values as thread-local bindings. The executes body. Pops the installed
bindings after body was evaluated. Returns the value of body."
+ {:added "1.1"}
[binding-map & body]
`(with-bindings* ~binding-map (fn [] ~@body)))
@@ -1351,6 +1359,7 @@
the thread at the time bound-fn* was called and then call f with any given
arguments. This may be used to define a helper function which runs on a
different thread, but needs the same bindings in place."
+ {:added "1.1"}
[f]
(let [bindings (get-thread-bindings)]
(fn [& args]
@@ -1361,6 +1370,7 @@
same bindings in effect as in the thread at the time bound-fn was called.
This may be used to define a helper function which runs on a different
thread, but needs the same bindings in place."
+ {:added "1.1"}
[& fntail]
`(bound-fn* (fn ~@fntail)))
@@ -1465,6 +1475,7 @@
"Returns the exception thrown during an asynchronous action of the
agent if the agent is failed. Returns nil if the agent is not
failed."
+ {:added "1.2"}
[^clojure.lang.Agent a] (.getError a))
(defn restart-agent
@@ -1477,6 +1488,7 @@
agent will remain failed with its old state and error. Watchers, if
any, will NOT be notified of the new state. Throws an exception if
the agent is not failed."
+ {:added "1.2"}
[^clojure.lang.Agent a, new-state & options]
(let [opts (apply hash-map options)]
(.restart a new-state (if (:clear-actions opts) true false))))
@@ -1486,12 +1498,14 @@
being run by the agent throws an exception or doesn't pass the
validator fn, handler-fn will be called with two arguments: the
agent and the exception."
+ {:added "1.2"}
[^clojure.lang.Agent a, handler-fn]
(.setErrorHandler a handler-fn))
(defn error-handler
"Returns the error-handler of agent a, or nil if there is none.
See set-error-handler!"
+ {:added "1.2"}
[^clojure.lang.Agent a]
(.getErrorHandler a))
@@ -1507,11 +1521,13 @@
accepting new 'send' and 'send-off' actions, and any previously
queued actions will be held until a 'restart-agent'. Deref will
still work, returning the state of the agent before the error."
+ {:added "1.2"}
[^clojure.lang.Agent a, mode-keyword]
(.setErrorMode a mode-keyword))
(defn error-mode
"Returns the error-mode of agent a. See set-error-mode!"
+ {:added "1.2"}
[^clojure.lang.Agent a]
(.getErrorMode a))
@@ -1676,11 +1692,13 @@
(defn ref-history-count
"Returns the history count of a ref"
+ {:added "1.1"}
[^clojure.lang.Ref ref]
(.getHistoryCount ref))
(defn ref-min-history
"Gets the min-history of a ref, or sets it and returns the ref"
+ {:added "1.1"}
([^clojure.lang.Ref ref]
(.getMinHistory ref))
([^clojure.lang.Ref ref n]
@@ -1688,6 +1706,7 @@
(defn ref-max-history
"Gets the max-history of a ref, or sets it and returns the ref"
+ {:added "1.1"}
([^clojure.lang.Ref ref]
(.getMaxHistory ref))
([^clojure.lang.Ref ref n]
@@ -1764,6 +1783,7 @@
returns a vector containing the result of applying each fn to the
args (left-to-right).
((juxt a b c) x) => [(a x) (b x) (c x)]"
+ {:added "1.1"}
([f]
(fn
([] [(f)])
@@ -1968,6 +1988,7 @@
(defn take-last
"Returns a seq of the last n items in coll. Depending on the type
of coll may be no better than linear time. For vectors, see also subvec."
+ {:added "1.1"}
[n coll]
(loop [s (seq coll), lead (seq (drop n coll))]
(if lead
@@ -2366,7 +2387,8 @@
(defn char
"Coerce to char"
{:tag Character
- :inline (fn [x] `(. clojure.lang.RT (charCast ~x)))}
+ :inline (fn [x] `(. clojure.lang.RT (charCast ~x)))
+ :added "1.1"}
[x] (. clojure.lang.RT (charCast x)))
(defn boolean
@@ -2402,15 +2424,17 @@
[n] (instance? clojure.lang.Ratio n))
(defn numerator
- "Returns the numerator part of a Ratio."
- {:tag BigInteger}
- [r]
+ "Returns the numerator part of a Ratio."
+ {:tag BigInteger
+ :added "1.2"}
+ [r]
(.numerator ^clojure.lang.Ratio r))
(defn denominator
- "Returns the denominator part of a Ratio."
- {:tag BigInteger}
- [r]
+ "Returns the denominator part of a Ratio."
+ {:tag BigInteger
+ :added "1.2"}
+ [r]
(.denominator ^clojure.lang.Ratio r))
(defn decimal?
@@ -2510,7 +2534,6 @@
(binding [*print-readably* nil]
(apply prn more)))
-
(defn read
"Reads the next object from stream, which must be an instance of
java.io.PushbackReader or some derivee. stream defaults to the
@@ -3689,28 +3712,32 @@
(defn boolean-array
"Creates an array of booleans"
{:inline (fn [& args] `(. clojure.lang.Numbers boolean_array ~@args))
- :inline-arities #{1 2}}
+ :inline-arities #{1 2}
+ :added "1.1"}
([size-or-seq] (. clojure.lang.Numbers boolean_array size-or-seq))
([size init-val-or-seq] (. clojure.lang.Numbers boolean_array size init-val-or-seq)))
(defn byte-array
"Creates an array of bytes"
{:inline (fn [& args] `(. clojure.lang.Numbers byte_array ~@args))
- :inline-arities #{1 2}}
+ :inline-arities #{1 2}
+ :added "1.1"}
([size-or-seq] (. clojure.lang.Numbers byte_array size-or-seq))
([size init-val-or-seq] (. clojure.lang.Numbers byte_array size init-val-or-seq)))
(defn char-array
"Creates an array of chars"
{:inline (fn [& args] `(. clojure.lang.Numbers char_array ~@args))
- :inline-arities #{1 2}}
+ :inline-arities #{1 2}
+ :added "1.1"}
([size-or-seq] (. clojure.lang.Numbers char_array size-or-seq))
([size init-val-or-seq] (. clojure.lang.Numbers char_array size init-val-or-seq)))
(defn short-array
"Creates an array of shorts"
{:inline (fn [& args] `(. clojure.lang.Numbers short_array ~@args))
- :inline-arities #{1 2}}
+ :inline-arities #{1 2}
+ :added "1.1"}
([size-or-seq] (. clojure.lang.Numbers short_array size-or-seq))
([size init-val-or-seq] (. clojure.lang.Numbers short_array size init-val-or-seq)))
@@ -3724,7 +3751,8 @@
(defn object-array
"Creates an array of objects"
{:inline (fn [arg] `(. clojure.lang.RT object_array ~arg))
- :inline-arities #{1}}
+ :inline-arities #{1}
+ :added "1.2"}
([size-or-seq] (. clojure.lang.RT object_array size-or-seq)))
(defn int-array
@@ -3743,18 +3771,22 @@
(definline booleans
"Casts to boolean[]"
+ {:added "1.1"}
[xs] `(. clojure.lang.Numbers booleans ~xs))
(definline bytes
"Casts to bytes[]"
+ {:added "1.1"}
[xs] `(. clojure.lang.Numbers bytes ~xs))
(definline chars
"Casts to chars[]"
+ {:added "1.1"}
[xs] `(. clojure.lang.Numbers chars ~xs))
(definline shorts
"Casts to shorts[]"
+ {:added "1.1"}
[xs] `(. clojure.lang.Numbers shorts ~xs))
(definline floats
@@ -3879,12 +3911,14 @@
(defn bound?
"Returns true if all of the vars provided as arguments have any bound value, root or thread-local.
Implies that deref'ing the provided vars will succeed. Returns true if no vars are provided."
+ {:added "1.2"}
[& vars]
(every? #(.isBound ^clojure.lang.Var %) vars))
(defn thread-bound?
"Returns true if all of the vars provided as arguments have thread-local bindings.
Implies that set!'ing the provided vars will succeed. Returns true if no vars are provided."
+ {:added "1.2"}
[& vars]
(every? #(.getThreadBinding ^clojure.lang.Var %) vars))
@@ -4681,10 +4715,12 @@
(defn future?
"Returns true if x is a future"
+ {:added "1.1"}
[x] (instance? java.util.concurrent.Future x))
(defn future-done?
"Returns true if future f is done"
+ {:added "1.1"}
[^java.util.concurrent.Future f] (.isDone f))
@@ -4742,6 +4778,7 @@
lists are used to group multiple constants that map to the same
expression, a vector can be used to match a list if needed. The
test-constants need not be all of the same type."
+ {:added "1.2"}
[e & clauses]
(let [ge (with-meta (gensym) {:tag Object})
@@ -4800,6 +4837,7 @@
invoke the function in another thread, and will cache the result and
return it on all subsequent calls to deref/@. If the computation has
not yet finished, calls to deref/@ will block."
+ {:added "1.1"}
[^Callable f]
(let [fut (.submit clojure.lang.Agent/soloExecutor f)]
(reify
@@ -4816,16 +4854,19 @@
"Takes a body of expressions and yields a future object that will
invoke the body in another thread, and will cache the result and
return it on all subsequent calls to deref/@. If the computation has
- not yet finished, calls to deref/@ will block."
+ not yet finished, calls to deref/@ will block."
+ {:added "1.1"}
[& body] `(future-call (fn [] ~@body)))
(defn future-cancel
"Cancels the future, if possible."
+ {:added "1.1"}
[^java.util.concurrent.Future f] (.cancel f true))
(defn future-cancelled?
"Returns true if future f is cancelled"
+ {:added "1.1"}
[^java.util.concurrent.Future f] (.isCancelled f))
(defn pmap
@@ -4904,6 +4945,7 @@
once only, with deliver. Calls to deref/@ prior to delivery will
block. All subsequent derefs will return the same delivered value
without blocking."
+ {:added "1.1"}
[]
(let [d (java.util.concurrent.CountDownLatch. 1)
v (atom nil)]
@@ -4922,13 +4964,15 @@
(defn deliver
"Alpha - subject to change.
Delivers the supplied value to the promise, releasing any pending
- derefs. A subsequent call to deliver on a promise will throw an exception."
+ derefs. A subsequent call to deliver on a promise will throw an exception."
+ {:added "1.1"}
[promise val] (promise val))
;;;;;;;;;;;;;;;;;;;;; editable collections ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn transient
"Alpha - subject to change.
Returns a new, transient version of the collection, in constant time."
+ {:added "1.1"}
[^clojure.lang.IEditableCollection coll]
(.asTransient coll))
@@ -4937,6 +4981,7 @@
Returns a new, persistent version of the transient collection, in
constant time. The transient collection cannot be used after this
call, any such use will throw an exception."
+ {:added "1.1"}
[^clojure.lang.ITransientCollection coll]
(.persistent coll))
@@ -4944,6 +4989,7 @@
"Alpha - subject to change.
Adds x to the transient collection, and return coll. The 'addition'
may happen at different 'places' depending on the concrete type."
+ {:added "1.1"}
[^clojure.lang.ITransientCollection coll x]
(.conj coll x))
@@ -4952,6 +4998,7 @@
When applied to a transient map, adds mapping of key(s) to
val(s). When applied to a transient vector, sets the val at index.
Note - index must be <= (count vector). Returns coll."
+ {:added "1.1"}
([^clojure.lang.ITransientAssociative coll key val] (.assoc coll key val))
([^clojure.lang.ITransientAssociative coll key val & kvs]
(let [ret (.assoc coll key val)]
@@ -4962,6 +5009,7 @@
(defn dissoc!
"Alpha - subject to change.
Returns a transient map that doesn't contain a mapping for key(s)."
+ {:added "1.1"}
([^clojure.lang.ITransientMap map key] (.without map key))
([^clojure.lang.ITransientMap map key & ks]
(let [ret (.without map key)]
@@ -4973,6 +5021,7 @@
"Alpha - subject to change.
Removes the last item from a transient vector. If
the collection is empty, throws an exception. Returns coll"
+ {:added "1.1"}
[^clojure.lang.ITransientVector coll]
(.pop coll))
@@ -4980,6 +5029,7 @@
"Alpha - subject to change.
disj[oin]. Returns a transient set of the same (hashed/sorted) type, that
does not contain key(s)."
+ {:added "1.1"}
([set] set)
([^clojure.lang.ITransientSet set key]
(. set (disjoin key)))
@@ -5002,6 +5052,7 @@
"Takes any nested combination of sequential things (lists, vectors,
etc.) and returns their contents as a single, flat sequence.
(flatten nil) returns nil."
+ {:added "1.2"}
[x]
(filter (complement sequential?)
(rest (tree-seq sequential? seq x))))
@@ -5010,6 +5061,7 @@
"Returns a map of the elements of coll keyed by the result of
f on each element. The value at each key will be a vector of the
corresponding elements, in the order they appeared in coll."
+ {:added "1.2"}
[f coll]
(persistent!
(reduce
@@ -5021,6 +5073,7 @@
(defn partition-by
"Applies f to each value in coll, splitting it each time f returns
a new value. Returns a lazy seq of partitions."
+ {:added "1.2"}
[f coll]
(lazy-seq
(when-let [s (seq coll)]
@@ -5032,6 +5085,7 @@
(defn frequencies
"Returns a map from distinct items in coll to the number of times
they appear."
+ {:added "1.2"}
[coll]
(persistent!
(reduce (fn [counts x]
@@ -5041,6 +5095,7 @@
(defn reductions
"Returns a lazy seq of the intermediate values of the reduction (as
per reduce) of coll by f, starting with init."
+ {:added "1.2"}
([f coll]
(lazy-seq
(if-let [s (seq coll)]
@@ -5056,12 +5111,14 @@
"Return a random element of the (sequential) collection. Will have
the same performance characteristics as nth for the given
collection."
+ {:added "1.2"}
[coll]
(nth coll (rand-int (count coll))))
(defn seq-contains?
"Returns true if sequential search of coll contains something equal (with =) to x,
in linear time."
+ {:added "1.2"}
[coll x]
(if (some (fn [y] (= y x)) coll)
true false))
@@ -5069,6 +5126,7 @@
(defn partition-all
"Returns a lazy sequence of lists like partition, but may include
partitions with fewer than n items at the end."
+ {:added "1.2"}
([n coll]
(partition-all n n coll))
([n step coll]
@@ -5078,6 +5136,7 @@
(defn shuffle
"Return a random permutation of coll"
+ {:added "1.2"}
[coll]
(let [al (java.util.ArrayList. coll)]
(java.util.Collections/shuffle al)
diff --git a/src/clj/clojure/core_deftype.clj b/src/clj/clojure/core_deftype.clj
index d6182193..82c58a74 100644
--- a/src/clj/clojure/core_deftype.clj
+++ b/src/clj/clojure/core_deftype.clj
@@ -12,6 +12,7 @@
(defn namespace-munge
"Convert a Clojure namespace name to a legal Java package name."
+ {:added "1.2"}
[ns]
(.replace (str ns) \- \_))
@@ -102,7 +103,7 @@
(reify clojure.lang.Seqable
(seq [] (seq f)))))
== (\\f \\o \\o))"
-
+ {:added "1.2"}
[& opts+specs]
(let [[interfaces methods] (parse-opts+specs opts+specs)]
(with-meta `(reify* ~interfaces ~@methods) (meta &form))))
@@ -131,6 +132,7 @@
(defn- emit-defrecord
"Do not use this directly - use defrecord"
+ {:added "1.2"}
[tagname name fields interfaces methods]
(let [tag (keyword (str *ns*) (str tagname))
classname (with-meta (symbol (str *ns* "." name)) (meta name))
@@ -283,6 +285,7 @@
followed by a metadata map (nil for none) and an extension field
map (nil for none), and one taking only the fields (using nil for
meta and extension fields)."
+ {:added "1.2"}
[name [& fields] & opts+specs]
(let [gname name
@@ -374,6 +377,7 @@
writes the .class file to the *compile-path* directory.
One constructors will be defined, taking the designated fields."
+ {:added "1.2"}
[name [& fields] & opts+specs]
(let [gname name
@@ -433,17 +437,20 @@
(defn extends?
"Returns true if atype extends protocol"
+ {:added "1.2"}
[protocol atype]
(boolean (or (implements? protocol atype)
(get (:impls protocol) atype))))
(defn extenders
"Returns a collection of the types explicitly extending protocol"
+ {:added "1.2"}
[protocol]
(keys (:impls protocol)))
(defn satisfies?
"Returns true if x satisfies the protocol"
+ {:added "1.2"}
[protocol x]
(boolean (find-protocol-impl protocol x)))
@@ -606,7 +613,7 @@
(foo [] 17)
(bar-me [] x)
(bar-me [y] x))))"
-
+ {:added "1.2"}
[name & opts+sigs]
(emit-protocol name opts+sigs))
@@ -645,7 +652,7 @@
See also:
extends?, satisfies?, extenders"
-
+ {:added "1.2"}
[atype & proto+mmaps]
(doseq [[proto mmap] (partition 2 proto+mmaps)]
(when (implements? proto atype)
@@ -696,7 +703,7 @@
Foo
{:baz (fn ([x] ...) ([x y & zs] ...))
:bar (fn [x y] ...)})"
-
+ {:added "1.2"}
[t & specs]
(emit-extend-type t specs))
@@ -742,6 +749,7 @@
(clojure.core/extend-type nil Protocol
(foo [x] ...)
(bar [x y] ...)))"
+ {:added "1.2"}
[p & specs]
(emit-extend-protocol p specs))
diff --git a/src/clj/clojure/stacktrace.clj b/src/clj/clojure/stacktrace.clj
index c69bdc68..1ded882c 100644
--- a/src/clj/clojure/stacktrace.clj
+++ b/src/clj/clojure/stacktrace.clj
@@ -17,6 +17,7 @@
(defn root-cause
"Returns the last 'cause' Throwable in a chain of Throwables."
+ {:added "1.1"}
[tr]
(if-let [cause (.getCause tr)]
(recur cause)
@@ -24,6 +25,7 @@
(defn print-trace-element
"Prints a Clojure-oriented view of one element in a stack trace."
+ {:added "1.1"}
[e]
(let [class (.getClassName e)
method (.getMethodName e)]
@@ -35,6 +37,7 @@
(defn print-throwable
"Prints the class and message of a Throwable."
+ {:added "1.1"}
[tr]
(printf "%s: %s" (.getName (class tr)) (.getMessage tr)))
@@ -42,6 +45,7 @@
"Prints a Clojure-oriented stack trace of tr, a Throwable.
Prints a maximum of n stack frames (default: unlimited).
Does not print chained exceptions (causes)."
+ {:added "1.1"}
([tr] (print-stack-trace tr nil))
([tr n]
(let [st (.getStackTrace tr)]
@@ -59,6 +63,7 @@
(defn print-cause-trace
"Like print-stack-trace but prints chained exceptions (causes)."
+ {:added "1.1"}
([tr] (print-cause-trace tr nil))
([tr n]
(print-stack-trace tr n)
@@ -68,6 +73,7 @@
(defn e
"REPL utility. Prints a brief stack trace for the root cause of the
- most recent exception."
+ most recent exception."
+ {:added "1.1"}
[]
(print-stack-trace (root-cause *e) 8))
diff --git a/src/clj/clojure/test.clj b/src/clj/clojure/test.clj
index 5317745b..997b60d5 100644
--- a/src/clj/clojure/test.clj
+++ b/src/clj/clojure/test.clj
@@ -239,13 +239,15 @@
(defonce
^{:doc "True by default. If set to false, no test functions will
be created by deftest, set-test, or with-test. Use this to omit
- tests when compiling or loading production code."}
+ tests when compiling or loading production code."
+ :added "1.1"}
*load-tests* true)
(def
^{:doc "The maximum depth of stack traces to print when an Exception
is thrown during a test. Defaults to nil, which means print the
- complete stack trace."}
+ complete stack trace."
+ :added "1.1"}
*stack-trace-depth* nil)
@@ -264,6 +266,7 @@
(defmacro with-test-out
"Runs body with *out* bound to the value of *test-out*."
+ {:added "1.1"}
[& body]
`(binding [*out* *test-out*]
~@body))
@@ -275,6 +278,7 @@
(defn file-position
"Returns a vector [filename line-number] for the nth call up the
stack."
+ {:added "1.1"}
[n]
(let [^StackTraceElement s (nth (.getStackTrace (new java.lang.Throwable)) n)]
[(.getFileName s) (.getLineNumber s)]))
@@ -283,6 +287,7 @@
"Returns a string representation of the current test. Renders names
in *testing-vars* as a list, then the source file and line of
current assertion."
+ {:added "1.1"}
[]
(let [[file line] (file-position 4)]
(str
@@ -294,12 +299,14 @@
(defn testing-contexts-str
"Returns a string representation of the current test context. Joins
strings in *testing-contexts* with spaces."
+ {:added "1.1"}
[]
(apply str (interpose " " (reverse *testing-contexts*))))
(defn inc-report-counter
"Increments the named counter in *report-counters*, a ref to a map.
Does nothing if *report-counters* is nil."
+ {:added "1.1"}
[name]
(when *report-counters*
(dosync (commute *report-counters* assoc name
@@ -316,7 +323,8 @@
'report' will be a map with a :type key. See the documentation at
the top of test_is.clj for more information on the types of
arguments for 'report'."
- :dynamic true}
+ :dynamic true
+ :added "1.1"}
report :type)
(defmethod report :default [m]
@@ -368,6 +376,7 @@
(defn get-possibly-unbound-var
"Like var-get but returns nil if the var is unbound."
+ {:added "1.1"}
[v]
(try (var-get v)
(catch IllegalStateException e
@@ -376,6 +385,7 @@
(defn function?
"Returns true if argument is a function or a symbol that resolves to
a function (not a macro)."
+ {:added "1.1"}
[x]
(if (symbol? x)
(when-let [v (resolve x)]
@@ -390,6 +400,7 @@
'actual' argument will contain the form with all its sub-forms
evaluated. If the predicate returns false, the 'actual' form will
be wrapped in (not...)."
+ {:added "1.1"}
[msg form]
(let [args (rest form)
pred (first form)]
@@ -405,6 +416,7 @@
(defn assert-any
"Returns generic assertion code for any test, including macros, Java
method calls, or isolated symbols."
+ {:added "1.1"}
[msg form]
`(let [value# ~form]
(if value#
@@ -513,6 +525,7 @@
(is (thrown-with-msg? c re body)) checks that an instance of c is
thrown AND that the message on the exception matches (with
re-find) the regular expression re."
+ {:added "1.1"}
([form] `(is ~form nil))
([form msg] `(try-expr ~msg ~form)))
@@ -529,12 +542,14 @@
(is (= 4 (* 2 2))))
Note: This breaks some reporting features, such as line numbers."
+ {:added "1.1"}
[argv expr & args]
`(temp/do-template ~argv (is ~expr) ~@args))
(defmacro testing
"Adds a new string to the list of testing contexts. May be nested,
but must occur inside a test function (deftest)."
+ {:added "1.1"}
[string & body]
`(binding [*testing-contexts* (conj *testing-contexts* ~string)]
~@body))
@@ -549,6 +564,7 @@
When *load-tests* is false, only evaluates the definition, ignoring
the tests."
+ {:added "1.1"}
[definition & body]
(if *load-tests*
`(doto ~definition (alter-meta! assoc :test (fn [] ~@body)))
@@ -566,6 +582,7 @@
itself.
When *load-tests* is false, deftest is ignored."
+ {:added "1.1"}
[name & body]
(when *load-tests*
`(def ~(vary-meta name assoc :test `(fn [] ~@body))
@@ -573,6 +590,7 @@
(defmacro deftest-
"Like deftest but creates a private var."
+ {:added "1.1"}
[name & body]
(when *load-tests*
`(def ~(vary-meta name assoc :test `(fn [] ~@body) :private true)
@@ -585,6 +603,7 @@
The var must already exist. Does not modify the value of the var.
When *load-tests* is false, set-test is ignored."
+ {:added "1.1"}
[name & body]
(when *load-tests*
`(alter-meta! (var ~name) assoc :test (fn [] ~@body))))
@@ -596,6 +615,7 @@
(defn- add-ns-meta
"Adds elements in coll to the current namespace metadata as the
value of key."
+ {:added "1.1"}
[key coll]
(alter-meta! *ns* assoc key coll))
@@ -603,6 +623,7 @@
"Wrap test runs in a fixture function to perform setup and
teardown. Using a fixture-type of :each wraps every test
individually, while:once wraps the whole run in a single function."
+ {:added "1.1"}
(fn [fixture-type & args] fixture-type))
(defmethod use-fixtures :each [fixture-type & args]
@@ -613,18 +634,21 @@
(defn- default-fixture
"The default, empty, fixture function. Just calls its argument."
+ {:added "1.1"}
[f]
(f))
(defn compose-fixtures
"Composes two fixture functions, creating a new fixture function
that combines their behavior."
+ {:added "1.1"}
[f1 f2]
(fn [g] (f1 (fn [] (f2 g)))))
(defn join-fixtures
"Composes a collection of fixtures, in order. Always returns a valid
fixture function, even if the collection is empty."
+ {:added "1.1"}
[fixtures]
(reduce compose-fixtures default-fixture fixtures))
@@ -633,9 +657,10 @@
;;; RUNNING TESTS: LOW-LEVEL FUNCTIONS
-(defn ^{:dynamic true} test-var
+(defn test-var
"If v has a function in its :test metadata, calls that function,
with *testing-vars* bound to (conj *testing-vars* v)."
+ {:dynamic true, :added "1.1"}
[v]
(when-let [t (:test (meta v))]
(binding [*testing-vars* (conj *testing-vars* v)]
@@ -649,6 +674,7 @@
(defn test-all-vars
"Calls test-var on every var interned in the namespace, with fixtures."
+ {:added "1.1"}
[ns]
(let [once-fixture-fn (join-fixtures (::once-fixtures (meta ns)))
each-fixture-fn (join-fixtures (::each-fixtures (meta ns)))]
@@ -666,6 +692,7 @@
Internally binds *report-counters* to a ref initialized to
*inital-report-counters*. Returns the final, dereferenced state of
*report-counters*."
+ {:added "1.1"}
[ns]
(binding [*report-counters* (ref *initial-report-counters*)]
(let [ns-obj (the-ns ns)]
@@ -686,6 +713,7 @@
"Runs all tests in the given namespaces; prints results.
Defaults to current namespace if none given. Returns a map
summarizing test results."
+ {:added "1.1"}
([] (run-tests *ns*))
([& namespaces]
(let [summary (assoc (apply merge-with + (map test-ns namespaces))
@@ -698,12 +726,14 @@
Optional argument is a regular expression; only namespaces with
names matching the regular expression (with re-matches) will be
tested."
+ {:added "1.1"}
([] (apply run-tests (all-ns)))
([re] (apply run-tests (filter #(re-matches re (name (ns-name %))) (all-ns)))))
(defn successful?
"Returns true if the given test summary indicates all tests
were successful, false otherwise."
+ {:added "1.1"}
[summary]
(and (zero? (:fail summary))
(zero? (:error summary))))
diff --git a/src/clj/clojure/test/junit.clj b/src/clj/clojure/test/junit.clj
index b25c4332..dd7b08d1 100644
--- a/src/clj/clojure/test/junit.clj
+++ b/src/clj/clojure/test/junit.clj
@@ -182,6 +182,7 @@
(defmacro with-junit-output
"Execute body with modified test-is reporting functions that write
JUnit-compatible XML output."
+ {:added "1.1"}
[& body]
`(binding [t/report junit-report
*var-context* (list)
diff --git a/src/clj/clojure/test/tap.clj b/src/clj/clojure/test/tap.clj
index 8b2ec972..6eec18e6 100644
--- a/src/clj/clojure/test/tap.clj
+++ b/src/clj/clojure/test/tap.clj
@@ -44,23 +44,27 @@
(defn print-tap-plan
"Prints a TAP plan line like '1..n'. n is the number of tests"
+ {:added "1.1"}
[n]
(println (str "1.." n)))
(defn print-tap-diagnostic
"Prints a TAP diagnostic line. data is a (possibly multi-line)
string."
+ {:added "1.1"}
[data]
(doseq [line (.split ^String data "\n")]
(println "#" line)))
(defn print-tap-pass
"Prints a TAP 'ok' line. msg is a string, with no line breaks"
+ {:added "1.1"}
[msg]
(println "ok" msg))
(defn print-tap-fail
"Prints a TAP 'not ok' line. msg is a string, with no line breaks"
+ {:added "1.1"}
[msg]
(println "not ok" msg))
@@ -106,6 +110,7 @@
(defmacro with-tap-output
"Execute body with modified test reporting functions that produce
TAP output"
+ {:added "1.1"}
[& body]
`(binding [t/report tap-report]
~@body))
diff --git a/src/clj/clojure/walk.clj b/src/clj/clojure/walk.clj
index 70094d07..613a294c 100644
--- a/src/clj/clojure/walk.clj
+++ b/src/clj/clojure/walk.clj
@@ -38,6 +38,7 @@ the sorting function."}
data structure of the same type, then applies outer to the result.
Recognizes all Clojure data structures except sorted-map-by.
Consumes seqs as with doall."
+ {:added "1.1"}
[inner outer form]
(cond
(list? form) (outer (apply list (map inner form)))
@@ -54,11 +55,13 @@ the sorting function."}
each sub-form, uses f's return value in place of the original.
Recognizes all Clojure data structures except sorted-map-by.
Consumes seqs as with doall."
+ {:added "1.1"}
[f form]
(walk (partial postwalk f) f form))
(defn prewalk
"Like postwalk, but does pre-order traversal."
+ {:added "1.1"}
[f form]
(walk (partial prewalk f) identity (f form)))
@@ -78,17 +81,20 @@ the sorting function."}
(defn postwalk-demo
"Demonstrates the behavior of postwalk by printing each form as it is
walked. Returns form."
+ {:added "1.1"}
[form]
(postwalk (fn [x] (print "Walked: ") (prn x) x) form))
(defn prewalk-demo
"Demonstrates the behavior of prewalk by printing each form as it is
walked. Returns form."
+ {:added "1.1"}
[form]
(prewalk (fn [x] (print "Walked: ") (prn x) x) form))
(defn keywordize-keys
"Recursively transforms all map keys from strings to keywords."
+ {:added "1.1"}
[m]
(let [f (fn [[k v]] (if (string? k) [(keyword k) v] [k v]))]
;; only apply to maps
@@ -96,6 +102,7 @@ the sorting function."}
(defn stringify-keys
"Recursively transforms all map keys from keywords to strings."
+ {:added "1.1"}
[m]
(let [f (fn [[k v]] (if (keyword? k) [(name k) v] [k v]))]
;; only apply to maps
@@ -105,6 +112,7 @@ the sorting function."}
"Recursively transforms form by replacing keys in smap with their
values. Like clojure/replace but works on any data structure. Does
replacement at the root of the tree first."
+ {:added "1.1"}
[smap form]
(prewalk (fn [x] (if (contains? smap x) (smap x) x)) form))
@@ -112,11 +120,13 @@ the sorting function."}
"Recursively transforms form by replacing keys in smap with their
values. Like clojure/replace but works on any data structure. Does
replacement at the leaves of the tree first."
+ {:added "1.1"}
[smap form]
(postwalk (fn [x] (if (contains? smap x) (smap x) x)) form))
(defn macroexpand-all
"Recursively performs all possible macroexpansions in form."
+ {:added "1.1"}
[form]
(prewalk (fn [x] (if (seq? x) (macroexpand x) x)) form))