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

Help with busted, local-lua config 🙏 #17

Open
aaharr opened this issue Jul 16, 2024 · 8 comments
Open

Help with busted, local-lua config 🙏 #17

aaharr opened this issue Jul 16, 2024 · 8 comments

Comments

@aaharr
Copy link

aaharr commented Jul 16, 2024

Very much appreciate you targeting this use case (💯)

When I try to run busted tests, I get syntax errors seemingly from the busted executable. Just the sample busted test from the plenary docs, passes when running busted either via plenary or lua. Would love to be able to debug!

For every test:
E5112: Error while creating lua chunk: /usr/local/bin/busted:3: unexpected symbol near '-'

File is called test_spec.lua and there is an empty minimum_init.spec in the same directory. Plenary seems to be picking it up, but only since I named it test_spec.lua.

            -- Local Lua DAP
            -- https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation#local-lua-debugger-vscode
            dap.adapters["local-lua"] = {
                type = "executable",
                command = "node",
                args = {
                    "/home/aaron/local-lua-debugger-vscode/extension/debugAdapter.js",
                },
                enrich_config = function(config, on_config)
                    if not config["extensionPath"] then
                        local c = vim.deepcopy(config)
                        -- 💀 If this is missing or wrong you'll see
                        -- "module 'lldebugger' not found" errors in the dap-repl when trying to launch a debug session
                        c.extensionPath = "/home/aaron/local-lua-debugger-vscode/"
                        on_config(c)
                    else
                        on_config(config)
                    end
                end,
            }

            -- Local Lua Launch Config
            -- https://zignar.net/2023/06/10/debugging-lua-in-neovim/
            dap.configurations.lua = {
                {
                    name = "Launch file (local-lua)",
                    type = "local-lua",
                    request = "launch",
                    cwd = "${workspaceFolder}",
                    console = "integratedTerminal",
                    program = {
                        lua = "lua5.1",
                        file = "${file}",
                    },
                    args = {},
                },
            }
            -- Currently filetypes are not set for lua (why?), so you have to manually run
            -- :lua require('dap').run(require('dap').configurations.lua[1])
                adapters = {
                    -- require("neotest-plenary").setup({
                    --     -- min_init = ".minimal_init.lua",
                    -- }),
                    require("neotest-busted")({
                        -- Leave as nil to let neotest-busted automatically find busted
                        busted_command = "/usr/local/bin/busted",
                        -- Extra arguments to busted
                        -- busted_args = { "--shuffle-files" },
                        -- List of paths to add to package.path in neovim before running busted
                        -- busted_paths = { "my/custom/path/?.lua" },
                        -- List of paths to add to package.cpath in neovim before running busted
                        -- busted_cpaths = { "my/custom/path/?.so" },
                        -- Custom config to load via -u to set up testing.
                        -- If nil, will look for a 'minimal_init.lua' file
                        -- minimal_init = "custom_init.lua",
                    }),
                },

Hoping something jumps out at you!

@MisanthropicBit
Copy link
Owner

Thanks for the kind words, I'm glad people find it useful 🙂 the adapter is still under development so it really helps when people submit an issue. FYI, the minimal_init.lua file is only necessary if you need to load some test dependencies.

  • So running /usr/local/bin/busted test_spec.lua works but you are unable to run the tests via neotest inside the test file? Or is it only debugging that does not work?
  • How did you install busted?
  • What version of neovim and neotest are you using? The output of :checkhealth neotest-busted check for compatible versions.
  • Do you mean the first test file here? I can run the tests and debug them.
  • Unfortunately, nothing jumps out at me apart from the console = "integratedTerminal", line which shouldn't matter. Your setup looks pretty much identical to mine.
  • You can try to set the log_level to vim.log.levels.debug in the neotest.setup function and check the logs. Perhaps that will give you an idea of what goes wrong. It seems like the command created by neotest-busted might be wrong. Otherwise, insert a vim.print(vim.inspect(test_command)) in the get_strategy_config function.
  • Lastly, you could open the busted "executable" which should actually just be a bash script with a shebang. Line 3 would correspond with the line that invokes busted via luarocks exec which might somehow be incorrectly set up.

Hope that helps 🙂

@aaharr
Copy link
Author

aaharr commented Jul 17, 2024

It certainly helps to see your config and get a sanity check. Enjoying neotest ✅

  • Yes I can run that busted path and get expected output on $
  • Luarocks.. it shows busted 2.2.0-1, I just use the path from which busted
  • will take a look and edit Nvim version is 0.10.0
* neotest-busted ~
- OK has neovim 0.9.0+
- OK `neotest` is installed
- OK `nio` is installed
- OK found no errors in config
- OK found `busted` (type: config) at
  /usr/local/bin/busted
  • Yes that's the one
  • Cool, worth a try
  • I keep hoping someday my lua print statements will go to nvim-dap-ui's console widget or repl, but that is another story
  • In the logs I see quite a bit of this, but no explicit errors
