aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStuart Halloway <stu@thinkrelevance.com>2010-05-06 18:12:36 -0400
committerStuart Halloway <stu@thinkrelevance.com>2010-05-06 18:12:36 -0400
commit1c805bd0e515ea57028721ea54e6db4b0c791e20 (patch)
tree636ddb11137c8848050f994ac3c907c9ca191327
parent95dddbbdd748b0cc6d9c8486b8388836e6418848 (diff)
hack for #82, very ugly
-rw-r--r--src/main/clojure/clojure/contrib/def.clj6
-rw-r--r--src/test/clojure/clojure/contrib/test_def.clj27
2 files changed, 31 insertions, 2 deletions
diff --git a/src/main/clojure/clojure/contrib/def.clj b/src/main/clojure/clojure/contrib/def.clj
index cc3eef75..08274cec 100644
--- a/src/main/clojure/clojure/contrib/def.clj
+++ b/src/main/clojure/clojure/contrib/def.clj
@@ -73,8 +73,10 @@ making private definitions more succinct."}
(if (.hasRoot (var ~orig))
(def ~name (.getRoot (var ~orig)))
(def ~name))
- conj
- (apply dissoc (meta (var ~orig)) (keys (meta (var ~name)))))
+ ;; When copying metadata, disregard {:macro false}.
+ ;; Workaround for http://www.assembla.com/spaces/clojure/tickets/273
+ #(conj (dissoc % :macro)
+ (apply dissoc (meta (var ~orig)) (remove #{:macro} (keys %)))))
(var ~name)))
([name orig doc]
(list `defalias (with-meta name (assoc (meta name) :doc doc)) orig)))
diff --git a/src/test/clojure/clojure/contrib/test_def.clj b/src/test/clojure/clojure/contrib/test_def.clj
new file mode 100644
index 00000000..2e8af137
--- /dev/null
+++ b/src/test/clojure/clojure/contrib/test_def.clj
@@ -0,0 +1,27 @@
+;; Tests for def.clj
+
+;; by Stuart Halloway
+
+;; Copyright (c) Stuart Halloway, 2009. All rights reserved. The use
+;; and distribution terms for this software are covered by the Eclipse
+;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
+;; which can be found in the file epl-v10.html at the root of this
+;; distribution. By using this software in any fashion, you are
+;; agreeing to be bound by the terms of this license. You must not
+;; remove this notice, or any other, from this software.
+
+(ns clojure.contrib.test-def
+ (:use clojure.test)
+ (:require [clojure.contrib.def :as d]))
+
+(defn sample-fn "sample-fn docstring" [])
+(d/defalias aliased-fn sample-fn)
+(defmacro sample-macro "sample-macro-docstring" [])
+(d/defalias aliased-macro sample-macro)
+
+(deftest defalias-preserves-metadata
+ (let [preserved-meta #(-> % (meta) (select-keys [:doc :arglists :ns :file :macro]))]
+ (are [x y] (= (preserved-meta (var x)) (preserved-meta (var y)))
+ aliased-fn sample-fn
+ aliased-macro sample-macro)))
+