Skip to content

Commit

Permalink
Let doc find builtin macros
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunjay Cauligi committed Mar 15, 2021
1 parent f4545f0 commit bf6aa92
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
8 changes: 7 additions & 1 deletion hy/core/macros.hy
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,13 @@
Use ``require`` to make other macros available.
Use ``(help foo)`` instead for help with runtime objects."
`(help (.get __macros__ (mangle '~symbol) None)))
(setv symbol (str symbol))
(setv mangled (mangle symbol))
(setv builtins (gensym "builtins"))
`(do (import [builtins :as ~builtins])
(help (or (.get __macros__ ~mangled)
(.get (. ~builtins __macros__) ~mangled)
(raise (NameError f"macro {~symbol !r} is not defined"))))))


(defmacro cfor [f #* generator]
Expand Down
20 changes: 19 additions & 1 deletion tests/native_tests/core.hy
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

;;;; some simple helpers

(import pytest)

(defn assert-true [x]
(assert (= True x)))

Expand Down Expand Up @@ -699,6 +701,17 @@ result['y in globals'] = 'y' in globals()")
<p> Move along. (Nothing to see here.)</p>)))

(defn test-doc [capsys]
;; https://github.com/hylang/hy/issues/1970
;; Let's first make sure we can doc the builtin macros
;; before we create the user macros.
(doc doc)
(setv [out err] (.readouterr capsys))
(assert (in "Gets help for a macro function" out))

(doc "#@")
(setv [out err] (.readouterr capsys))
(assert (in "with-decorator tag macro" out))

(defmacro <-mangle-> []
"a fancy docstring"
'(+ 2 2))
Expand All @@ -716,7 +729,12 @@ result['y in globals'] = 'y' in globals()")
(doc "#pillgrums")
(setv [out err] (.readouterr capsys))
(assert (in "Look at the quality of that picture!" out))
(assert (empty? err)))
(assert (empty? err))

;; make sure doc raises an error instead of
;; presenting a default value help screen
(with [(pytest.raises NameError)]
(doc does-not-exist)))


(defn test-do-n []
Expand Down

0 comments on commit bf6aa92

Please sign in to comment.