aboutsummaryrefslogtreecommitdiffstats
path: root/tests/mason-core/installer/context_spec.lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2023-04-26 18:23:34 +0200
committerGitHub <noreply@github.com>2023-04-26 16:23:34 +0000
commite5bcda8ffb4668d484c1d08d6b5fbe12f330c727 (patch)
treec751bf492cb5205b1309c5f7d4c2d6c3963797fa /tests/mason-core/installer/context_spec.lua
parentfeat(linker): add ruby exec wrapper delegate (#1260) (diff)
downloadmason-e5bcda8ffb4668d484c1d08d6b5fbe12f330c727.tar
mason-e5bcda8ffb4668d484c1d08d6b5fbe12f330c727.tar.gz
mason-e5bcda8ffb4668d484c1d08d6b5fbe12f330c727.tar.bz2
mason-e5bcda8ffb4668d484c1d08d6b5fbe12f330c727.tar.lz
mason-e5bcda8ffb4668d484c1d08d6b5fbe12f330c727.tar.xz
mason-e5bcda8ffb4668d484c1d08d6b5fbe12f330c727.tar.zst
mason-e5bcda8ffb4668d484c1d08d6b5fbe12f330c727.zip
fix(context): don't write exec wrapper file if it already exists (#1261)
Diffstat (limited to 'tests/mason-core/installer/context_spec.lua')
-rw-r--r--tests/mason-core/installer/context_spec.lua44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/mason-core/installer/context_spec.lua b/tests/mason-core/installer/context_spec.lua
index efd632e3..af99089f 100644
--- a/tests/mason-core/installer/context_spec.lua
+++ b/tests/mason-core/installer/context_spec.lua
@@ -19,6 +19,10 @@ describe("installer", function()
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle)
stub(ctx.fs, "write_file")
+ stub(ctx.fs, "file_exists")
+ stub(ctx.fs, "dir_exists")
+ ctx.fs.file_exists.on_call_with(match.is_ref(ctx.fs), "my-executable").returns(false)
+ ctx.fs.dir_exists.on_call_with(match.is_ref(ctx.fs), "my-executable").returns(false)
stub(std, "chmod")
ctx:write_shell_exec_wrapper("my-executable", "bash -c 'echo $GREETING'", {
@@ -44,6 +48,10 @@ exec bash -c 'echo $GREETING' "$@"]]
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle)
stub(ctx.fs, "write_file")
+ stub(ctx.fs, "file_exists")
+ stub(ctx.fs, "dir_exists")
+ ctx.fs.file_exists.on_call_with(match.is_ref(ctx.fs), "my-executable").returns(false)
+ ctx.fs.dir_exists.on_call_with(match.is_ref(ctx.fs), "my-executable").returns(false)
stub(std, "chmod")
ctx:write_shell_exec_wrapper("my-executable", "cmd.exe /C echo %GREETING%", {
@@ -60,6 +68,23 @@ cmd.exe /C echo %GREETING% %*]]
)
end)
+ it("should not write shell exec wrapper if new executable path already exists", function()
+ local exec_rel_path = path.concat { "obscure", "path", "to", "server" }
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle)
+ stub(ctx.fs, "file_exists")
+ stub(ctx.fs, "dir_exists")
+ ctx.fs.file_exists.on_call_with(match.is_ref(ctx.fs), exec_rel_path).returns(true)
+ ctx.fs.file_exists.on_call_with(match.is_ref(ctx.fs), "my-wrapper-script").returns(true)
+ ctx.fs.dir_exists.on_call_with(match.is_ref(ctx.fs), "my-wrapper-script").returns(true)
+
+ local err = assert.has_error(function()
+ ctx:write_shell_exec_wrapper("my-wrapper-script", "contents")
+ end)
+
+ assert.equals([[Cannot write exec wrapper to "my-wrapper-script" because the file already exists.]], err)
+ end)
+
it("should write Node exec wrapper", function()
local js_rel_path = path.concat { "some", "obscure", "path", "server.js" }
local dummy = registry.get_package "dummy"
@@ -79,6 +104,25 @@ cmd.exe /C echo %GREETING% %*]]
)
end)
+ it("should write Ruby exec wrapper", function()
+ local js_rel_path = path.concat { "some", "obscure", "path", "server.js" }
+ local dummy = registry.get_package "dummy"
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle)
+ stub(ctx, "write_shell_exec_wrapper")
+ stub(ctx.fs, "file_exists")
+ ctx.fs.file_exists.on_call_with(match.is_ref(ctx.fs), js_rel_path).returns(true)
+
+ ctx:write_ruby_exec_wrapper("my-wrapper-script", js_rel_path)
+
+ assert.spy(ctx.write_shell_exec_wrapper).was_called(1)
+ assert.spy(ctx.write_shell_exec_wrapper).was_called_with(
+ match.is_ref(ctx),
+ "my-wrapper-script",
+ ("ruby %q"):format(path.concat { dummy:get_install_path(), js_rel_path })
+ )
+ end)
+
it("should not write Node exec wrapper if the target script doesn't exist", function()
local js_rel_path = path.concat { "some", "obscure", "path", "server.js" }
local handle = InstallHandleGenerator "dummy"