Files
neovim/test/functional/lua/ssh_spec.lua
Justin M. Keyes 6d8c8b18d5 test(harness): migrate away from magic globals
Problem:
The magic globals `it`, `describe`, etc., are more trouble than they are
worth.

- Hooking into `after_each` requires `getfenv()` hacks.
- They confuse luals/emmylua, because the top-level `.luarc.json` isn't
  merged with `test/.luarc.json` (apparently a luals limitation?)
- They totally defeat discoverability because the user just has to
  "know" about the various magic symbols.

So they harm DX, which means they serve no purpose at all.

Solution:
- Expose the test API from `testutil`, so tests can call `t.it()`,
  `t.describe()`, etc., in the conventional way.
- Drop `getfenv()` hacks.
- Drop the `setfenv()` injection in `load_chunk`.
- Drop `test/_meta.lua`.
2026-07-21 13:22:39 +02:00

80 lines
1.7 KiB
Lua

local t = require('test.testutil')
local parser = require('vim.net._ssh')
local describe, it = t.describe, t.it
local eq = t.eq
describe('SSH parser', function()
it('parses SSH configuration strings', function()
local config = [[
Host *
ConnectTimeout 10
ServerAliveInterval 60
ServerAliveCountMax 3
# Use a specific key for any host not otherwise specified
# IdentityFile ~/.ssh/id_rsa
Host=dev
HostName=dev.example.com
User=devuser
Port=2222
IdentityFile=~/.ssh/id_rsa_dev
Host prod test
HostName 198.51.100.10
User admin
Port 22
IdentityFile ~/.ssh/id_rsa_prod
ForwardAgent yes
Host test
IdentitiesOnly yes
Host "quoted string"
User quote
Port 22
Match host foo host gh
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_github
IdentitiesOnly yes
]]
eq({
'dev',
'prod',
'test',
'quoted string',
'gh',
}, parser.parse_ssh_config(config))
end)
it('fails when a quote is not closed', function()
local config = [[
Host prod dev "test prod my
HostName 198.51.100.10
User admin
Port 22
IdentityFile ~/.ssh/id_rsa_prod
ForwardAgent yes
]]
local ok, _ = pcall(parser.parse_ssh_config, config)
eq(false, ok)
end)
it('fails when the line ends with a single backslash', function()
local config = [[
Host prod test
HostName 198.51.100.10
User admin\
Port 22
IdentityFile ~/.ssh/id_rsa_prod
ForwardAgent yes
]]
local ok, _ = pcall(parser.parse_ssh_config, config)
eq(false, ok)
end)
end)