Permalink
Browse files

[Issue #5] uses require/refer from old ns when present

  • Loading branch information...
1 parent 0db667d commit 79a1c9b51c5c926adbcc42fa48a1c6df88f0477e Alex Baranosky committed Dec 24, 2012
Showing with 34 additions and 11 deletions.
  1. +2 −1 project.clj
  2. +8 −7 src/slam/hound/regrow.clj
  3. +2 −2 test/slam/hound/regrow_test.clj
  4. +22 −1 test/slam/hound_test.clj
View
@@ -3,7 +3,8 @@
:plugins [[lein-swank "1.4.4"]]
:dependencies [[org.clojure/clojure "1.4.0"]]
:dev-dependencies [[org.clojure/tools.trace "0.7.3"]
- [org.clojars.runa/clj-schema "0.7.0"]]
+ [org.clojars.runa/clj-schema "0.7.0"]
+ [korma "0.3.0-beta11"]]
:test-selectors {:default (constantly true)
:integration :integration
:unit :unit})
View
@@ -81,26 +81,27 @@
(re-pattern (string/join "." (butlast (.split (name candidate) "\\."))))
(re-pattern (name (first candidate)))))
-(defn in-original-pred [original]
+(defn in-originals-pred [originals]
(fn [candidate]
- (re-find (butlast-regex candidate) (str original))))
+ (some #(re-find (butlast-regex candidate) (str %)) originals)))
(def ^:private disambiguator-blacklist
(if-let [v (resolve 'user/slamhound-disambiguator-blacklist)]
@v
#"swank|lancet"))
-(defn- new-type-to-old-type [new-type]
+(defn- new-type-to-old-types [new-type]
(case new-type
- :require-as :require
- :require-refer :use
- new-type))
+ :require-as [:require]
+ :require-refer [:require :use] ;; could've been require/refer or use/only
+ [new-type]))
(defn- disambiguate [candidates missing ns-map type]
;; TODO: prefer things in src/classes to jars
(debug :disambiguating missing :in candidates)
(->> candidates
- (sort-by (juxt (complement (in-original-pred ((new-type-to-old-type type) (:old ns-map))))
+ (sort-by (juxt (complement (in-originals-pred (map #(get (:old ns-map) %)
+ (new-type-to-old-types type))))
(comp count str)))
(remove #(re-find disambiguator-blacklist (str %)))
first))
@@ -1,6 +1,6 @@
(ns slam.hound.regrow-test
(:require [clojure.test :refer [deftest is testing]]
- [slam.hound.regrow :refer [regrow in-original-pred]]))
+ [slam.hound.regrow :refer [regrow in-originals-pred]]))
(def sample-body
@@ -49,7 +49,7 @@
(deftest ^:unit test-grow-preserve
- (let [in-orig? (in-original-pred '((java.util Date UUID)))]
+ (let [in-orig? (in-originals-pred ['((java.util Date UUID))])]
(is (in-orig? 'java.util.Date))
(is (not (in-orig? 'java.sql.Date))))
(is (= '(java.io.File java.util.Date)
View
@@ -1,5 +1,5 @@
(ns slam.hound-test
- (:require [clojure.test :refer [deftest is]]
+ (:require [clojure.test :refer [deftest is testing]]
[slam.hound :refer [reconstruct]])
(:import java.io.StringReader))
@@ -56,3 +56,24 @@
(:require [clj-schema.validation :as val]))
'#{:x {:a (val/validation-errors [[:name] String] {:name "Bob"})}}))))))
+(deftest ^:integration test-prefers-requires-as-clauses-from-orig-ns
+ ;; korma.core is on the :dev-dependencies, and was getting erroneously picked for
+ ;; these 2 namespaces
+ (testing "original ns has a require/refer"
+ (is (= "(ns foo.bar
+ (:require [clojure.string :refer [join]]))
+"
+ (reconstruct (StringReader. (str '(ns foo.bar
+ (:require [clojure.string :refer [join]]))
+ '(defn do-it! []
+ (join "," ["a" "b" "c"]))))))))
+
+ (testing "original ns has a use/only"
+ (is (= "(ns foo.bar
+ (:require [clojure.string :refer [join]]))
+"
+ (reconstruct (StringReader. (str '(ns foo.bar
+ (:use [clojure.string :only [join]]))
+ '(defn do-it! []
+ (join "," ["a" "b" "c"])))))))))
+

0 comments on commit 79a1c9b

Please sign in to comment.