Permalink
Browse files

Make backwards-compatibility functions automatically available.

  • Loading branch information...
marick committed Jan 26, 2013
1 parent 0be7a0f commit 155daece785d2f600edda152a99a2235c8c162f4
@@ -3,7 +3,6 @@
(ns ^{:doc "Checkers for collections and strings."}
midje.checking.checkers.collection
(:use midje.clojure.core
- [midje.util.backwards-compatible-utils :only [every-pred-m]]
[midje.util.form-utils :only [pred-cond macro-for]]
[midje.checking.checkers collection-util util chatty defining collection-comparison]
midje.checking.extended-equality
@@ -2,8 +2,6 @@
midje.checking.checkers.combining
(:use [midje.checking.checkers.defining]
[midje.checking.checkers.chatty]
- [midje.util.backwards-compatible-utils :only [every-pred-m some-fn-m]]
-
[midje.checking.extended-falsehood]))
(defn report-failure [actual checker-form result]
@@ -10,7 +10,6 @@
[midje.error-handling.exceptions :only [captured-throwable?]]
[midje.util.ecosystem :only [clojure-1-3? +M -M *M]]
[midje.util.form-utils :only [def-many-methods pred-cond]]
- [midje.util.backwards-compatible-utils :only [every-pred-m some-fn-m]]
[clojure.algo.monads :only [domonad set-m]])
(:import [midje.error_handling.exceptions ICapturedThrowable]))
@@ -1,8 +1,18 @@
(ns ^{:doc "Functions grabbed from newer versions of Clojure,
so we can maintain backwards compatibility."}
- midje.util.backwards-compatible-utils)
+ midje.clojure.backwards-compatibility)
-(defn every-pred-m
+(letfn [(missing? [sym] (not (ns-resolve 'clojure.core sym)))]
+
+ (defmacro defn-once [sym & rest]
+ (when (missing? sym)
+ `(defn ~sym ~@rest)))
+
+ (defmacro defn-once-in-core [sym & rest]
+ (when (missing? sym)
+ `(intern 'clojure.core '~sym (fn ~@rest)))))
+
+(defn-once every-pred-m
"Takes a set of predicates and returns a function f that returns true if all of its
composing predicates return a logical true value against all of its arguments, else it returns
false. Note that f is short-circuiting in that it will stop execution on the first
@@ -42,7 +52,7 @@
([x y z & args] (boolean (and (epn x y z)
(every? #(every? % args) ps))))))))
-(defn some-fn-m
+(defn-once some-fn-m
"Takes a set of predicates and returns a function f that returns the first logical true value
returned by one of its composing predicates against any of its arguments, else it returns
logical false. Note that f is short-circuiting in that it will stop execution on the first
@@ -83,9 +93,8 @@
(some #(some % args) ps)))))))
-(when-not (ns-resolve 'clojure.core 'ex-info)
- (intern 'clojure.core 'ex-info
- (fn ([msg map]
- (RuntimeException. msg))
- ([msg map cause]
- (RuntimeException. msg cause)))))
+(defn-once-in-core ex-info
+ ([msg map]
+ (RuntimeException. msg))
+ ([msg map cause]
+ (RuntimeException. msg cause)))
@@ -2,7 +2,8 @@
midje.clojure.core
(:require clojure.pprint
clojure.set
- utilize.seq))
+ utilize.seq
+ midje.clojure.backwards-compatibility))
;; Note: some of this code is taken from https://github.com/flatland/useful/blob/develop/src/flatland/useful/ns.clj
;; Those functions should be immigrated once the new useful namespace is pushed to clojars.
@@ -150,3 +151,7 @@ metadata (as provided by def) merged into the metadata of the original."
;;; Printing
(immigrate-from 'clojure.pprint '[pprint cl-format])
+
+ ;;; Compatibility
+
+(immigrate 'midje.clojure.backwards-compatibility)
@@ -6,8 +6,7 @@
(:require [midje.emission.boundaries :as emission-boundary]
[midje.util.ecosystem :as ecosystem]
[midje.emission.colorize :as color]
- [midje.config :as config]
- midje.util.backwards-compatible-utils))
+ [midje.config :as config]))
(ecosystem/when-1-3+
@@ -6,8 +6,7 @@
[midje.parsing.util.arrows :only [start-of-checking-arrow-sequence? take-arrow-sequence]]
[midje.parsing.1-to-explicit-form.background :only [seq-headed-by-setup-teardown-form?]]
[midje.parsing.1-to-explicit-form.prerequisites :only [metaconstant-prerequisite?]]
- [midje.util.form-utils :only [def-many-methods pred-cond]]
- [midje.util.backwards-compatible-utils :only [some-fn-m]]))
+ [midje.util.form-utils :only [def-many-methods pred-cond]]))
(def #^:private possible-wrapping-targets #{:facts, :contents, :checks })
(def #^:private possible-state-descriptions #{"before" "after" "around"})
@@ -2,8 +2,7 @@
midje.util.form-utils
(:use midje.clojure.core
[midje.util.treelike :only [tree-variant]]
- [midje.util.backwards-compatible-utils :only [every-pred-m]]
- [utilize.seq :only (first-truthy-fn)])
+ [utilize.seq :only (first-truthy-fn)])
(:require [clojure.zip :as zip]))
@@ -1,7 +1,7 @@
(ns ^{:doc "To evaluate a fact it needs to be eagerly evaluated."}
midje.util.laziness
- (:use [midje.util.form-utils :only [pred-cond]]
- [midje.util.backwards-compatible-utils :only [some-fn-m]]))
+ (:use [midje.clojure.core])
+ (:use [midje.util.form-utils :only [pred-cond]]))
(defn eagerly
"Descend form, converting all lazy seqs into lists.

0 comments on commit 155daec

Please sign in to comment.