Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

require-macros hook #398

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/fennel/specials.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,7 @@ modules in the compiler environment."
(let [(loader filename) (search-macro-module modname 1)]
(compiler.assert loader (.. modname " module not found.") ast)
(tset macro-loaded modname (loader modname filename))))
(utils.hook :require-macros ast scope)
;; if we're called from import-macros, return the modname, else add them
;; to scope directly
(if (= :import-macros (tostring (. ast 1)))
Expand Down
2 changes: 1 addition & 1 deletion test/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ local function testall(suites)
end

local suites = {"core", "mangling", "quoting", "bit", "fennelview", "parser",
"failures", "repl", "cli", "macro", "linter", "loops", "misc"}
"failures", "repl", "cli", "macro", "linter", "loops", "misc", "plugin"}

if(#arg == 0) then
local ok, err = pcall(testall, suites)
Expand Down
19 changes: 19 additions & 0 deletions test/plugin.fnl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(local fennel (require :fennel))
(local l (require :test.luaunit))

(var ran-require-macros false)

(local plugin
{:name :test-plugin
:version fennel.version
:require-macros (fn [ast scope]
(set ran-require-macros true))})

(local options {:plugins [plugin]})

(fn test-require-macros []
"Check require-macros hook is trigered"
(let [src "(import-macros m :test.macros)"]
(l.assertEquals ran-require-macros false)))

{: test-require-macros}