stevearc / overseer.nvim

A task runner and job management plugin for Neovim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bug: shell escape single quote

AbaoFromCUG opened this issue · comments

commented

Neovim version (nvim -v)

NVIM v0.10.0-dev

Operating system/version

Linux

Describe the bug

Issue

I am using overseer.nvim+toggleterm.nvim+neotest+neotest-plenary, and writing test for my neovim plugin.

I write xxx_spec.lua and run it via :lua require("neotest").run.run(vim.fn.expand("%")) but failed with error zsh: parse error near `)' , here is the output of toggleterm terminal window

$ /usr/bin/nvim --headless -i NONE -n --noplugin --cmd 'lua vim.opt.runtimepath:prepend(\'/home/abao/.local/share/nvim/lazy/plenary.nvim\')' --cmd 'lua package.path = \'lua/?.lua;\' .. \'lua/?/init.lua;\' .. package.path' -u tests/minimal_init.lua -c 'source /home/abao/.local/share/nvim/lazy/neotest-plenary/run_tests.lua' -c 'lua _run_tests({results = \'/tmp/nvim.abao/9WCB57/3\', file = \'/home/abao/Documents/plugins/websocket.nvim/tests/websocket/websocket_spec.lua\', filter = {}})'
zsh: parse error near `)'
$ exit $?

What is the severity of this bug?

breaking (some functionality is broken)

Steps To Reproduce

  1. nvim -u repro.lua xxx_spec.lua
  2. :lua require("neotest").run.run(vim.fn.expand("%"))

Expected Behavior

I guess this is a issue of escaping a single quoted string. There is a question in stackoverflow https://stackoverflow.com/questions/1250079/how-to-escape-single-quotes-within-single-quoted-strings

Here are two solutions:

Support escape single quoted

Should we add a test case in tests/shell_spec.lua?

      it("Escape a single quoted string", function()
        local got = shell.escape_cmd({ "foo", "baz 'qux'" }, "strong")
        assert.equals("?", got)
      end)

Change escape method to weak (double quote)

or change shell.escape_cmd method of lua/overseer/strategy/toggleterm.lua to weak to avoid this issue

if type(cmd) == "table" then
cmd = shell.escape_cmd(cmd, "strong")
end

Minimal example file

-- xxx_spec.lua
describe("test", function()
	it("code", function() end)
end)

Minimal init.lua

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
	vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
	vim.fn.system({
		"git",
		"clone",
		"--filter=blob:none",
		"--single-branch",
		"https://github.com/folke/lazy.nvim.git",
		lazypath,
	})
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
	"folke/tokyonight.nvim",
	{ "stevearc/dressing.nvim", config = true },
	{
		"stevearc/overseer.nvim",
		config = function()
			require("overseer").setup({
				-- add your overseer config here
			})
		end,
	},
	-- add any other plugins here
	{
		"stevearc/overseer.nvim",
		config = function()
			require("overseer").setup({
				templates = { "builtin" },
				strategy = {
					"toggleterm",
					direction = "float",
                    shell="bash",
					use_shell = true,
				},
			})
		end,
	},
	{
		"nvim-neotest/neotest",
		dependencies = {
			"nvim-neotest/nvim-nio",
			"nvim-lua/plenary.nvim",
			"nvim-treesitter/nvim-treesitter",
		},
		config = function()
			require("neotest").setup({
				adapters = {
					require("neotest-plenary"),
				},
				consumers = {
					overseer = require("neotest.consumers.overseer"),
				},
			})
		end,
	},
    { "akinsho/toggleterm.nvim", opts = {} },
	"nvim-neotest/neotest-plenary",
}
require("lazy").setup(plugins, {
	root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here

Additional context

Thanks

Can you give #308 a try and see if it fixes your issue?