diff options
| author | William Boman <william@redwill.se> | 2022-12-20 14:58:19 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-20 14:58:19 +0100 |
| commit | dd04b4105e84620685c37efb6ca935d282e11465 (patch) | |
| tree | 64e917185d49b7586d522e8ad7456e6d5800a7bd /tests/mason-core/spawn_spec.lua | |
| parent | chore: update generated code (#780) (diff) | |
| download | mason-dd04b4105e84620685c37efb6ca935d282e11465.tar mason-dd04b4105e84620685c37efb6ca935d282e11465.tar.gz mason-dd04b4105e84620685c37efb6ca935d282e11465.tar.bz2 mason-dd04b4105e84620685c37efb6ca935d282e11465.tar.lz mason-dd04b4105e84620685c37efb6ca935d282e11465.tar.xz mason-dd04b4105e84620685c37efb6ca935d282e11465.tar.zst mason-dd04b4105e84620685c37efb6ca935d282e11465.zip | |
fix(spawn): always expand cmd if PATH is not modified (#773)
fix(spawn): always expand cmd on Windows
Closes #720.
Diffstat (limited to 'tests/mason-core/spawn_spec.lua')
| -rw-r--r-- | tests/mason-core/spawn_spec.lua | 62 |
1 files changed, 47 insertions, 15 deletions
diff --git a/tests/mason-core/spawn_spec.lua b/tests/mason-core/spawn_spec.lua index f9f90411..59ccd533 100644 --- a/tests/mason-core/spawn_spec.lua +++ b/tests/mason-core/spawn_spec.lua @@ -66,7 +66,7 @@ describe("async spawn", function() assert.equals("", result:get_or_nil().stderr) assert.spy(process.spawn).was_called(1) assert.spy(process.spawn).was_called_with( - "bash", + match.matches "bash$", match.tbl_containing { stdio_sink = match.tbl_containing { stdout = match.is_function(), @@ -139,7 +139,8 @@ describe("async spawn", function() callback(false) end) - local result = spawn.my_cmd {} + local result = spawn.bash {} + assert.spy(process.spawn).was_called(1) assert.is_true(result:is_failure()) assert.is_nil(result:err_or_nil().exit_code) end) @@ -155,33 +156,40 @@ describe("async spawn", function() local result = spawn.bash {} assert.is_true(result:is_failure()) - assert.equals( - "spawn: bash failed with exit code 127 and signal -. This is an error message for bash!", - tostring(result:err_or_nil()) + assert.is_true( + match.matches "spawn: .+bash failed with exit code 127 and signal %-%. This is an error message for .+bash!"( + tostring(result:err_or_nil()) + ) ) end) ) it( - "should check whether command is executable", + "should fail if unable to expand command", async_test(function() - local result = spawn.my_cmd {} + spy.on(process, "spawn") + stub(vim.fn, "exepath", function() + return "" + end) + + local result = spawn.unexpand_cmd {} assert.is_true(result:is_failure()) - assert.equals( - "spawn: my_cmd failed with exit code - and signal -. my_cmd is not executable", - tostring(result:err_or_nil()) + assert.is_true( + match.matches "spawn: unexpand_cmd failed with exit code %- and signal %-%. unexpand_cmd is not executable"( + tostring(result:err_or_nil()) + ) ) end) ) it( - "should skip checking whether command is executable", + "should not expand cmd if custom PATH is used", async_test(function() stub(process, "spawn", function(_, _, callback) callback(false, 127) end) - local result = spawn.my_cmd { "arg1", check_executable = false } + local result = spawn.my_cmd { "arg1", env = { PATH = "/bin" } } assert.is_true(result:is_failure()) assert.spy(process.spawn).was_called(1) assert.spy(process.spawn).was_called_with( @@ -195,17 +203,17 @@ describe("async spawn", function() ) it( - "should skip checking whether command is executable if with_paths is provided", + "should skip expanding command if with_paths is provided", async_test(function() stub(process, "spawn", function(_, _, callback) callback(false, 127) end) - local result = spawn.my_cmd { "arg1", with_paths = {} } + local result = spawn.custom_path { "arg1", with_paths = {} } assert.is_true(result:is_failure()) assert.spy(process.spawn).was_called(1) assert.spy(process.spawn).was_called_with( - "my_cmd", + "custom_path", match.tbl_containing { args = match.same { "arg1" }, }, @@ -213,4 +221,28 @@ describe("async spawn", function() ) end) ) + + it( + "should use expanded command path", + async_test(function() + stub(vim.fn, "exepath", function() + return "/abs/path/to/cmd" + end) + stub(process, "spawn", function(_, _, callback) + callback(false) + end) + + spawn.the_command { "arg1", "arg2" } + assert.spy(vim.fn.exepath).was_called(1) + assert.spy(vim.fn.exepath).was_called_with "the_command" + assert.spy(process.spawn).was_called(1) + assert.spy(process.spawn).was_called_with( + "/abs/path/to/cmd", + match.tbl_containing { + args = match.same { "arg1", "arg2" }, + }, + match.is_function() + ) + end) + ) end) |