<SNR>97_try_cmd returning ['LUAROCKS_SYSCONFDIR=''/usr/local/etc.../busted/2.2.0-1/bin/busted'' "$@"', '']
calling <SNR>97_try_cmd
<SNR>97_try_cmd returning ['LUAROCKS_SYSCONFDIR=''/usr/local/etc.../busted/2.2.0-1/bin/busted'' "$@"', '']
calling <SNR>97_try_cmd
<SNR>97_try_cmd returning ['LUAROCKS_SYSCONFDIR=''/usr/local/etc.../busted/2.2.0-1/bin/busted'' "$@"', '']
calling <SNR>97_try_cmd
<SNR>97_try_cmd returning ['_']
calling <SNR>97_try_cmd
<SNR>97_try_cmd returning ['_']
calling <SNR>97_try_cmd
<SNR>97_try_cmd returning ['_']
calling <SNR>97_try_cmd
<SNR>97_try_cmd returning ['_']
  • edit
    Looks like we're just using lua to run busted with some explicit paths in this bash command, and it is working from the cli. I do see a - or two
LUAROCKS_SYSCONFDIR='/usr/local/etc/luarocks' exec '/usr/bin/lua5.1' -e 'package.path="/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;"..package.path;package.cpath="/usr/local/lib/lua/5.1/?.so;"..package.cpath;local k,l,_=pcall(require,"luarocks.loader") _=k and l.add_context("busted","2.2.0-1")' '/usr/local/lib/luarocks/rocks-5.1/busted/2.2.0-1/bin/busted' "$@"

*edit - Command info from vim.inspect

{
  arguments = { "--headless", "-i", "NONE", "-n", "-u", "NONE", "-c", "lua package.path = 'lua/?.lua;lua/?/init.lua;' .. package.path", "-l", "/usr/local/bin/busted", "--verbose", "--output", "/home/aaron/.local/share/nvim/lazy/neotest-busted/lua/neotest-busted/output_handler.lua", "-Xoutput", "/tmp/nvim.aaron/XW7ip6/4.json", "--filter", '"Hello test some other test"', '"/home/aaron/plugins/myplugin/tests/test_spec.lua"', '"--helper"', '"/home/aaron/.local/share/nvim/lazy/neotest-busted/lua/neotest-busted/start_debug.lua"' },
  cpaths = {},
  nvim_command = "/usr/bin/nvim",
  paths = { "lua/?.lua", "lua/?/init.lua" }
}

That's pretty much what I thought as well. I will try these steps and get back. The voice in my head says "it's a path somewhere.. it's always a path!!" Thanks again

@MisanthropicBit
Copy link
Owner

Thanks for providing the additional info.

In the logs I see quite a bit of this, but no explicit errors

I don't have a single line in my logs (710886 lines) that mention the ...try_cmd thing. Perhaps it's related to neotest which uses vim.fn.jobstart for some stuff under the hood. I can't see the severity of those logs but I guess they are probably just reported as INFO.

Looks like we're just using lua to run busted with some explicit paths in this bash command, and it is working from the cli. I do see a - or two

Everything looks as expected and properly quoted (which might otherwise have meant that a '-' got misinterpreted) and nice that you can run it in the CLI.

*edit - Command info from vim.inspect

I noticed that the additional package.path setup is just lua/?.lua;lua/?/init.lua; (which is included by default) and that package.cpath isn't set up at all. When using a custom busted executable, neotest-busted does not set any additional paths which is why you only see the default ones. If you have a special installation of luarocks/busted that isn't covered by neotest-busted, the paths won't be set up because neotest-busted doesn't know where to look. You can try providing them via busted_paths and busted_cpaths in the setup function.

Do you have an installation in ~/.luarocks (you can also try luarocks list busted)? Neotest-busted should emit debug-level logs about which one it found. You could try to do a directory-local install and see if that setup works since you might have an installation setup that neotest-busted isn't accounting for.

@aaharr
Copy link
Author

aaharr commented Jul 20, 2024

Thanks @MisanthropicBit for the info and ideas.

Seems like it will take me some time to step through the config combinations and get back. Feel free to close if you need to until then 👍

@MisanthropicBit
Copy link
Owner

MisanthropicBit commented Jul 21, 2024

No problem 🙂 Let's keep this issue open for now until it's confirmed whether this is a bug in neotest-busted, a new feature is needed, or something else.

I've added a warning box about the consequences of setting busted_command in another PR for future reference.

@MisanthropicBit
Copy link
Owner

Hey @aaharr. Did you get a chance to look at the config combinations?

@aaharr
Copy link
Author

aaharr commented Oct 17, 2024

@MisanthropicBit No.. my Lua flow has been pretty ad hoc. I'm not sure when I'll finally get to TDD my half-finished plugins 🥲

@MisanthropicBit
Copy link
Owner

No worries, just wanted to follow up on it 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants