2017-05-12 10:03:05 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
|
|
|
|
|
|
|
local eq = helpers.eq
|
|
|
|
local neq = helpers.neq
|
2022-03-27 10:25:55 -07:00
|
|
|
local command = helpers.command
|
2023-03-25 19:49:32 -07:00
|
|
|
local exec_capture = helpers.exec_capture
|
2022-03-27 10:25:55 -07:00
|
|
|
local write_file = helpers.write_file
|
2024-01-12 10:59:57 -07:00
|
|
|
local api = helpers.api
|
2017-05-12 10:03:05 -07:00
|
|
|
local clear = helpers.clear
|
|
|
|
local dedent = helpers.dedent
|
|
|
|
local exc_exec = helpers.exc_exec
|
2017-05-12 10:47:33 -07:00
|
|
|
local missing_provider = helpers.missing_provider
|
2017-05-12 10:03:05 -07:00
|
|
|
|
2022-03-27 10:25:55 -07:00
|
|
|
local tmpfile = 'X_ex_cmds_script'
|
|
|
|
|
2017-05-12 10:03:05 -07:00
|
|
|
before_each(clear)
|
|
|
|
|
2022-03-27 10:25:55 -07:00
|
|
|
local function source(code)
|
|
|
|
write_file(tmpfile, code)
|
2024-01-02 18:09:18 -07:00
|
|
|
command('source ' .. tmpfile)
|
2022-03-27 10:25:55 -07:00
|
|
|
end
|
|
|
|
|
2017-05-12 10:03:05 -07:00
|
|
|
describe('script_get-based command', function()
|
|
|
|
local garbage = ')}{+*({}]*[;(+}{&[]}{*])('
|
|
|
|
|
2022-03-27 10:25:55 -07:00
|
|
|
after_each(function()
|
|
|
|
os.remove(tmpfile)
|
|
|
|
end)
|
|
|
|
|
2017-05-12 10:03:05 -07:00
|
|
|
local function test_garbage_exec(cmd, check_neq)
|
|
|
|
describe(cmd, function()
|
|
|
|
it('works correctly when skipping oneline variant', function()
|
2024-01-02 18:09:18 -07:00
|
|
|
eq(
|
|
|
|
true,
|
|
|
|
pcall(
|
|
|
|
source,
|
|
|
|
(dedent([[
|
2017-05-12 10:03:05 -07:00
|
|
|
if 0
|
|
|
|
%s %s
|
|
|
|
endif
|
2024-01-02 18:09:18 -07:00
|
|
|
]])):format(cmd, garbage)
|
|
|
|
)
|
|
|
|
)
|
2023-03-25 19:49:32 -07:00
|
|
|
eq('', exec_capture('messages'))
|
2017-05-12 10:03:05 -07:00
|
|
|
if check_neq then
|
2024-01-02 18:09:18 -07:00
|
|
|
neq(
|
|
|
|
0,
|
|
|
|
exc_exec(dedent([[
|
2017-05-12 10:03:05 -07:00
|
|
|
%s %s
|
2024-01-02 18:09:18 -07:00
|
|
|
]])):format(cmd, garbage)
|
|
|
|
)
|
2017-05-12 10:03:05 -07:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
it('works correctly when skipping HEREdoc variant', function()
|
2024-01-02 18:09:18 -07:00
|
|
|
eq(
|
|
|
|
true,
|
|
|
|
pcall(
|
|
|
|
source,
|
|
|
|
(dedent([[
|
2017-05-12 10:03:05 -07:00
|
|
|
if 0
|
|
|
|
%s << EOF
|
|
|
|
%s
|
|
|
|
EOF
|
|
|
|
endif
|
2024-01-02 18:09:18 -07:00
|
|
|
]])):format(cmd, garbage)
|
|
|
|
)
|
|
|
|
)
|
2023-03-25 19:49:32 -07:00
|
|
|
eq('', exec_capture('messages'))
|
2017-05-12 10:03:05 -07:00
|
|
|
if check_neq then
|
2024-01-02 18:09:18 -07:00
|
|
|
eq(
|
|
|
|
true,
|
|
|
|
pcall(
|
|
|
|
source,
|
|
|
|
(dedent([[
|
2017-05-12 10:03:05 -07:00
|
|
|
let g:exc = 0
|
|
|
|
try
|
|
|
|
%s << EOF
|
|
|
|
%s
|
|
|
|
EOF
|
|
|
|
catch
|
|
|
|
let g:exc = v:exception
|
|
|
|
endtry
|
2024-01-02 18:09:18 -07:00
|
|
|
]])):format(cmd, garbage)
|
|
|
|
)
|
|
|
|
)
|
2024-01-12 10:59:57 -07:00
|
|
|
neq(0, api.nvim_get_var('exc'))
|
2017-05-12 10:03:05 -07:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
clear()
|
|
|
|
|
|
|
|
-- Built-in scripts
|
|
|
|
test_garbage_exec('lua', true)
|
|
|
|
|
|
|
|
-- Provider-based scripts
|
2017-05-12 10:47:33 -07:00
|
|
|
test_garbage_exec('ruby', not missing_provider('ruby'))
|
|
|
|
test_garbage_exec('python3', not missing_provider('python3'))
|
2017-05-12 10:03:05 -07:00
|
|
|
|
|
|
|
-- Missing scripts
|
2022-01-28 07:42:19 -07:00
|
|
|
test_garbage_exec('python', false)
|
2017-05-12 10:03:05 -07:00
|
|
|
test_garbage_exec('tcl', false)
|
|
|
|
test_garbage_exec('mzscheme', false)
|
|
|
|
test_garbage_exec('perl', false)
|
|
|
|
|
|
|
|
-- Not really a script
|
|
|
|
test_garbage_exec('xxxinvalidlanguagexxx', true)
|
|
|
|
end)
|