Update generated neovim config
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
#!/nix/store/4bj2kxdm1462fzcc2i2s4dn33g2angcc-bash-5.2p32/bin/bash
|
||||
#!/nix/store/izpf49b74i15pcr9708s3xdwyqs4jxwl-bash-5.2p32/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
require("plenary.async").tests.add_to_env()
|
||||
local conform = require("conform")
|
||||
local fs = require("conform.fs")
|
||||
local runner = require("conform.runner")
|
||||
local test_util = require("tests.test_util")
|
||||
local util = require("conform.util")
|
||||
@ -121,7 +122,7 @@ describe("runner", function()
|
||||
local config = assert(conform.get_formatter_config("test"))
|
||||
local ctx = runner.build_context(0, config)
|
||||
local cmd = runner.build_cmd("", ctx, config)
|
||||
assert.are.same({ "echo", vim.api.nvim_buf_get_name(bufnr) }, cmd)
|
||||
assert.are.same({ vim.fn.exepath("echo"), vim.api.nvim_buf_get_name(bufnr) }, cmd)
|
||||
end)
|
||||
|
||||
it("replaces $DIRNAME in args", function()
|
||||
@ -135,7 +136,10 @@ describe("runner", function()
|
||||
local config = assert(conform.get_formatter_config("test"))
|
||||
local ctx = runner.build_context(0, config)
|
||||
local cmd = runner.build_cmd("", ctx, config)
|
||||
assert.are.same({ "echo", vim.fs.dirname(vim.api.nvim_buf_get_name(bufnr)) }, cmd)
|
||||
assert.are.same(
|
||||
{ vim.fn.exepath("echo"), vim.fs.dirname(vim.api.nvim_buf_get_name(bufnr)) },
|
||||
cmd
|
||||
)
|
||||
end)
|
||||
|
||||
it("resolves arg function", function()
|
||||
@ -150,35 +154,7 @@ describe("runner", function()
|
||||
local config = assert(conform.get_formatter_config("test"))
|
||||
local ctx = runner.build_context(0, config)
|
||||
local cmd = runner.build_cmd("", ctx, config)
|
||||
assert.are.same({ "echo", "--stdin" }, cmd)
|
||||
end)
|
||||
|
||||
it("replaces $FILENAME in string args", function()
|
||||
vim.cmd.edit({ args = { "README.md" } })
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
conform.formatters.test = {
|
||||
meta = { url = "", description = "" },
|
||||
command = "echo",
|
||||
args = "$FILENAME | patch",
|
||||
}
|
||||
local config = assert(conform.get_formatter_config("test"))
|
||||
local ctx = runner.build_context(0, config)
|
||||
local cmd = runner.build_cmd("", ctx, config)
|
||||
assert.equal("echo " .. vim.api.nvim_buf_get_name(bufnr) .. " | patch", cmd)
|
||||
end)
|
||||
|
||||
it("replaces $DIRNAME in string args", function()
|
||||
vim.cmd.edit({ args = { "README.md" } })
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
conform.formatters.test = {
|
||||
meta = { url = "", description = "" },
|
||||
command = "echo",
|
||||
args = "$DIRNAME | patch",
|
||||
}
|
||||
local config = assert(conform.get_formatter_config("test"))
|
||||
local ctx = runner.build_context(0, config)
|
||||
local cmd = runner.build_cmd("", ctx, config)
|
||||
assert.equal("echo " .. vim.fs.dirname(vim.api.nvim_buf_get_name(bufnr)) .. " | patch", cmd)
|
||||
assert.are.same({ vim.fn.exepath("echo"), "--stdin" }, cmd)
|
||||
end)
|
||||
|
||||
it("resolves arg function with string results", function()
|
||||
@ -193,7 +169,7 @@ describe("runner", function()
|
||||
local config = assert(conform.get_formatter_config("test"))
|
||||
local ctx = runner.build_context(0, config)
|
||||
local cmd = runner.build_cmd("", ctx, config)
|
||||
assert.equal("echo | patch", cmd)
|
||||
assert.are.same(util.shell_build_argv(vim.fn.exepath("echo") .. " | patch"), cmd)
|
||||
end)
|
||||
end)
|
||||
|
||||
@ -410,5 +386,22 @@ print("a")
|
||||
assert.are.same({ "a", "d", "c" }, vim.api.nvim_buf_get_lines(0, 0, -1, false))
|
||||
end)
|
||||
end)
|
||||
|
||||
it("can run the format command in the shell", function()
|
||||
-- Mac echo doesn't seem to support -e, but the linux ci runner apparently doesn't have seq
|
||||
if fs.is_mac then
|
||||
conform.formatters.test = {
|
||||
command = "seq",
|
||||
args = "3 1 | sort",
|
||||
}
|
||||
run_formatter_test("", "1\n2\n3")
|
||||
else
|
||||
conform.formatters.test = {
|
||||
command = "echo",
|
||||
args = '-e "World\nHello" | sort',
|
||||
}
|
||||
run_formatter_test("", "Hello\nWorld")
|
||||
end
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
@ -0,0 +1,72 @@
|
||||
local test_util = require("tests.test_util")
|
||||
local util = require("conform.util")
|
||||
|
||||
describe("util", function()
|
||||
local shell = vim.o.shell
|
||||
local shellcmdflag = vim.o.shellcmdflag
|
||||
local shellxescape = vim.o.shellxescape
|
||||
local shellxquote = vim.o.shellxquote
|
||||
after_each(function()
|
||||
test_util.reset_editor()
|
||||
vim.o.shell = shell
|
||||
vim.o.shellcmdflag = shellcmdflag
|
||||
vim.o.shellxescape = shellxescape
|
||||
vim.o.shellxquote = shellxquote
|
||||
end)
|
||||
|
||||
describe("shell_build_argv", function()
|
||||
it("builds simple command", function()
|
||||
vim.o.shell = "/bin/bash"
|
||||
vim.o.shellcmdflag = "-c"
|
||||
vim.o.shellxescape = ""
|
||||
vim.o.shellxquote = ""
|
||||
local argv = util.shell_build_argv("echo hello")
|
||||
assert.are_same({ "/bin/bash", "-c", "echo hello" }, argv)
|
||||
end)
|
||||
|
||||
it("handles shell arguments", function()
|
||||
vim.o.shell = "/bin/bash -f"
|
||||
vim.o.shellcmdflag = "-c"
|
||||
vim.o.shellxescape = ""
|
||||
vim.o.shellxquote = ""
|
||||
local argv = util.shell_build_argv("echo hello")
|
||||
assert.are_same({ "/bin/bash", "-f", "-c", "echo hello" }, argv)
|
||||
end)
|
||||
|
||||
it("handles shell with spaces", function()
|
||||
vim.o.shell = '"c:\\program files\\unix\\sh.exe"'
|
||||
vim.o.shellcmdflag = "-c"
|
||||
vim.o.shellxescape = ""
|
||||
vim.o.shellxquote = ""
|
||||
local argv = util.shell_build_argv("echo hello")
|
||||
assert.are_same({ "c:\\program files\\unix\\sh.exe", "-c", "echo hello" }, argv)
|
||||
end)
|
||||
|
||||
it("handles shell with spaces and args", function()
|
||||
vim.o.shell = '"c:\\program files\\unix\\sh.exe" -f'
|
||||
vim.o.shellcmdflag = "-c"
|
||||
vim.o.shellxescape = ""
|
||||
vim.o.shellxquote = ""
|
||||
local argv = util.shell_build_argv("echo hello")
|
||||
assert.are_same({ "c:\\program files\\unix\\sh.exe", "-f", "-c", "echo hello" }, argv)
|
||||
end)
|
||||
|
||||
it("applies shellxquote", function()
|
||||
vim.o.shell = "/bin/bash"
|
||||
vim.o.shellcmdflag = "-c"
|
||||
vim.o.shellxescape = ""
|
||||
vim.o.shellxquote = "'"
|
||||
local argv = util.shell_build_argv("echo hello")
|
||||
assert.are_same({ "/bin/bash", "-c", "'echo hello'" }, argv)
|
||||
end)
|
||||
|
||||
it("uses shellxescape", function()
|
||||
vim.o.shell = "/bin/bash"
|
||||
vim.o.shellcmdflag = "-c"
|
||||
vim.o.shellxescape = "el"
|
||||
vim.o.shellxquote = "("
|
||||
local argv = util.shell_build_argv("echo hello")
|
||||
assert.are_same({ "/bin/bash", "-c", "(^echo h^e^l^lo)" }, argv)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
Reference in New Issue
Block a user