LuaLS / lua-language-server

A language server that offers Lua language support - programmed in Lua
https://luals.github.io
MIT License
3.36k stars 320 forks source link

`luamake test` doesn't find packages #2855

Open sparr opened 2 months ago

sparr commented 2 months ago

How are you using the lua-language-server?

Command Line

Which OS are you using?

MacOS

What is the issue affecting?

Other

Expected Behaviour

luamake test runs the same tests with the same results as luamake rebuild

Actual Behaviour

luamake rebuild works.

luamake test can't find packages:

module 'log' not found:
        no field package.preload['log']
        no file 'log.lua'
        no file 'log/init.lua'
        no file './test/log.lua'
        no file './test/log/init.lua'
        no file 'log.so'
        no file 'build/bin/log.so'
stack traceback:
        /Users/sparr/src/lua-language-server/test.lua:20: in main chunk

Updating package.path to point to the log module leads to another failed package load, then multiple additions to package.path to find more modules, eventually leading to needing to compile lpeglabel.so manually, then a dead end when I couldn't figure out how to resolve this one (note the new paths being searched from all the additions I made to package.path to get this far)

module 'luamake' not found:
        no field package.preload['luamake']
        no file 'luamake.lua'
        no file 'luamake/init.lua'
        no file './test/luamake.lua'
        no file './test/luamake/init.lua'
        no file './script/luamake.lua'
        no file './script/luamake/init.lua'
        no file './test/plugins/ffi/luamake.lua'
        no file './make/luamake.lua'
        no file 'luamake.so'
        no file 'build/bin/luamake.so'
stack traceback:
        ...rs/clarence/src/lua-language-server/make/code_format.lua:1: in main chunk
        ...e/src/lua-language-server/script/provider/formatting.lua:1: in main chunk
        ...e/src/lua-language-server/script/provider/capability.lua:8: in main chunk
        ...nce/src/lua-language-server/script/provider/provider.lua:2: in main chunk
        /Users/clarence/src/lua-language-server/script/lclient.lua:11: in main chunk
        /Users/clarence/src/lua-language-server/test.lua:82: in local 'main'
        /Users/clarence/src/lua-language-server/test.lua:119: in main chunk

Reproduction steps

  1. Run 3rd/luamake/luamake rebuild
  2. Run 3rd/luamake/luamake test

Additional Notes

No response

Log File

No response

tomlau10 commented 2 months ago

3rd/luamake/luamake test is not the way to run the test. From the readme here: https://github.com/actboy168/luamake/blob/master/README.md#commands

luamake test Equivalent to luamake lua test.lua

which is just running any lua file (in this case test.lua) in your current directory (i.e. the test.lua in luals repo's root).


But this file should not be run by luamake, it should be run by the ./bin/lua-language-server binary. You can verify this by looking into the launch.json: https://github.com/LuaLS/lua-language-server/blob/66141703b3dcd3c94d815ab275638cad443e0dd8/.vscode/launch.json#L6-L11


In any case, I think the readme of luals should be updated to reflect this. πŸ€” Or need to request some change to luals's wiki page repo: https://github.com/LuaLS/LuaLS.github.io

tomlau10 commented 2 months ago

Seems I have some misunderstanding on this πŸ˜• , I do found a test command inside 3rd/luamake: https://github.com/actboy168/luamake/blob/master/scripts/command/test.lua

Maybe really luamake test isn't working properly πŸ€”

sparr commented 2 months ago

Thanks for the insights. Running luamake on its own runs the bee tests and the test.lua tests, which is useful. And bin/lua-language-server test.lua runs the test.lua tests as well. These will certainly help me test things faster. If no one comes up with an explanation or fix for using luamake to run test.lua when I'll PR a change to the README soon.

tomlau10 commented 2 months ago

Some further analysis, I think the make.lua is used when invoking 3rd/luamake/luamake πŸ‘€


luamake test is completely another thing, it's a luamake command that runs a test.lua directly. (just like build / rebuild, which are commands of luamake). I guess it assumes the test.lua is some generic lua script without dependencies. But it's not the case in luals because the test.lua depends on some specific require paths that set by bin/lua-language-server itself, so it cannot be run by luamake directly => need to wrap it as a unit-test rule, as done in the current make.lua configuration

sparr commented 2 months ago

luamake alone will also do a build if your code has changed or you did luamake clean previously. It seems like the contents of make.lua provide additional instructions for luamake, but it also provides some of its own functionality such as building by default and taking the rebuild parameter.

So, it seems like luamake unit-test is what I was looking for. Thanks! I'll keep this issue open until I or someone else PR's an update to the docs.