diff --git a/src/potemkin/namespace.clj b/src/potemkin/namespace.clj index 6577041..9687f8d 100644 --- a/src/potemkin/namespace.clj +++ b/src/potemkin/namespace.clj @@ -17,15 +17,15 @@ n (:name m) arglists (:arglists m) doc (:doc m)] - `(do - (def ~n - ~(eval sym)) + #_`(do + (def ~n ~(ns-resolve (:ns m) (:name m))) (alter-meta! ~(list 'var n) assoc :doc ~doc - :arglists '~arglists + :arglists ~(list 'quote arglists) :file ~(:file m) :line ~(:line m)) - ~(list 'var n)))) + ~(list 'var n)) + (list `def (with-meta n {:doc doc :arglists (list 'quote arglists) :file (:file m) :line (:line m)}) (eval sym)))) (defmacro import-macro "Given a macro in another namespace, defines a macro with the same name in the @@ -39,11 +39,10 @@ doc (:doc m) args-sym (gensym "args")] `(do - (defmacro ~n + (defmacro ~(with-meta n {:arglists arglists}) [~'& ~args-sym] (list* ~sym ~args-sym)) (alter-meta! ~(list 'var n) assoc - :arglists '~arglists :doc ~doc :file ~(:file m) :line ~(:line m)) diff --git a/test/potemkin/test/namespace.clj b/test/potemkin/test/namespace.clj index e764f26..6d87681 100644 --- a/test/potemkin/test/namespace.clj +++ b/test/potemkin/test/namespace.clj @@ -12,11 +12,14 @@ clojure.test) (:require [clojure.repl :as repl] - [clojure.string :as str])) + [clojure.string :as str] + [potemkin.test.protocol :as p])) (import-macro #'repl/source) (import-macro #'repl/doc) (import-fn #'repl/find-doc) +(import-fn #'p/multi-arity) +(import-fn #'p/protocol-function) (defn drop-lines [n s] (->> s str/split-lines (drop n) (interpose "\n") (apply str))) @@ -25,7 +28,9 @@ `(= ~@(map (fn [x] `(with-out-str ~x)) args))) (defmacro rest-out= [& args] - `(= ~@(map (fn [x] `(drop-lines 2 (with-out-str ~x))) args))) + `(do + ;;(do ~@(map (fn [x] `(println (with-out-str ~x))) args)) + (= ~@(map (fn [x] `(drop-lines 2 (with-out-str ~x))) args)))) (deftest test-import-macro (is (out= (source repl/source) (source source))) @@ -33,6 +38,10 @@ (deftest test-import-fn (is (out= (source repl/find-doc) (source find-doc))) - (is (rest-out= (doc repl/find-doc) (doc find-doc)))) + (is (rest-out= (doc repl/find-doc) (doc find-doc))) + (is (out= (source p/multi-arity) (source multi-arity))) + (is (rest-out= (doc p/multi-arity) (doc multi-arity))) + (is (rest-out= (doc p/protocol-function) (doc protocol-function))) + ) diff --git a/test/potemkin/test/protocol.clj b/test/potemkin/test/protocol.clj new file mode 100644 index 0000000..3b67b3b --- /dev/null +++ b/test/potemkin/test/protocol.clj @@ -0,0 +1,9 @@ +(ns potemkin.test.protocol) + +(defn multi-arity + "Here is a doc-string." + ([x]) + ([x y])) + +(defprotocol TestProtocol + (protocol-function [x a b c] "This is a protocol function."))