Skip to content

Commit

Permalink
Make backwards-compatibility functions automatically available.
Browse files Browse the repository at this point in the history
  • Loading branch information
marick committed Jan 26, 2013
1 parent 0be7a0f commit 155daec
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 22 deletions.
1 change: 0 additions & 1 deletion src/midje/checking/checkers/collection.clj
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/midje/checking/checkers/combining.clj
Expand Up @@ -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]
Expand Down
1 change: 0 additions & 1 deletion src/midje/checking/checkers/simple.clj
Expand Up @@ -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]))

Expand Down
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)))
7 changes: 6 additions & 1 deletion src/midje/clojure/core.clj
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
3 changes: 1 addition & 2 deletions src/midje/data/project_state.clj
Expand Up @@ -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+

Expand Down
3 changes: 1 addition & 2 deletions src/midje/error_handling/background_validations.clj
Expand Up @@ -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"})
Expand Down
3 changes: 1 addition & 2 deletions src/midje/util/form_utils.clj
Expand Up @@ -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]))


Expand Down
4 changes: 2 additions & 2 deletions src/midje/util/laziness.clj
@@ -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.
Expand Down

0 comments on commit 155daec

Please sign in to comment.