From c1dbd9824ceb03f2e378cc5b732cd11ba0e4c991 Mon Sep 17 00:00:00 2001 From: William Boman Date: Sun, 5 Mar 2023 02:33:57 +0100 Subject: feat(InstallContext): add strict_mode flag (#1055) Also add some more ctx.fs methods. --- tests/helpers/lua/test_helpers.lua | 8 ++++---- tests/mason-core/installer/context_spec.lua | 1 - tests/mason-core/installer/installer_spec.lua | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/helpers/lua/test_helpers.lua b/tests/helpers/lua/test_helpers.lua index 17ec5ae5..08a0e91b 100644 --- a/tests/helpers/lua/test_helpers.lua +++ b/tests/helpers/lua/test_helpers.lua @@ -43,10 +43,10 @@ end ---@param opts PackageInstallOpts? function InstallContextGenerator(handle, opts) local context = InstallContext.new(handle, opts or {}) - context.spawn = setmetatable({}, { - __index = function(s, cmd) - s[cmd] = spy.new(mockx.just_runs()) - return s[cmd] + context.spawn = setmetatable({ strict_mode = false }, { + __index = function(self, cmd) + self[cmd] = spy.new(mockx.just_runs()) + return self[cmd] end, }) return context diff --git a/tests/mason-core/installer/context_spec.lua b/tests/mason-core/installer/context_spec.lua index 0a5b7410..e09ebd52 100644 --- a/tests/mason-core/installer/context_spec.lua +++ b/tests/mason-core/installer/context_spec.lua @@ -105,7 +105,6 @@ cmd.exe /C echo %GREETING% %*]] stub(ctx.cwd, "get") ctx.cwd.get.returns "/tmp/placeholder" stub(ctx, "write_shell_exec_wrapper") - stub(ctx.spawn, "python") ctx:write_pyvenv_exec_wrapper("my-wrapper-script", "my-module") diff --git a/tests/mason-core/installer/installer_spec.lua b/tests/mason-core/installer/installer_spec.lua index 094129f9..66cdb89b 100644 --- a/tests/mason-core/installer/installer_spec.lua +++ b/tests/mason-core/installer/installer_spec.lua @@ -4,6 +4,7 @@ local stub = require "luassert.stub" local fs = require "mason-core.fs" local a = require "mason-core.async" local path = require "mason-core.path" +local Result = require "mason-core.result" local installer = require "mason-core.installer" local InstallContext = require "mason-core.installer.context" @@ -147,4 +148,23 @@ describe("installer", function() .was_called_with(path.package_prefix "dummy/mason-debug.log", "Hello stdout!\nHello stderr!") end) ) + + it( + "should raise spawn errors in strict mode", + async_test(function() + local handle = InstallHandleGenerator "dummy" + stub(handle.package.spec, "install", function(ctx) + ctx.spawn.bash { "-c", "exit 42" } + end) + local result = installer.execute(handle, { debug = true }) + assert.same( + Result.failure { + exit_code = 42, + signal = 0, + }, + result + ) + assert.equals("spawn: bash failed with exit code 42 and signal 0. ", tostring(result:err_or_nil())) + end) + ) end) -- cgit v1.2.3-70-g09d2