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

package.moonpath is never updated which breaks Moonscript module requirements #719

Open
wauterboi opened this issue Apr 26, 2023 · 1 comment
Labels

Comments

@wauterboi
Copy link

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
@wauterboi
Copy link
Author

Temporary workaround

Create a helper Moonscript file containing:

package.moonpath = string.gsub package.path, '%.lua', '.moon'

Use --helper to point to the helper script.

@Tieske Tieske added the bug label Apr 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants