This commit is contained in:
Barrett Ruth 2025-09-22 23:25:02 -04:00
parent 5f555a0285
commit 5dd4d9109a

View file

@ -26,7 +26,7 @@ describe('cp.async.scraper', function()
end, end,
} }
vim.system = function(cmd, opts, callback) vim.system = function(cmd, _, callback)
local result = { code = 0, stdout = '{}', stderr = '' } local result = { code = 0, stdout = '{}', stderr = '' }
if cmd[1] == 'ping' then if cmd[1] == 'ping' then
result = { code = 0 } result = { code = 0 }
@ -40,7 +40,6 @@ describe('cp.async.scraper', function()
if callback then if callback then
callback(result) callback(result)
else else
-- Return object with :wait() for sync calls
return { return {
wait = function() wait = function()
return result return result
@ -87,9 +86,16 @@ describe('cp.async.scraper', function()
end) end)
it('calls callback with error on network failure', function() it('calls callback with error on network failure', function()
vim.system = function(cmd, _, callback) vim.system = function(_, _, callback)
if cmd[1] == 'ping' then local result = { code = 1 }
callback({ code = 1 }) if callback then
callback(result)
else
return {
wait = function()
return result
end,
}
end end
end end
@ -118,10 +124,21 @@ describe('cp.async.scraper', function()
it('calls callback with error on subprocess failure', function() it('calls callback with error on subprocess failure', function()
vim.system = function(cmd, _, callback) vim.system = function(cmd, _, callback)
local result
if cmd[1] == 'ping' then if cmd[1] == 'ping' then
callback({ code = 0 }) result = { code = 0 }
else else
callback({ code = 1, stderr = 'execution failed' }) result = { code = 1, stderr = 'execution failed' }
end
if callback then
callback(result)
else
return {
wait = function()
return result
end,
}
end end
end end
@ -136,10 +153,21 @@ describe('cp.async.scraper', function()
it('calls callback with error on invalid JSON', function() it('calls callback with error on invalid JSON', function()
vim.system = function(cmd, _, callback) vim.system = function(cmd, _, callback)
local result
if cmd[1] == 'ping' then if cmd[1] == 'ping' then
callback({ code = 0 }) result = { code = 0 }
else else
callback({ code = 0, stdout = 'invalid json' }) result = { code = 0, stdout = 'invalid json' }
end
if callback then
callback(result)
else
return {
wait = function()
return result
end,
}
end end
end end
@ -166,9 +194,16 @@ describe('cp.async.scraper', function()
end) end)
it('handles network failure gracefully', function() it('handles network failure gracefully', function()
vim.system = function(cmd, _, callback) vim.system = function(_, _, callback)
if cmd[1] == 'ping' then local result = { code = 1 }
callback({ code = 1 }) if callback then
callback(result)
else
return {
wait = function()
return result
end,
}
end end
end end