aboutsummaryrefslogtreecommitdiffstats
path: root/tests/core/spawn_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tests/core/spawn_spec.lua')
-rw-r--r--tests/core/spawn_spec.lua31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/core/spawn_spec.lua b/tests/core/spawn_spec.lua
index 176135ee..7c0a27f8 100644
--- a/tests/core/spawn_spec.lua
+++ b/tests/core/spawn_spec.lua
@@ -1,4 +1,5 @@
local spy = require "luassert.spy"
+local stub = require "luassert.stub"
local match = require "luassert.match"
local spawn = require "nvim-lsp-installer.core.spawn"
local process = require "nvim-lsp-installer.process"
@@ -113,4 +114,34 @@ describe("async spawn", function()
assert.is_true(result:is_failure())
end)
)
+
+ it(
+ "should handle failure to spawn process",
+ async_test(function()
+ stub(process, "spawn", function(_, _, callback)
+ callback(false)
+ end)
+
+ local result = spawn.my_cmd {}
+ assert.is_true(result:is_failure())
+ assert.is_nil(result:err_or_nil().exit_code)
+ end)
+ )
+
+ it(
+ "should format failure message",
+ async_test(function()
+ stub(process, "spawn", function(cmd, opts, callback)
+ opts.stdio_sink.stderr(("This is an error message for %s!"):format(cmd))
+ callback(false, 127)
+ end)
+
+ local result = spawn.my_cmd {}
+ assert.is_true(result:is_failure())
+ assert.equals(
+ "spawn: my_cmd failed with exit code 127. This is an error message for my_cmd!",
+ tostring(result:err_or_nil())
+ )
+ end)
+ )
end)