robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
2.5 KiB114 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3
4local describe, it, before_each, after_each = t.describe, t.it, t.before_each, t.after_each
5local eq = t.eq
6local pcall_err = t.pcall_err
7local neq = t.neq
8local command = n.command
9local exec_capture = n.exec_capture
10local write_file = t.write_file
11local api = n.api
12local clear = n.clear
13local dedent = t.dedent
14local missing_provider = n.missing_provider
15
16local tmpfile = 'X_ex_cmds_script'
17
18before_each(clear)
19
20local function source(code)
21  write_file(tmpfile, code)
22  command('source ' .. tmpfile)
23end
24
25describe('script_get-based command', function()
26  local garbage = ')}{+*({}]*[;(+}{&[]}{*])('
27
28  after_each(function()
29    os.remove(tmpfile)
30  end)
31
32  local function test_garbage_exec(cmd, check_neq)
33    describe(cmd, function()
34      it('works correctly when skipping oneline variant', function()
35        eq(
36          true,
37          pcall(
38            source,
39            (dedent([[
40          if 0
41            %s %s
42          endif
43        ]])):format(cmd, garbage)
44          )
45        )
46        eq('', exec_capture('messages'))
47        if check_neq then
48          neq(
49            0,
50            pcall_err(
51              command,
52              dedent([[
53            %s %s
54          ]])
55            ):format(cmd, garbage)
56          )
57        end
58      end)
59      it('works correctly when skipping HEREdoc variant', function()
60        eq(
61          true,
62          pcall(
63            source,
64            (dedent([[
65          if 0
66          %s << EOF
67          %s
68          EOF
69          endif
70        ]])):format(cmd, garbage)
71          )
72        )
73        eq('', exec_capture('messages'))
74        if check_neq then
75          eq(
76            true,
77            pcall(
78              source,
79              (dedent([[
80            let g:exc = 0
81            try
82            %s << EOF
83            %s
84            EOF
85            catch
86            let g:exc = v:exception
87            endtry
88          ]])):format(cmd, garbage)
89            )
90          )
91          neq(0, api.nvim_get_var('exc'))
92        end
93      end)
94    end)
95  end
96
97  clear()
98
99  -- Built-in scripts
100  test_garbage_exec('lua', true)
101
102  -- Provider-based scripts
103  test_garbage_exec('ruby', not missing_provider('ruby'))
104  test_garbage_exec('python3', not missing_provider('python'))
105
106  -- Missing scripts
107  test_garbage_exec('python', false)
108  test_garbage_exec('tcl', false)
109  test_garbage_exec('mzscheme', false)
110  test_garbage_exec('perl', false)
111
112  -- Not really a script
113  test_garbage_exec('xxxinvalidlanguagexxx', true)
114end)