robin/laufey

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

robinmerge: 1dc9728daa1d8a2702

master
2.2 KiB84 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3
4local describe, it = t.describe, t.it
5local eq = t.eq
6local is_os = t.is_os
7local skip = t.skip
8local api = n.api
9local clear = n.clear
10
11describe("'shell…' option defaults based on $SHELL #28384", function()
12  ---@param sh string
13  ---@param shcf string
14  ---@param sp string
15  ---@param srr string
16  ---@param sxq string
17  ---@param ssl boolean
18  local function expect(sh, shcf, sp, srr, sxq, ssl)
19    local opt = { sh = sh, shcf = shcf, sp = sp, srr = srr, sxq = sxq, ssl = ssl }
20    for k, v in pairs(opt) do
21      eq(v, api.nvim_get_option_info2(k, {}).default)
22    end
23  end
24  it('cmd.exe', function()
25    skip(not is_os('win'), 'N/A: only works on Windows')
26    clear()
27    expect('cmd.exe', '/s /c', '2>&1| tee', '>%s 2>&1', '"', false)
28  end)
29
30  it('powershell(PowerShell 5.x)', function()
31    t.skip(not is_os('win'), 'N/A: only works on Windows')
32    clear {
33      env = { SHELL = 'powershell' },
34    }
35    expect('powershell', '-Command', '2>&1| tee', '>%s 2>&1', '', true)
36  end)
37
38  it('pwsh(PowerShell 7.x)', function()
39    clear {
40      env = { SHELL = 'pwsh' },
41    }
42    expect('pwsh', '-c', '2>&1| tee', '>%s 2>&1', '', true)
43  end)
44
45  it('csh', function()
46    clear {
47      env = { SHELL = 'csh' },
48    }
49    expect('csh', '-c', '|& tee', '>&', '', true)
50  end)
51
52  it('bash', function()
53    clear {
54      env = { SHELL = 'bash' },
55    }
56    expect('bash', '-c', '2>&1| tee', '>%s 2>&1', '', true)
57  end)
58
59  it('unknown', function()
60    clear {
61      env = { SHELL = 'unknown' },
62    }
63    expect(
64      'unknown',
65      '-c',
66      not is_os('win') and '| tee' or '2>&1| tee',
67      not is_os('win') and '>' or '>%s 2>&1',
68      '',
69      not is_os('win') and true or false
70    )
71  end)
72
73  it('if the path contains spaces', function()
74    clear {
75      env = { SHELL = ('%s/foo bar/bash'):format(n.nvim_dir) },
76    }
77    expect(('"%s/foo bar/bash"'):format(n.nvim_dir), '-c', '2>&1| tee', '>%s 2>&1', '', true)
78  end)
79
80  it('no crash when the shell path ends in a separator', function()
81    clear { args = { '--cmd', 'let &shell = "/bin/"' } }
82    eq('/bin/', api.nvim_get_option_value('shell', {}))
83  end)
84end)