diff options
| -rw-r--r-- | lua/mason-core/installer/init.lua | 11 | ||||
| -rw-r--r-- | tests/mason-core/installer/installer_spec.lua | 19 |
2 files changed, 27 insertions, 3 deletions
diff --git a/lua/mason-core/installer/init.lua b/lua/mason-core/installer/init.lua index 4250508c..a11de45d 100644 --- a/lua/mason-core/installer/init.lua +++ b/lua/mason-core/installer/init.lua @@ -107,11 +107,12 @@ function M.execute(handle, opts) local pkg = handle.package local context = InstallContext.new(handle, opts) + local tailed_output = {} if opts.debug then - local append_log = a.scope(function(chunk) - context.fs:append_file("mason-debug.log", chunk) - end) + local function append_log(chunk) + tailed_output[#tailed_output + 1] = chunk + end handle:on("stdout", append_log) handle:on("stderr", append_log) end @@ -149,6 +150,9 @@ function M.execute(handle, opts) permit:forget() handle:close() log.fmt_info("Installation succeeded for %s", pkg) + if opts.debug then + context.fs:write_file("mason-debug.log", table.concat(tailed_output, "")) + end end) :on_failure(function(failure) permit:forget() @@ -162,6 +166,7 @@ function M.execute(handle, opts) fs.async.rmrf(context.cwd:get()) end) else + context.fs:write_file("mason-debug.log", table.concat(tailed_output, "")) context.stdio_sink.stdout( ("[debug] Installation directory retained at %q.\n"):format(context.cwd:get()) ) diff --git a/tests/mason-core/installer/installer_spec.lua b/tests/mason-core/installer/installer_spec.lua index 421de34b..c9c44d24 100644 --- a/tests/mason-core/installer/installer_spec.lua +++ b/tests/mason-core/installer/installer_spec.lua @@ -1,3 +1,4 @@ +local stub = require "luassert.stub" local spy = require "luassert.spy" local match = require "luassert.match" local fs = require "mason-core.fs" @@ -111,4 +112,22 @@ describe("installer", function() assert.spy(capture).was_called_with(match.instanceof(InstallContext), "two", "three") end) ) + + it( + "should write log files if debug is true", + async_test(function() + spy.on(fs.async, "write_file") + local handle = InstallHandleGenerator "dummy" + stub(handle.package.spec, "install", function(ctx) + ctx.stdio_sink.stdout "Hello stdout!\n" + ctx.stdio_sink.stderr "Hello " + ctx.stdio_sink.stderr "stderr!" + ctx.receipt:with_primary_source { type = "unmanaged" } + end) + installer.execute(handle, { debug = true }) + assert + .spy(fs.async.write_file) + .was_called_with(path.package_prefix "dummy/mason-debug.log", "Hello stdout!\nHello stderr!") + end) + ) end) |
