Permalink
Browse files

switch to clojure-1.3 compatible dependencies.

this still breaks a couple of tests on clojure.contrib.mock
and some other stuff that needs looking at.
  • Loading branch information...
1 parent 20f17b6 commit 05081f66329053744f147d878935a69b337db446 @joodie committed Nov 22, 2011
View
@@ -1,4 +1,6 @@
(defproject joodie/clojure-refactoring "0.6.5-SNAPSHOT"
:description "Clojure refactoring for Emacs/SLIME"
:dependencies [[org.clojure/clojure "1.3.0"]
- [net.cgrand/parsley "0.8.0"]])
+ [net.cgrand/parsley "0.8.0"]
+ [org.clojure/tools.namespace "0.1.1"]]
+ :dev-dependencies [[org.clojure.contrib/mock "1.3.0-alpha4"]])
@@ -28,10 +28,9 @@
(ns clojure-refactoring.ast
(:refer-clojure
:exclude [symbol symbol? keyword? list vector newline conj])
- (:use [clojure.contrib.seq-utils :only [find-first]]
- [clojure.contrib.str-utils :only [str-join]]
- [clojure-refactoring.support.core :exclude [sub-nodes tree-contains?]])
+ (:use [clojure-refactoring.support.core :exclude [sub-nodes tree-contains?]])
(:require [clojure.core :as core]
+ [clojure.string :as str]
[clojure-refactoring.support.parser :as parser])
(:import net.cgrand.parsley.Node))
@@ -104,7 +103,7 @@
(tree-replace (symbol old) (symbol new) ast))
(defn ast->string [ast]
- (str-join "" (filter string? (sub-nodes ast))))
+ (str/join "" (filter string? (sub-nodes ast))))
(def sexp->parsley (comp parser/parse1 format-code))
@@ -120,7 +119,7 @@
(tag= :atom ast))
(defn- ast-content [ast]
- (str-join "" (:content ast)))
+ (str/join "" (:content ast)))
(def symbol?
(all-of? map? parsley-atom?
@@ -163,7 +162,7 @@
(def newline (make-node :whitespace '("\n")))
(defn first-vector [ast]
- (find-first (tag= :vector) (:content ast)))
+ (first (filter (tag= :vector) (:content ast))))
(defn parsley-fn-args [ast]
(first-vector (parsley-get-first-node ast)))
@@ -28,7 +28,7 @@
(ns clojure-refactoring.ast.zip
(:require [clojure.zip :as zip]))
-(clojure.contrib.def/defalias ast-zip zip/xml-zip)
+(def ast-zip zip/xml-zip)
(defn find-node [zipped-ast node]
"Given a zipped ast, returns the loc of the first occurrence of node
@@ -28,10 +28,9 @@
(ns clojure-refactoring.destructuring
(:use [clojure.walk]
[clojure-refactoring.support core]
- [clojure.contrib.seq-utils :only [find-first]]
- [clojure.contrib.str-utils :only [str-join]]
[clojure-refactoring.ast :only [defparsed-fn]])
- (:require [clojure-refactoring.ast :as ast]))
+ (:require [clojure-refactoring.ast :as ast]
+ [clojure.string :as str]))
(defn map-lookup? [ast]
(let [content (ast/relevant-content ast)]
@@ -42,7 +41,7 @@
(defn key->sym [kw-node]
(ast/replace-content kw-node
(list
- (str-join ""
+ (str/join ""
(drop 1 (first (:content kw-node)))))))
(defn find-lookups [node]
@@ -29,8 +29,7 @@
(ns clojure-refactoring.extract-method
(:use [clojure-refactoring.support core formatter find-bindings-above-node]
[clojure-refactoring.ast :only [defparsed-fn]]
- [clojure.set]
- [clojure.contrib.seq-utils :only [find-first]])
+ [clojure.set])
(:require [clojure-refactoring.ast :as ast]))
(defn- find-occurences [args node]
@@ -28,12 +28,11 @@
(ns clojure-refactoring.local-binding
(:use clojure.walk
[clojure-refactoring.support core formatter]
- [clojure.contrib.seq-utils :only (find-first)]
[clojure-refactoring.ast :only [defparsed-fn]])
(:require [clojure-refactoring.ast :as ast]))
(defn- get-function-definition [defn-ast]
- (find-first (ast/tag= :list) (:content defn-ast)))
+ (first (filter (ast/tag= :list) (:content defn-ast))))
(defn- add-to-binding [{content :content :as binding-node}
value var-name]
@@ -26,7 +26,7 @@
;; OF THE POSSIBILITY OF SUCH DAMAGE.
(ns clojure-refactoring.support.source
- (:use [clojure.contrib.find-namespaces :only [find-namespaces-in-dir]]
+ (:use [clojure.tools.namespace :only [find-namespaces-in-dir]]
[clojure-refactoring.support core paths])
(:require [clojure-refactoring.support.parser :as parser])
(:import java.io.File))
@@ -51,6 +51,10 @@
;; Time is the time this cache entry was created, parsley is the
;; result of calling parsley after slurping the file
+(defn mk-cache-entry
+ [time parsley namespace]
+ (NameSpaceCacheEntry. time parsley namespace))
+
(defn new-ns-entry [namespace]
(let [f (filename-from-ns namespace)
parsed (parser/parse (slurp f))]
@@ -1,6 +1,5 @@
(ns clojure-refactoring.rename-test
- (:use clojure.test
- clojure.contrib.mock)
+ (:use clojure.test)
(:require [clojure-refactoring.ast :as ast])
(:require [clojure-refactoring.support.parser :as parser])
(:use clojure-refactoring.rename :reload))
@@ -12,7 +12,7 @@
(deftest filename_from_ns
(let [path "clojure_refactoring/support/namespaces.clj"]
- (know "calls slime find file with a munged path"
+ (fact "calls slime find file with a munged path"
(is (= (filename-from-ns
'clojure-refactoring.support.namespaces)
path))
@@ -20,6 +20,7 @@
(defn replacement-map-for-tests []
(build-replacement-map 'a replace-test-fn))
+
(deftest build_replacement_map
(testing "populates the attributes correctly"
(expect [parsley-from-cache (returns (parser/parse "(+ a 1)"))
@@ -1,10 +1,10 @@
(ns clojure-refactoring.support.source-test
- (:use clojure-refactoring.support.source :reload)
- (:import clojure-refactoring.support.source.NameSpaceCacheEntry)
+ (:use clojure-refactoring.support.source :reload)
(:use clojure-refactoring.test-helpers
clojure-refactoring.support.paths
clojure.test
clojure.contrib.mock)
+
(:require [clojure-refactoring.support replace replace-test])
(:require [clojure-refactoring.support.parser :as parser]))
@@ -13,7 +13,7 @@
(def a nil) ;; used to test does-ns-refer-to-var? below.
(def cache-with-one-entry (atom {'a
- (NameSpaceCacheEntry. 0 (parser/parse "(+ 1 2)") 'a)}))
+ (mk-cache-entry 0 (parser/parse "(+ 1 2)") 'a)}))
(defn test-entry-from-cache []
(parsley-from-cache 'a))
@@ -42,7 +42,7 @@
new-ns-entry (times 1)]))))
(deftest namespaces_who_refer_to
- (know "it requires all the namespaces in the user dir"
+ (fact "it requires all the namespaces in the user dir"
(doall (namespaces-who-refer-to 'b))
(provided
[find-ns-in-user-dir (returns '[a])
@@ -1,12 +1,37 @@
(ns clojure-refactoring.test-helpers
(:use clojure.test
- [clojure.contrib.def :only [defalias]]
clojure.contrib.mock)
(:require [clojurecheck.core :as cc])
- (:require [clojure.contrib.repl-utils :as repl-utils]))
+ (:import (java.io File LineNumberReader InputStreamReader PushbackReader)
+ (java.lang.reflect Modifier Method Constructor)
+ (clojure.lang RT Compiler Compiler$C)))
+
+;; from clojure.contrib.repl-utils
+(defn get-source
+ "Returns a string of the source code for the given symbol, if it can
+ find it. This requires that the symbol resolve to a Var defined in
+ a namespace for which the .clj is in the classpath. Returns nil if
+ it can't find the source. For most REPL usage, 'source' is more
+ convenient.
+
+ Example: (get-source 'filter)"
+ {:deprecated "1.2"}
+ [x]
+ (when-let [v (resolve x)]
+ (when-let [filepath (:file (meta v))]
+ (when-let [strm (.getResourceAsStream (RT/baseLoader) filepath)]
+ (with-open [rdr (LineNumberReader. (InputStreamReader. strm))]
+ (dotimes [_ (dec (:line (meta v)))] (.readLine rdr))
+ (let [text (StringBuilder.)
+ pbr (proxy [PushbackReader] [rdr]
+ (read [] (let [i (proxy-super read)]
+ (.append text (char i))
+ i)))]
+ (read (PushbackReader. pbr))
+ (str text)))))))
(defonce memoized-get-source
- (memoize repl-utils/get-source))
+ (memoize get-source))
(def symbol-chars (vec "abcdefghijklmnopqrstuvwxyz"))
@@ -28,7 +53,9 @@
(proxy [java.io.File] ["~/"] (lastModified [] time)
(getCanonicalPath [] "absolute-path")))
-(defalias prop cc/property)
+(defmacro prop
+ [& args]
+ `(cc/property ~@args))
(defmacro modified? [reference & exprs]
"Checks if a reference is modified whilst running exprs.
@@ -44,6 +71,3 @@
`(expect ~(second provided)
~test))
-(defalias know fact)
-
-(defalias with binding)
@@ -1,7 +1,7 @@
(ns clojure-refactoring.thread-expression-test
(:use clojure-refactoring.thread-expression :reload)
(:use [clojure-refactoring.support core formatter]
- clojure.test clojure.contrib.str-utils))
+ [clojure.test]))
(use-fixtures :once #(time (%)))
View
@@ -1,12 +1,3 @@
-;; (when (= (class clojure.test/report) clojure.lang.MultiFn)
-;; (eval
-;; '(do (require 'clojure.test)
-;; (ns clojure.test)
-;; (def old-report clojure.test/report))))
-
-(ns clojure-refactoring.test.clojurecheck.core
- (:use [clojure.test]))
-
; Copyright 2010 © Meikel Brandmeyer.
; All rights reserved.
@@ -29,8 +20,9 @@
; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
; DEALINGS IN THE SOFTWARE.
-(ns ^{:author "Meikel Brandmeyer"
- :doc
+(ns clojurecheck.core
+ {:author "Meikel Brandmeyer"
+ :doc
"clojurecheck - property based testing
clojurecheck is an extensions to clojure.test. It provides generators
@@ -81,7 +73,6 @@
Ran 2 tests containing 7 assertions.
1 failures, 0 errors.
{:type :summary, :test 2, :pass 6, :fail 1, :error 0}"}
- clojurecheck.core
(:refer-clojure
:exclude (int float list vec set sorted-set hash-map sorted-map))
(:use clojure.test))
@@ -188,9 +179,8 @@
available to the following generator definitions."
{:added "2.0"}
[bindings & body]
- (@#'clojure.core/assert-args let-gen
- (vector? bindings) "a vector for its bindings"
- (even? (count bindings)) "an even number of forms in the bindings vector")
+ (assert (vector? bindings))
+ (assert (even? (count bindings)))
(let [size (gensym "size__")
emit-g (fn [[local gen] body]
`(let ~[local (clojure.core/list gen size)]
@@ -325,7 +315,7 @@
(/ (inc n) 2)))
(defn property*
- "The property* driver handles the work when testing a property. It
+ "The probperty* driver handles the work when testing a property. It
expects:
* a descriptive message for failure reporting
* a list of locals (also for reporting)
@@ -342,9 +332,17 @@
(if (< trials n)
(report {:type :pass})
(let [input (-> n size-scale gen)]
- (try
- (binding [report report-fn]
- (prop input))
+ (if-let [err (try (binding [report report-fn]
+ (prop input)
+ nil)
+ (catch Throwable t
+ t))]
+ (report {:type ::property-error
+ :message msg
+ :locals locals
+ :input input
+ :attempt n
+ :error err})
(let [failures (filter #(-> % :type (not= :pass)) @results)]
(if (seq failures)
(report {:type ::property-fail
@@ -353,14 +351,7 @@
:input input
:attempts n
:failures failures})
- (recur (inc n))))
- (catch Throwable t
- (report {:type ::property-error
- :message msg
- :locals locals
- :input input
- :attempt n
- :error t}))))))))
+ (recur (inc n))))))))))
(defmacro property
"Defines a property consisting of a binding vector as for let-gen
@@ -376,6 +367,8 @@
(let-gen ~bindings [~@locals])
(fn [[~@locals]] ~@body))))
+(defmulti old-report class)
+
(defmethod old-report ::property-fail
[{:keys [message locals input attempts failures] :as m}]
(with-test-out

0 comments on commit 05081f6

Please sign in to comment.