`package.moonpath` is never updated which breaks Moonscript module requirements
wauterboi opened this issue · 1 comments
If you create a Moonscript spec file, the spec itself works fine. With that said, if you attempt to require a Moonscript file from inside the spec file, it doesn't take into account the value of either the command flag -m
/--lpath
, or the cooresponding .busted
keyvalue.
When trying to diagnose the issue with @leafo, we came to the conclusion that busted is initializing the Moonscript loader before modifying package.path
. As Moonscript is initialized with the older value, it needs to be updated to take into account the other search paths set by busted. Failing to do this means package.moonpath
defaults to whatever is assigned to the environment variable LUA_PATH
, which is unexpected behavior.
For demonstration, you can throw this in a Moonscript spec file and compare:
spec/moon_spec.moon
:
print 'package.path:\n\t' .. string.gsub(package.path, ';', '\n\t')
print 'package.moonpath:\n\t' .. string.gsub(package.moonpath, ';', '\n\t')
Output
package.path:
./src/?.lua
./src/?/?.lua
./src/?/init.lua
/home/theis/.luarocks/share/lua/5.1/?.lua
/home/theis/.luarocks/share/lua/5.1/?/init.lua
./?.lua
/usr/local/share/lua/5.1/?.lua
/usr/local/share/lua/5.1/?/init.lua
/usr/local/lib/lua/5.1/?.lua
/usr/local/lib/lua/5.1/?/init.lua
/usr/share/lua/5.1/?.lua
/usr/share/lua/5.1/?/init.lua
package.moonpath:
/home/theis/.luarocks/share/lua/5.1/?.moon
/home/theis/.luarocks/share/lua/5.1/?/init.moon
./?.moon
/usr/local/share/lua/5.1/?.moon
/usr/local/share/lua/5.1/?/init.moon
/usr/local/lib/lua/5.1/?.moon
/usr/local/lib/lua/5.1/?/init.moon
/usr/share/lua/5.1/?.moon
/usr/share/lua/5.1/?/init.moon
Temporary workaround
Create a helper Moonscript file containing:
package.moonpath = string.gsub package.path, '%.lua', '.moon'
Use --helper
to point to the helper script.