|
1 | 1 | local a = require "mason-core.async"
|
2 | 2 | local match = require "luassert.match"
|
| 3 | +local platform = require "mason-core.platform" |
3 | 4 | local process = require "mason-core.process"
|
4 | 5 | local spawn = require "mason-core.spawn"
|
5 | 6 | local spy = require "luassert.spy"
|
@@ -146,46 +147,81 @@ describe("async spawn", function()
|
146 | 147 | )
|
147 | 148 | end)
|
148 | 149 |
|
149 |
| - it("should check whether command is executable", function() |
150 |
| - local result = a.run_blocking(spawn.my_cmd, {}) |
151 |
| - assert.is_true(result:is_failure()) |
152 |
| - assert.equals( |
153 |
| - "spawn: my_cmd failed with exit code - and signal -. my_cmd is not executable", |
154 |
| - tostring(result:err_or_nil()) |
155 |
| - ) |
156 |
| - end) |
| 150 | + describe("Windows", function() |
| 151 | + before_each(function() |
| 152 | + platform.is.win = true |
| 153 | + end) |
157 | 154 |
|
158 |
| - it("should skip checking whether command is executable", function() |
159 |
| - stub(process, "spawn", function(_, _, callback) |
160 |
| - callback(false, 127) |
| 155 | + after_each(function() |
| 156 | + platform.is.win = nil |
161 | 157 | end)
|
162 | 158 |
|
163 |
| - local result = a.run_blocking(spawn.my_cmd, { "arg1", check_executable = false }) |
164 |
| - assert.is_true(result:is_failure()) |
165 |
| - assert.spy(process.spawn).was_called(1) |
166 |
| - assert.spy(process.spawn).was_called_with( |
167 |
| - "my_cmd", |
168 |
| - match.tbl_containing { |
169 |
| - args = match.same { "arg1" }, |
170 |
| - }, |
171 |
| - match.is_function() |
172 |
| - ) |
173 |
| - end) |
| 159 | + it("should use exepath to get absolute path to executable", function() |
| 160 | + stub(process, "spawn", function(_, _, callback) |
| 161 | + callback(true, 0, 0) |
| 162 | + end) |
| 163 | + |
| 164 | + local result = a.run_blocking(spawn.bash, { "arg1" }) |
| 165 | + assert.is_true(result:is_success()) |
| 166 | + assert.spy(process.spawn).was_called(1) |
| 167 | + assert.spy(process.spawn).was_called_with( |
| 168 | + vim.fn.exepath "bash", |
| 169 | + match.tbl_containing { |
| 170 | + args = match.same { "arg1" }, |
| 171 | + }, |
| 172 | + match.is_function() |
| 173 | + ) |
| 174 | + end) |
174 | 175 |
|
175 |
| - it("should skip checking whether command is executable if with_paths is provided", function() |
176 |
| - stub(process, "spawn", function(_, _, callback) |
177 |
| - callback(false, 127) |
| 176 | + it("should not use exepath if env.PATH is set", function() |
| 177 | + stub(process, "spawn", function(_, _, callback) |
| 178 | + callback(true, 0, 0) |
| 179 | + end) |
| 180 | + |
| 181 | + local result = a.run_blocking(spawn.bash, { "arg1", env = { PATH = "C:\\some\\path" } }) |
| 182 | + assert.is_true(result:is_success()) |
| 183 | + assert.spy(process.spawn).was_called(1) |
| 184 | + assert.spy(process.spawn).was_called_with( |
| 185 | + "bash", |
| 186 | + match.tbl_containing { |
| 187 | + args = match.same { "arg1" }, |
| 188 | + }, |
| 189 | + match.is_function() |
| 190 | + ) |
178 | 191 | end)
|
179 | 192 |
|
180 |
| - local result = a.run_blocking(spawn.my_cmd, { "arg1", with_paths = {} }) |
181 |
| - assert.is_true(result:is_failure()) |
182 |
| - assert.spy(process.spawn).was_called(1) |
183 |
| - assert.spy(process.spawn).was_called_with( |
184 |
| - "my_cmd", |
185 |
| - match.tbl_containing { |
186 |
| - args = match.same { "arg1" }, |
187 |
| - }, |
188 |
| - match.is_function() |
189 |
| - ) |
| 193 | + it("should not use exepath if env_raw.PATH is set", function() |
| 194 | + stub(process, "spawn", function(_, _, callback) |
| 195 | + callback(true, 0, 0) |
| 196 | + end) |
| 197 | + |
| 198 | + local result = a.run_blocking(spawn.bash, { "arg1", env_raw = { "PATH=C:\\some\\path" } }) |
| 199 | + assert.is_true(result:is_success()) |
| 200 | + assert.spy(process.spawn).was_called(1) |
| 201 | + assert.spy(process.spawn).was_called_with( |
| 202 | + "bash", |
| 203 | + match.tbl_containing { |
| 204 | + args = match.same { "arg1" }, |
| 205 | + }, |
| 206 | + match.is_function() |
| 207 | + ) |
| 208 | + end) |
| 209 | + |
| 210 | + it("should not use exepath if with_paths is provided", function() |
| 211 | + stub(process, "spawn", function(_, _, callback) |
| 212 | + callback(true, 0, 0) |
| 213 | + end) |
| 214 | + |
| 215 | + local result = a.run_blocking(spawn.bash, { "arg1", with_paths = { "C:\\some\\path" } }) |
| 216 | + assert.is_true(result:is_success()) |
| 217 | + assert.spy(process.spawn).was_called(1) |
| 218 | + assert.spy(process.spawn).was_called_with( |
| 219 | + "bash", |
| 220 | + match.tbl_containing { |
| 221 | + args = match.same { "arg1" }, |
| 222 | + }, |
| 223 | + match.is_function() |
| 224 | + ) |
| 225 | + end) |
190 | 226 | end)
|
191 | 227 | end)
|
0 commit comments