Skip to content

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

Open
@wauterboi

Description

@wauterboi

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions