aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lua/mason-core/spawn.lua7
-rw-r--r--tests/mason-core/spawn_spec.lua18
2 files changed, 22 insertions, 3 deletions
diff --git a/lua/mason-core/spawn.lua b/lua/mason-core/spawn.lua
index 0da67569..3c9c645d 100644
--- a/lua/mason-core/spawn.lua
+++ b/lua/mason-core/spawn.lua
@@ -54,12 +54,13 @@ local function Failure(err, cmd)
}))
end
-local get_path_from_env_list = _.compose(_.strip_prefix "PATH=", _.find_first(_.starts_with "PATH="))
+local get_path_from_env_list =
+ _.compose(_.if_else(_.is_nil, _.identity, _.strip_prefix "PATH="), _.find_first(_.starts_with "PATH="))
---@class SpawnArgs
---@field with_paths string[]? Paths to add to the PATH environment variable.
----@field env table<string, string>? Example { SOME_ENV = "value", SOME_OTHER_ENV = "some_value" }
----@field env_raw string[]? Example: { "SOME_ENV=value", "SOME_OTHER_ENV=some_value" }
+---@field env table<string, string>? Environment variables to merge with the current environment. Example { SOME_ENV = "value", SOME_OTHER_ENV = "some_value" }
+---@field env_raw string[]? The environment to start the process with, will not merge with the current environment. Example: { "SOME_ENV=value", "SOME_OTHER_ENV=some_value" }
---@field stdio_sink StdioSink? If provided, will be used to write to stdout and stderr.
---@field cwd string?
---@field on_spawn (fun(handle: luv_handle, stdio: luv_pipe[], pid: integer))? Will be called when the process successfully spawns.
diff --git a/tests/mason-core/spawn_spec.lua b/tests/mason-core/spawn_spec.lua
index b224bfc3..abbe557e 100644
--- a/tests/mason-core/spawn_spec.lua
+++ b/tests/mason-core/spawn_spec.lua
@@ -193,6 +193,24 @@ describe("async spawn", function()
)
end)
+ it("should handle being unable to find PATH env", function()
+ stub(process, "spawn", function(_, _, callback)
+ callback(true, 0, 0)
+ end)
+
+ local result = a.run_blocking(spawn.bash, { "arg1", env_raw = { SOME_ENV = "value" } })
+ assert.is_true(result:is_success())
+ assert.spy(process.spawn).was_called(1)
+ assert.spy(process.spawn).was_called_with(
+ vim.fn.exepath "bash",
+ match.tbl_containing {
+ args = match.same { "arg1" },
+ env = match.is_table(),
+ },
+ match.is_function()
+ )
+ end)
+
it("should use exepath if env_raw.PATH is set", function()
stub(process, "spawn", function(_, _, callback)
callback(true, 0, 0)