diff options
Diffstat (limited to 'tests/mason-core/installer')
35 files changed, 914 insertions, 628 deletions
diff --git a/tests/mason-core/installer/context_spec.lua b/tests/mason-core/installer/context_spec.lua index 646f7e30..9c1805cb 100644 --- a/tests/mason-core/installer/context_spec.lua +++ b/tests/mason-core/installer/context_spec.lua @@ -3,10 +3,20 @@ local path = require "mason-core.path" local pypi = require "mason-core.installer.managers.pypi" local registry = require "mason-registry" local stub = require "luassert.stub" +local test_helpers = require "mason-test.helpers" describe("installer", function() ---@module "mason-core.platform" local platform + local snapshot + + before_each(function() + snapshot = assert.snapshot() + end) + + after_each(function() + snapshot:revert() + end) before_each(function() package.loaded["mason-core.installer.platform"] = nil @@ -15,8 +25,7 @@ describe("installer", function() end) it("should write shell exec wrapper on Unix", function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) + local ctx = test_helpers.create_context() stub(ctx.fs, "write_file") stub(ctx.fs, "file_exists") stub(ctx.fs, "dir_exists") @@ -44,8 +53,7 @@ exec bash -c 'echo $GREETING' "$@"]] platform.is.unix = false platform.is.linux = false platform.is.win = true - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) + local ctx = test_helpers.create_context() stub(ctx.fs, "write_file") stub(ctx.fs, "file_exists") stub(ctx.fs, "dir_exists") @@ -68,8 +76,7 @@ cmd.exe /C echo %GREETING% %*]] 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) + local ctx = test_helpers.create_context() 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) @@ -86,8 +93,7 @@ cmd.exe /C echo %GREETING% %*]] it("should write Node 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) + local ctx = test_helpers.create_context() 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) @@ -105,8 +111,7 @@ cmd.exe /C echo %GREETING% %*]] 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) + local ctx = test_helpers.create_context() 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) @@ -123,8 +128,7 @@ cmd.exe /C echo %GREETING% %*]] 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" - local ctx = InstallContextGenerator(handle) + local ctx = test_helpers.create_context() 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(false) @@ -142,8 +146,7 @@ cmd.exe /C echo %GREETING% %*]] it("should write Python exec wrapper", function() local dummy = registry.get_package "dummy" - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) + local ctx = test_helpers.create_context() stub(ctx.cwd, "get") ctx.cwd.get.returns "/tmp/placeholder" stub(ctx, "write_shell_exec_wrapper") @@ -159,8 +162,7 @@ cmd.exe /C echo %GREETING% %*]] end) it("should not write Python exec wrapper if module cannot be found", function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) + local ctx = test_helpers.create_context() stub(ctx.cwd, "get") ctx.cwd.get.returns "/tmp/placeholder" stub(ctx, "write_shell_exec_wrapper") @@ -181,8 +183,7 @@ cmd.exe /C echo %GREETING% %*]] it("should write exec wrapper", function() local dummy = registry.get_package "dummy" local exec_rel_path = path.concat { "obscure", "path", "to", "server" } - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) + local ctx = test_helpers.create_context() stub(ctx, "write_shell_exec_wrapper") stub(ctx.fs, "file_exists") ctx.fs.file_exists.on_call_with(match.is_ref(ctx.fs), exec_rel_path).returns(true) @@ -201,8 +202,7 @@ cmd.exe /C echo %GREETING% %*]] it("should not write exec wrapper if target executable doesn't exist", function() local exec_rel_path = path.concat { "obscure", "path", "to", "server" } - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) + local ctx = test_helpers.create_context() stub(ctx, "write_shell_exec_wrapper") stub(ctx.fs, "file_exists") ctx.fs.file_exists.on_call_with(match.is_ref(ctx.fs), exec_rel_path).returns(false) @@ -218,8 +218,7 @@ cmd.exe /C echo %GREETING% %*]] it("should write PHP exec wrapper", function() local php_rel_path = path.concat { "some", "obscure", "path", "cli.php" } local dummy = registry.get_package "dummy" - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) + local ctx = test_helpers.create_context() stub(ctx, "write_shell_exec_wrapper") stub(ctx.fs, "file_exists") ctx.fs.file_exists.on_call_with(match.is_ref(ctx.fs), php_rel_path).returns(true) @@ -236,8 +235,7 @@ cmd.exe /C echo %GREETING% %*]] it("should not write PHP exec wrapper if the target script doesn't exist", function() local php_rel_path = path.concat { "some", "obscure", "path", "cli.php" } - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) + local ctx = test_helpers.create_context() stub(ctx, "write_shell_exec_wrapper") stub(ctx.fs, "file_exists") ctx.fs.file_exists.on_call_with(match.is_ref(ctx.fs), php_rel_path).returns(false) diff --git a/tests/mason-core/installer/handle_spec.lua b/tests/mason-core/installer/handle_spec.lua index c301b28b..66a9a5c4 100644 --- a/tests/mason-core/installer/handle_spec.lua +++ b/tests/mason-core/installer/handle_spec.lua @@ -4,6 +4,16 @@ local spy = require "luassert.spy" local stub = require "luassert.stub" describe("installer handle", function() + local snapshot + + before_each(function() + snapshot = assert.snapshot() + end) + + after_each(function() + snapshot:revert() + end) + it("should register spawn handle", function() local handle = InstallHandle.new(mock.new {}) local spawn_handle_change_handler = spy.new() @@ -72,36 +82,33 @@ describe("installer handle", function() assert.spy(kill_handler).was_called_with(9) end) - it( - "should terminate handle", - async_test(function() - local process = require "mason-core.process" - stub(process, "kill") - local uv_handle1 = {} - local uv_handle2 = {} - local handle = InstallHandle.new(mock.new {}) - local kill_handler = spy.new() - local terminate_handler = spy.new() - local closed_handler = spy.new() + it("should terminate handle", function() + local process = require "mason-core.process" + stub(process, "kill") + local uv_handle1 = {} + local uv_handle2 = {} + local handle = InstallHandle.new(mock.new {}) + local kill_handler = spy.new() + local terminate_handler = spy.new() + local closed_handler = spy.new() - handle:once("kill", kill_handler) - handle:once("terminate", terminate_handler) - handle:once("closed", closed_handler) - handle.state = "ACTIVE" - handle.spawn_handles = { { uv_handle = uv_handle2 }, { uv_handle = uv_handle2 } } - handle:terminate() + handle:once("kill", kill_handler) + handle:once("terminate", terminate_handler) + handle:once("closed", closed_handler) + handle.state = "ACTIVE" + handle.spawn_handles = { { uv_handle = uv_handle2 }, { uv_handle = uv_handle2 } } + handle:terminate() - assert.spy(process.kill).was_called(2) - assert.spy(process.kill).was_called_with(uv_handle1, 15) - assert.spy(process.kill).was_called_with(uv_handle2, 15) - assert.spy(kill_handler).was_called(1) - assert.spy(kill_handler).was_called_with(15) - assert.spy(terminate_handler).was_called(1) - assert.is_true(handle.is_terminated) - assert.wait_for(function() - assert.is_true(handle:is_closed()) - assert.spy(closed_handler).was_called(1) - end) + assert.spy(process.kill).was_called(2) + assert.spy(process.kill).was_called_with(uv_handle1, 15) + assert.spy(process.kill).was_called_with(uv_handle2, 15) + assert.spy(kill_handler).was_called(1) + assert.spy(kill_handler).was_called_with(15) + assert.spy(terminate_handler).was_called(1) + assert.is_true(handle.is_terminated) + assert.wait(function() + assert.is_true(handle:is_closed()) + assert.spy(closed_handler).was_called(1) end) - ) + end) end) diff --git a/tests/mason-core/installer/installer_spec.lua b/tests/mason-core/installer/installer_spec.lua deleted file mode 100644 index 3e291308..00000000 --- a/tests/mason-core/installer/installer_spec.lua +++ /dev/null @@ -1,217 +0,0 @@ -local InstallContext = require "mason-core.installer.context" -local Result = require "mason-core.result" -local a = require "mason-core.async" -local fs = require "mason-core.fs" -local installer = require "mason-core.installer" -local match = require "luassert.match" -local path = require "mason-core.path" -local spy = require "luassert.spy" -local stub = require "luassert.stub" - -local function timestamp() - local seconds, microseconds = vim.loop.gettimeofday() - return (seconds * 1000) + math.floor(microseconds / 1000) -end - -describe("installer", function() - before_each(function() - package.loaded["dummy_package"] = nil - end) - - it( - "should call installer", - async_test(function() - spy.on(fs.async, "mkdirp") - spy.on(fs.async, "rename") - - local handle = InstallHandleGenerator "dummy" - spy.on(handle.package.spec.source, "install") - local result = installer.execute(handle, {}) - - assert.is_nil(result:err_or_nil()) - assert.spy(handle.package.spec.source.install).was_called(1) - assert - .spy(handle.package.spec.source.install) - .was_called_with(match.instanceof(InstallContext), match.is_table()) - assert.spy(fs.async.mkdirp).was_called_with(path.package_build_prefix "dummy") - assert.spy(fs.async.rename).was_called_with(path.package_build_prefix "dummy", path.package_prefix "dummy") - end) - ) - - it( - "should return failure if installer errors", - async_test(function() - spy.on(fs.async, "rmrf") - spy.on(fs.async, "rename") - local installer_fn = spy.new(function() - error("something went wrong. don't try again.", 0) - end) - local handler = InstallHandleGenerator "dummy" - stub(handler.package.spec.source, "install", installer_fn) - local result = installer.execute(handler, {}) - assert.spy(installer_fn).was_called(1) - assert.is_true(result:is_failure()) - assert.equals("something went wrong. don't try again.", result:err_or_nil()) - assert.spy(fs.async.rmrf).was_called_with(path.package_build_prefix "dummy") - assert.spy(fs.async.rename).was_not_called() - end) - ) - - it( - "should write receipt", - async_test(function() - spy.on(fs.async, "write_file") - local handle = InstallHandleGenerator "dummy" - stub(handle.package.spec.source, "install", function(ctx) - ctx.fs:write_file("target", "") - ctx.fs:write_file("file.jar", "") - ctx.fs:write_file("opt-cmd", "") - end) - handle.package.spec.bin = { - ["executable"] = "target", - } - handle.package.spec.share = { - ["package/file.jar"] = "file.jar", - } - handle.package.spec.opt = { - ["package/bin/opt-cmd"] = "opt-cmd", - } - installer.execute(handle, {}) - handle.package.spec.bin = {} - handle.package.spec.share = {} - handle.package.spec.opt = {} - assert.spy(fs.async.write_file).was_called_with( - ("%s/mason-receipt.json"):format(handle.package:get_install_path()), - match.capture(function(arg) - ---@type InstallReceipt - local receipt = vim.json.decode(arg) - assert.is_true(match.tbl_containing { - name = "dummy", - source = match.same { - type = handle.package.spec.schema, - id = handle.package.spec.source.id, - }, - schema_version = "1.2", - metrics = match.is_table(), - links = match.same { - bin = { executable = "target" }, - share = { ["package/file.jar"] = "file.jar" }, - opt = { ["package/bin/opt-cmd"] = "opt-cmd" }, - }, - }(receipt)) - end) - ) - end) - ) - - it( - "should run async functions concurrently", - async_test(function() - spy.on(fs.async, "write_file") - local capture = spy.new() - local start = timestamp() - local handle = InstallHandleGenerator "dummy" - stub(handle.package.spec.source, "install", function(ctx) - capture(installer.run_concurrently { - function() - a.sleep(100) - return installer.context() - end, - function() - a.sleep(100) - return "two" - end, - function() - a.sleep(100) - return "three" - end, - }) - end) - installer.execute(handle, {}) - local stop = timestamp() - local grace_ms = 25 - assert.is_true((stop - start) >= (100 - grace_ms)) - 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.source, "install", function(ctx) - ctx.stdio_sink.stdout "Hello stdout!\n" - ctx.stdio_sink.stderr "Hello " - ctx.stdio_sink.stderr "stderr!" - 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) - ) - - it( - "should raise spawn errors in strict mode", - async_test(function() - local handle = InstallHandleGenerator "dummy" - stub(handle.package.spec.source, "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) - ) - - it( - "should lock package", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local callback = spy.new() - stub(handle.package.spec.source, "install", function() - a.sleep(3000) - end) - - a.run(function() - return installer.execute(handle, { debug = true }) - end, callback) - - assert.wait_for(function() - assert.is_true(fs.sync.file_exists(path.package_lock "dummy")) - end) - handle:terminate() - assert.wait_for(function() - assert.spy(callback).was_called(1) - end) - assert.is_false(fs.sync.file_exists(path.package_lock "dummy")) - end) - ) - - it( - "should not run installer if package lock exists", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local install = spy.new() - stub(handle.package.spec.source, "install", install) - - fs.sync.write_file(path.package_lock "dummy", "dummypid") - local result = installer.execute(handle, { debug = true }) - assert.is_true(fs.sync.file_exists(path.package_lock "dummy")) - fs.sync.unlink(path.package_lock "dummy") - - assert.spy(install).was_not_called() - assert.equals( - "Lockfile exists, installation is already running in another process (pid: dummypid). Run with :MasonInstall --force to bypass.", - result:err_or_nil() - ) - end) - ) -end) diff --git a/tests/mason-core/installer/linker_spec.lua b/tests/mason-core/installer/linker_spec.lua index 8bcf2607..9684f57d 100644 --- a/tests/mason-core/installer/linker_spec.lua +++ b/tests/mason-core/installer/linker_spec.lua @@ -1,7 +1,9 @@ +local a = require "mason-core.async" local fs = require "mason-core.fs" local path = require "mason-core.path" local registry = require "mason-registry" local stub = require "luassert.stub" +local test_helpers = require "mason-test.helpers" local WIN_CMD_SCRIPT = [[@ECHO off GOTO start @@ -15,6 +17,16 @@ CALL :find_dp0 endLocal & goto #_undefined_# 2>NUL || title %%COMSPEC%% & "%s" %%*]] describe("linker", function() + local snapshot + + before_each(function() + snapshot = assert.snapshot() + end) + + after_each(function() + snapshot:revert() + end) + ---@module "mason-core.installer.linker" local linker ---@module "mason-core.platform" @@ -27,130 +39,119 @@ describe("linker", function() linker = require "mason-core.installer.linker" end) - it( - "should symlink executable on Unix", - async_test(function() - local dummy = registry.get_package "dummy" - stub(fs.async, "file_exists") - stub(fs.async, "symlink") - stub(fs.async, "write_file") + it("should symlink executable on Unix", function() + local dummy = registry.get_package "dummy" + stub(fs.async, "file_exists") + stub(fs.async, "symlink") + stub(fs.async, "write_file") - fs.async.file_exists.on_call_with(path.bin_prefix "my-executable").returns(false) - fs.async.file_exists.on_call_with(path.bin_prefix "another-executable").returns(false) - fs.async.file_exists - .on_call_with(path.concat { dummy:get_install_path(), "nested", "path", "my-executable" }) - .returns(true) - fs.async.file_exists - .on_call_with(path.concat { dummy:get_install_path(), "another-executable" }) - .returns(true) + fs.async.file_exists.on_call_with(path.bin_prefix "my-executable").returns(false) + fs.async.file_exists.on_call_with(path.bin_prefix "another-executable").returns(false) + fs.async.file_exists + .on_call_with(path.concat { dummy:get_install_path(), "nested", "path", "my-executable" }) + .returns(true) + fs.async.file_exists.on_call_with(path.concat { dummy:get_install_path(), "another-executable" }).returns(true) - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) - ctx:link_bin("my-executable", path.concat { "nested", "path", "my-executable" }) - ctx:link_bin("another-executable", "another-executable") - assert.is_true(linker.link(ctx):is_success()) + local ctx = test_helpers.create_context() + ctx:link_bin("my-executable", path.concat { "nested", "path", "my-executable" }) + ctx:link_bin("another-executable", "another-executable") + local result = a.run_blocking(linker.link, ctx) + assert.is_true(result:is_success()) - assert.spy(fs.async.write_file).was_called(0) - assert.spy(fs.async.symlink).was_called(2) - assert - .spy(fs.async.symlink) - .was_called_with(path.concat { dummy:get_install_path(), "another-executable" }, path.bin_prefix "another-executable") - assert.spy(fs.async.symlink).was_called_with( + assert.spy(fs.async.write_file).was_called(0) + assert.spy(fs.async.symlink).was_called(2) + assert + .spy(fs.async.symlink) + .was_called_with(path.concat { dummy:get_install_path(), "another-executable" }, path.bin_prefix "another-executable") + assert + .spy(fs.async.symlink) + .was_called_with( path.concat { dummy:get_install_path(), "nested", "path", "my-executable" }, path.bin_prefix "my-executable" ) - end) - ) + end) - it( - "should write executable wrapper on Windows", - async_test(function() - platform.is.darwin = false - platform.is.mac = false - platform.is.linux = false - platform.is.unix = false - platform.is.win = true + it("should write executable wrapper on Windows", function() + platform.is.darwin = false + platform.is.mac = false + platform.is.linux = false + platform.is.unix = false + platform.is.win = true - local dummy = registry.get_package "dummy" - stub(fs.async, "file_exists") - stub(fs.async, "symlink") - stub(fs.async, "write_file") + local dummy = registry.get_package "dummy" + stub(fs.async, "file_exists") + stub(fs.async, "symlink") + stub(fs.async, "write_file") - fs.async.file_exists.on_call_with(path.bin_prefix "my-executable").returns(false) - fs.async.file_exists.on_call_with(path.bin_prefix "another-executable").returns(false) - fs.async.file_exists - .on_call_with(path.concat { dummy:get_install_path(), "nested", "path", "my-executable" }) - .returns(true) - fs.async.file_exists - .on_call_with(path.concat { dummy:get_install_path(), "another-executable" }) - .returns(true) + fs.async.file_exists.on_call_with(path.bin_prefix "my-executable").returns(false) + fs.async.file_exists.on_call_with(path.bin_prefix "another-executable").returns(false) + fs.async.file_exists + .on_call_with(path.concat { dummy:get_install_path(), "nested", "path", "my-executable" }) + .returns(true) + fs.async.file_exists.on_call_with(path.concat { dummy:get_install_path(), "another-executable" }).returns(true) - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) - ctx:link_bin("my-executable", path.concat { "nested", "path", "my-executable" }) - ctx:link_bin("another-executable", "another-executable") - assert.is_true(linker.link(ctx):is_success()) + local ctx = test_helpers.create_context() + ctx:link_bin("my-executable", path.concat { "nested", "path", "my-executable" }) + ctx:link_bin("another-executable", "another-executable") - assert.spy(fs.async.symlink).was_called(0) - assert.spy(fs.async.write_file).was_called(2) - assert.spy(fs.async.write_file).was_called_with( - path.bin_prefix "another-executable.cmd", - WIN_CMD_SCRIPT:format(path.concat { dummy:get_install_path(), "another-executable" }) - ) - assert.spy(fs.async.write_file).was_called_with( - path.bin_prefix "my-executable.cmd", - WIN_CMD_SCRIPT:format(path.concat { dummy:get_install_path(), "nested", "path", "my-executable" }) - ) - end) - ) + local result = a.run_blocking(linker.link, ctx) + assert.is_true(result:is_success()) - it( - "should symlink share files", - async_test(function() - local dummy = registry.get_package "dummy" - stub(fs.async, "mkdirp") - stub(fs.async, "dir_exists") - stub(fs.async, "file_exists") - stub(fs.async, "symlink") - stub(fs.async, "write_file") + assert.spy(fs.async.symlink).was_called(0) + assert.spy(fs.async.write_file).was_called(2) + assert.spy(fs.async.write_file).was_called_with( + path.bin_prefix "another-executable.cmd", + WIN_CMD_SCRIPT:format(path.concat { dummy:get_install_path(), "another-executable" }) + ) + assert.spy(fs.async.write_file).was_called_with( + path.bin_prefix "my-executable.cmd", + WIN_CMD_SCRIPT:format(path.concat { dummy:get_install_path(), "nested", "path", "my-executable" }) + ) + end) - -- mock non-existent dest files - fs.async.file_exists.on_call_with(path.share_prefix "share-file").returns(false) - fs.async.file_exists.on_call_with(path.share_prefix(path.concat { "nested", "share-file" })).returns(false) + it("should symlink share files", function() + local dummy = registry.get_package "dummy" + stub(fs.async, "mkdirp") + stub(fs.async, "dir_exists") + stub(fs.async, "file_exists") + stub(fs.async, "symlink") + stub(fs.async, "write_file") - fs.async.dir_exists.on_call_with(path.share_prefix()).returns(false) - fs.async.dir_exists.on_call_with(path.share_prefix "nested/path").returns(false) + -- mock non-existent dest files + fs.async.file_exists.on_call_with(path.share_prefix "share-file").returns(false) + fs.async.file_exists.on_call_with(path.share_prefix(path.concat { "nested", "share-file" })).returns(false) - -- mock existent source files - fs.async.file_exists.on_call_with(path.concat { dummy:get_install_path(), "share-file" }).returns(true) - fs.async.file_exists - .on_call_with(path.concat { dummy:get_install_path(), "nested", "path", "to", "share-file" }) - .returns(true) + fs.async.dir_exists.on_call_with(path.share_prefix()).returns(false) + fs.async.dir_exists.on_call_with(path.share_prefix "nested/path").returns(false) - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) - ctx.links.share["nested/path/share-file"] = path.concat { "nested", "path", "to", "share-file" } - ctx.links.share["share-file"] = "share-file" + -- mock existent source files + fs.async.file_exists.on_call_with(path.concat { dummy:get_install_path(), "share-file" }).returns(true) + fs.async.file_exists + .on_call_with(path.concat { dummy:get_install_path(), "nested", "path", "to", "share-file" }) + .returns(true) - local result = linker.link(ctx) + local ctx = test_helpers.create_context() + ctx.links.share["nested/path/share-file"] = path.concat { "nested", "path", "to", "share-file" } + ctx.links.share["share-file"] = "share-file" - assert.is_true(result:is_success()) + local result = a.run_blocking(linker.link, ctx) - assert.spy(fs.async.write_file).was_called(0) - assert.spy(fs.async.symlink).was_called(2) - assert - .spy(fs.async.symlink) - .was_called_with(path.concat { dummy:get_install_path(), "share-file" }, path.share_prefix "share-file") - assert.spy(fs.async.symlink).was_called_with( - path.concat { dummy:get_install_path(), "nested", "path", "to", "share-file" }, - path.share_prefix "nested/path/share-file" - ) + assert.is_true(result:is_success()) - assert.spy(fs.async.mkdirp).was_called(2) - assert.spy(fs.async.mkdirp).was_called_with(path.share_prefix()) - assert.spy(fs.async.mkdirp).was_called_with(path.share_prefix "nested/path") - end) - ) + assert.spy(fs.async.write_file).was_called(0) + assert.spy(fs.async.symlink).was_called(2) + assert + .spy(fs.async.symlink) + .was_called_with(path.concat { dummy:get_install_path(), "share-file" }, path.share_prefix "share-file") + assert.spy(fs.async.symlink).was_called_with( + path.concat { dummy:get_install_path(), "nested", "path", "to", "share-file" }, + path.share_prefix "nested/path/share-file" + ) + + assert.spy(fs.async.mkdirp).was_called(2) + assert.spy(fs.async.mkdirp).was_called_with(path.share_prefix()) + assert.spy(fs.async.mkdirp).was_called_with(path.share_prefix "nested/path") + end) it("should copy share files on Windows", function() platform.is.darwin = false @@ -178,8 +179,7 @@ describe("linker", function() .on_call_with(path.concat { dummy:get_install_path(), "nested", "path", "to", "share-file" }) .returns(true) - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) + local ctx = test_helpers.create_context() ctx.links.share["nested/path/share-file"] = path.concat { "nested", "path", "to", "share-file" } ctx.links.share["share-file"] = "share-file" diff --git a/tests/mason-core/installer/managers/cargo_spec.lua b/tests/mason-core/installer/managers/cargo_spec.lua index 475c2c86..bc5c5f21 100644 --- a/tests/mason-core/installer/managers/cargo_spec.lua +++ b/tests/mason-core/installer/managers/cargo_spec.lua @@ -1,12 +1,12 @@ local cargo = require "mason-core.installer.managers.cargo" -local installer = require "mason-core.installer" local spy = require "luassert.spy" +local test_helpers = require "mason-test.helpers" describe("cargo manager", function() it("should install", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() - installer.exec_in_context(ctx, function() + ctx:execute(function() cargo.install("my-crate", "1.0.0") end) @@ -23,10 +23,10 @@ describe("cargo manager", function() end) it("should write output", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() spy.on(ctx.stdio_sink, "stdout") - installer.exec_in_context(ctx, function() + ctx:execute(function() cargo.install("my-crate", "1.0.0") end) @@ -34,8 +34,8 @@ describe("cargo manager", function() end) it("should install locked", function() - local ctx = create_dummy_context() - installer.exec_in_context(ctx, function() + local ctx = test_helpers.create_context() + ctx:execute(function() cargo.install("my-crate", "1.0.0", { locked = true, }) @@ -54,8 +54,8 @@ describe("cargo manager", function() end) it("should install provided features", function() - local ctx = create_dummy_context() - installer.exec_in_context(ctx, function() + local ctx = test_helpers.create_context() + ctx:execute(function() cargo.install("my-crate", "1.0.0", { features = "lsp,cli", }) @@ -74,8 +74,8 @@ describe("cargo manager", function() end) it("should install git tag source", function() - local ctx = create_dummy_context() - installer.exec_in_context(ctx, function() + local ctx = test_helpers.create_context() + ctx:execute(function() cargo.install("my-crate", "1.0.0", { git = { url = "https://github.com/neovim/neovim", @@ -96,8 +96,8 @@ describe("cargo manager", function() end) it("should install git rev source", function() - local ctx = create_dummy_context() - installer.exec_in_context(ctx, function() + local ctx = test_helpers.create_context() + ctx:execute(function() cargo.install("my-crate", "16dfc89abd413c391e5b63ae5d132c22843ce9a7", { git = { url = "https://github.com/neovim/neovim", diff --git a/tests/mason-core/installer/managers/common_spec.lua b/tests/mason-core/installer/managers/common_spec.lua index e72d7697..16d3ba52 100644 --- a/tests/mason-core/installer/managers/common_spec.lua +++ b/tests/mason-core/installer/managers/common_spec.lua @@ -7,6 +7,7 @@ local mock = require "luassert.mock" local spy = require "luassert.spy" local std = require "mason-core.installer.managers.std" local stub = require "luassert.stub" +local test_helpers = require "mason-test.helpers" describe("common manager :: download", function() it("should parse download files from common structure", function() @@ -54,11 +55,11 @@ describe("common manager :: download", function() end) it("should download files", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() stub(std, "download_file", mockx.returns(Result.success())) stub(std, "unpack", mockx.returns(Result.success())) - local result = installer.exec_in_context(ctx, function() + local result = ctx:execute(function() return common.download_files(ctx, { { out_file = "file.jar", download_url = "https://example.com/file.jar" }, { out_file = "LICENSE.md", download_url = "https://example.com/LICENSE" }, @@ -75,12 +76,12 @@ describe("common manager :: download", function() end) it("should download files to specified directory", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() stub(std, "download_file", mockx.returns(Result.success())) stub(std, "unpack", mockx.returns(Result.success())) stub(ctx.fs, "mkdirp") - local result = installer.exec_in_context(ctx, function() + local result = ctx:execute(function() return common.download_files(ctx, { { out_file = "lib/file.jar", download_url = "https://example.com/file.jar" }, { out_file = "doc/LICENSE.md", download_url = "https://example.com/LICENSE" }, @@ -99,7 +100,7 @@ end) describe("common manager :: build", function() it("should run build instruction", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() local uv = require "mason-core.async.uv" spy.on(ctx, "promote_cwd") stub(uv, "write") @@ -115,7 +116,7 @@ describe("common manager :: build", function() end ) - local result = installer.exec_in_context(ctx, function() + local result = ctx:execute(function() return common.run_build_instruction { run = [[npm install && npm run compile]], env = { @@ -143,11 +144,11 @@ describe("common manager :: build", function() end) it("should promote cwd if not staged", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() stub(ctx, "promote_cwd") stub(ctx.spawn, "bash", mockx.returns(Result.success())) - local result = installer.exec_in_context(ctx, function() + local result = ctx:execute(function() return common.run_build_instruction { run = "make", staged = false, diff --git a/tests/mason-core/installer/managers/composer_spec.lua b/tests/mason-core/installer/managers/composer_spec.lua index a8ccaffb..f3887c68 100644 --- a/tests/mason-core/installer/managers/composer_spec.lua +++ b/tests/mason-core/installer/managers/composer_spec.lua @@ -1,11 +1,11 @@ local composer = require "mason-core.installer.managers.composer" -local installer = require "mason-core.installer" local spy = require "luassert.spy" +local test_helpers = require "mason-test.helpers" describe("composer manager", function() it("should install", function() - local ctx = create_dummy_context() - installer.exec_in_context(ctx, function() + local ctx = test_helpers.create_context() + ctx:execute(function() composer.install("my-package", "1.0.0") end) @@ -22,10 +22,10 @@ describe("composer manager", function() end) it("should write output", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() spy.on(ctx.stdio_sink, "stdout") - installer.exec_in_context(ctx, function() + ctx:execute(function() composer.install("my-package", "1.0.0") end) diff --git a/tests/mason-core/installer/managers/gem_spec.lua b/tests/mason-core/installer/managers/gem_spec.lua index 7ac8c33e..83b8d96a 100644 --- a/tests/mason-core/installer/managers/gem_spec.lua +++ b/tests/mason-core/installer/managers/gem_spec.lua @@ -1,13 +1,15 @@ local gem = require "mason-core.installer.managers.gem" -local installer = require "mason-core.installer" local spy = require "luassert.spy" +local test_helper = require "mason-test.helpers" describe("gem manager", function() it("should install", function() - local ctx = create_dummy_context() - installer.exec_in_context(ctx, function() - gem.install("my-gem", "1.0.0") + local ctx = test_helper.create_context() + + local result = ctx:execute(function() + return gem.install("my-gem", "1.0.0") end) + assert.is_true(result:is_success()) assert.spy(ctx.spawn.gem).was_called(1) assert.spy(ctx.spawn.gem).was_called_with { @@ -20,15 +22,15 @@ describe("gem manager", function() "my-gem:1.0.0", vim.NIL, -- extra_packages env = { - GEM_HOME = ctx.cwd:get(), + GEM_HOME = "/tmp/install-dir", }, } end) it("should write output", function() - local ctx = create_dummy_context() + local ctx = test_helper.create_context() spy.on(ctx.stdio_sink, "stdout") - installer.exec_in_context(ctx, function() + ctx:execute(function() gem.install("my-gem", "1.0.0") end) @@ -36,8 +38,8 @@ describe("gem manager", function() end) it("should install extra packages", function() - local ctx = create_dummy_context() - installer.exec_in_context(ctx, function() + local ctx = test_helper.create_context() + ctx:execute(function() gem.install("my-gem", "1.0.0", { extra_packages = { "extra-gem" }, }) diff --git a/tests/mason-core/installer/managers/golang_spec.lua b/tests/mason-core/installer/managers/golang_spec.lua index 58e4c4b8..e1a99cbd 100644 --- a/tests/mason-core/installer/managers/golang_spec.lua +++ b/tests/mason-core/installer/managers/golang_spec.lua @@ -1,12 +1,12 @@ local golang = require "mason-core.installer.managers.golang" -local installer = require "mason-core.installer" local spy = require "luassert.spy" +local test_helpers = require "mason-test.helpers" describe("golang manager", function() it("should install", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() - installer.exec_in_context(ctx, function() + ctx:execute(function() golang.install("my-golang", "1.0.0") end) @@ -22,10 +22,10 @@ describe("golang manager", function() end) it("should write output", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() spy.on(ctx.stdio_sink, "stdout") - installer.exec_in_context(ctx, function() + ctx:execute(function() golang.install("my-golang", "1.0.0") end) @@ -33,8 +33,8 @@ describe("golang manager", function() end) it("should install extra packages", function() - local ctx = create_dummy_context() - installer.exec_in_context(ctx, function() + local ctx = test_helpers.create_context() + ctx:execute(function() golang.install("my-golang", "1.0.0", { extra_packages = { "extra", "package" }, }) diff --git a/tests/mason-core/installer/managers/luarocks_spec.lua b/tests/mason-core/installer/managers/luarocks_spec.lua index 3be963a8..406c5c51 100644 --- a/tests/mason-core/installer/managers/luarocks_spec.lua +++ b/tests/mason-core/installer/managers/luarocks_spec.lua @@ -1,13 +1,23 @@ -local installer = require "mason-core.installer" local luarocks = require "mason-core.installer.managers.luarocks" local spy = require "luassert.spy" local stub = require "luassert.stub" +local test_helpers = require "mason-test.helpers" describe("luarocks manager", function() + local snapshot + + before_each(function() + snapshot = assert.snapshot() + end) + + after_each(function() + snapshot:revert() + end) + it("should install", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() stub(ctx, "promote_cwd") - installer.exec_in_context(ctx, function() + ctx:execute(function() luarocks.install("my-rock", "1.0.0") end) @@ -23,9 +33,9 @@ describe("luarocks manager", function() end) it("should install dev mode", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() stub(ctx, "promote_cwd") - installer.exec_in_context(ctx, function() + ctx:execute(function() luarocks.install("my-rock", "1.0.0", { dev = true, }) @@ -43,9 +53,9 @@ describe("luarocks manager", function() end) it("should install using provided server", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() stub(ctx, "promote_cwd") - installer.exec_in_context(ctx, function() + ctx:execute(function() luarocks.install("my-rock", "1.0.0", { server = "https://luarocks.org/dev", }) @@ -63,10 +73,10 @@ describe("luarocks manager", function() end) it("should write output", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() stub(ctx, "promote_cwd") spy.on(ctx.stdio_sink, "stdout") - installer.exec_in_context(ctx, function() + ctx:execute(function() luarocks.install("my-rock", "1.0.0") end) diff --git a/tests/mason-core/installer/managers/npm_spec.lua b/tests/mason-core/installer/managers/npm_spec.lua index 59a8c84f..b2fabc80 100644 --- a/tests/mason-core/installer/managers/npm_spec.lua +++ b/tests/mason-core/installer/managers/npm_spec.lua @@ -1,21 +1,31 @@ local Result = require "mason-core.result" -local installer = require "mason-core.installer" local match = require "luassert.match" local npm = require "mason-core.installer.managers.npm" local spawn = require "mason-core.spawn" local spy = require "luassert.spy" local stub = require "luassert.stub" +local test_helpers = require "mason-test.helpers" describe("npm manager", function() + local snapshot + + before_each(function() + snapshot = assert.snapshot() + end) + + after_each(function() + snapshot:revert() + end) + it("should init package.json", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() stub(ctx.fs, "append_file") stub(spawn, "npm") spawn.npm.returns(Result.success {}) spawn.npm.on_call_with({ "version", "--json" }).returns(Result.success { stdout = [[ { "npm": "8.1.0" } ]], }) - installer.exec_in_context(ctx, function() + ctx:execute(function() npm.init() end) @@ -30,14 +40,14 @@ describe("npm manager", function() end) it("should use install-strategy on npm >= 9", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() stub(ctx.fs, "append_file") stub(spawn, "npm") spawn.npm.returns(Result.success {}) spawn.npm.on_call_with({ "version", "--json" }).returns(Result.success { stdout = [[ { "npm": "9.1.0" } ]], }) - installer.exec_in_context(ctx, function() + ctx:execute(function() npm.init() end) @@ -51,8 +61,8 @@ describe("npm manager", function() end) it("should install", function() - local ctx = create_dummy_context() - installer.exec_in_context(ctx, function() + local ctx = test_helpers.create_context() + ctx:execute(function() npm.install("my-package", "1.0.0") end) @@ -65,8 +75,8 @@ describe("npm manager", function() end) it("should install extra packages", function() - local ctx = create_dummy_context() - installer.exec_in_context(ctx, function() + local ctx = test_helpers.create_context() + ctx:execute(function() npm.install("my-package", "1.0.0", { extra_packages = { "extra-package" }, }) @@ -81,10 +91,10 @@ describe("npm manager", function() end) it("should write output", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() spy.on(ctx.stdio_sink, "stdout") - installer.exec_in_context(ctx, function() + ctx:execute(function() npm.install("my-package", "1.0.0") end) diff --git a/tests/mason-core/installer/managers/nuget_spec.lua b/tests/mason-core/installer/managers/nuget_spec.lua index 8d4b0e87..fdfbdc82 100644 --- a/tests/mason-core/installer/managers/nuget_spec.lua +++ b/tests/mason-core/installer/managers/nuget_spec.lua @@ -1,11 +1,11 @@ -local installer = require "mason-core.installer" local nuget = require "mason-core.installer.managers.nuget" local spy = require "luassert.spy" +local test_helpers = require "mason-test.helpers" describe("nuget manager", function() it("should install", function() - local ctx = create_dummy_context() - installer.exec_in_context(ctx, function() + local ctx = test_helpers.create_context() + ctx:execute(function() nuget.install("nuget-package", "1.0.0") end) @@ -21,10 +21,10 @@ describe("nuget manager", function() end) it("should write output", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() spy.on(ctx.stdio_sink, "stdout") - installer.exec_in_context(ctx, function() + ctx:execute(function() nuget.install("nuget-package", "1.0.0") end) diff --git a/tests/mason-core/installer/managers/opam_spec.lua b/tests/mason-core/installer/managers/opam_spec.lua index cc552114..51f116e8 100644 --- a/tests/mason-core/installer/managers/opam_spec.lua +++ b/tests/mason-core/installer/managers/opam_spec.lua @@ -1,12 +1,12 @@ -local installer = require "mason-core.installer" local opam = require "mason-core.installer.managers.opam" local spy = require "luassert.spy" +local test_helpers = require "mason-test.helpers" describe("opam manager", function() it("should install", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() - installer.exec_in_context(ctx, function() + ctx:execute(function() opam.install("opam-package", "1.0.0") end) @@ -21,10 +21,10 @@ describe("opam manager", function() end) it("should write output", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() spy.on(ctx.stdio_sink, "stdout") - installer.exec_in_context(ctx, function() + ctx:execute(function() opam.install("opam-package", "1.0.0") end) diff --git a/tests/mason-core/installer/managers/powershell_spec.lua b/tests/mason-core/installer/managers/powershell_spec.lua index 86bbe1f9..14478305 100644 --- a/tests/mason-core/installer/managers/powershell_spec.lua +++ b/tests/mason-core/installer/managers/powershell_spec.lua @@ -1,3 +1,4 @@ +local a = require "mason-core.async" local match = require "luassert.match" local mock = require "luassert.mock" local spawn = require "mason-core.spawn" @@ -5,6 +6,16 @@ local spy = require "luassert.spy" local stub = require "luassert.stub" describe("powershell manager", function() + local snapshot + + before_each(function() + snapshot = assert.snapshot() + end) + + after_each(function() + snapshot:revert() + end) + local function powershell() package.loaded["mason-core.installer.managers.powershell"] = nil return require "mason-core.installer.managers.powershell" @@ -22,21 +33,18 @@ describe("powershell manager", function() assert.spy(spawn.powershell).was_called(0) end) - it( - "should use powershell if pwsh is not available", - async_test(function() - stub(spawn, "pwsh", function() end) - stub(spawn, "powershell", function() end) - stub(vim.fn, "executable") - vim.fn.executable.on_call_with("pwsh").returns(0) + it("should use powershell if pwsh is not available", function() + stub(spawn, "pwsh", function() end) + stub(spawn, "powershell", function() end) + stub(vim.fn, "executable") + vim.fn.executable.on_call_with("pwsh").returns(0) - local powershell = powershell() - powershell.command "echo 'Is this bash?'" + local powershell = powershell() + a.run_blocking(powershell.command, "echo 'Is this bash?'") - assert.spy(spawn.pwsh).was_called(0) - assert.spy(spawn.powershell).was_called(1) - end) - ) + assert.spy(spawn.pwsh).was_called(0) + assert.spy(spawn.powershell).was_called(1) + end) it("should use the provided spawner for commands", function() spy.on(spawn, "pwsh") diff --git a/tests/mason-core/installer/managers/pypi_spec.lua b/tests/mason-core/installer/managers/pypi_spec.lua index 6689e350..f3a7e429 100644 --- a/tests/mason-core/installer/managers/pypi_spec.lua +++ b/tests/mason-core/installer/managers/pypi_spec.lua @@ -1,5 +1,4 @@ local Result = require "mason-core.result" -local installer = require "mason-core.installer" local match = require "luassert.match" local path = require "mason-core.path" local providers = require "mason-core.providers" @@ -7,6 +6,7 @@ local pypi = require "mason-core.installer.managers.pypi" local spawn = require "mason-core.spawn" local spy = require "luassert.spy" local stub = require "luassert.stub" +local test_helpers = require "mason-test.helpers" ---@param ctx InstallContext local function venv_py(ctx) @@ -19,17 +19,24 @@ local function venv_py(ctx) end describe("pypi manager", function() + local snapshot + before_each(function() + snapshot = assert.snapshot() stub(spawn, "python3", mockx.returns(Result.success())) spawn.python3.on_call_with({ "--version" }).returns(Result.success { stdout = "Python 3.11.0" }) end) + after_each(function() + snapshot:revert() + end) + it("should init venv without upgrading pip", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() stub(ctx, "promote_cwd") stub(providers.pypi, "get_supported_python_versions", mockx.returns(Result.failure())) - installer.exec_in_context(ctx, function() + ctx:execute(function() pypi.init { package = { name = "cmake-language-server", version = "0.1.10" }, upgrade_pip = false } end) @@ -44,13 +51,13 @@ describe("pypi manager", function() end) it("should init venv and upgrade pip", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() stub(ctx, "promote_cwd") stub(ctx.fs, "file_exists") stub(providers.pypi, "get_supported_python_versions", mockx.returns(Result.failure())) ctx.fs.file_exists.on_call_with(match.ref(ctx.fs), "venv/bin/python").returns(true) - installer.exec_in_context(ctx, function() + ctx:execute(function() pypi.init { package = { name = "cmake-language-server", version = "0.1.10" }, upgrade_pip = true, @@ -80,7 +87,7 @@ describe("pypi manager", function() end) it("should find versioned candidates during init", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() stub(ctx, "promote_cwd") stub(ctx.fs, "file_exists") stub(providers.pypi, "get_supported_python_versions", mockx.returns(Result.success ">=3.12")) @@ -90,7 +97,7 @@ describe("pypi manager", function() spawn["python3.12"].on_call_with({ "--version" }).returns(Result.success { stdout = "Python 3.12.0" }) ctx.fs.file_exists.on_call_with(match.ref(ctx.fs), "venv/bin/python").returns(true) - installer.exec_in_context(ctx, function() + ctx:execute(function() pypi.init { package = { name = "cmake-language-server", version = "0.1.10" }, upgrade_pip = false, @@ -109,7 +116,7 @@ describe("pypi manager", function() end) it("should error if unable to find a suitable python3 version", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() spy.on(ctx.stdio_sink, "stderr") stub(ctx, "promote_cwd") stub(ctx.fs, "file_exists") @@ -123,7 +130,7 @@ describe("pypi manager", function() stub(spawn, "python3", mockx.returns(Result.success())) spawn.python3.on_call_with({ "--version" }).returns(Result.success { stdout = "Python 3.5.0" }) - local result = installer.exec_in_context(ctx, function() + local result = ctx:execute(function() return pypi.init { package = { name = "cmake-language-server", version = "0.1.10" }, upgrade_pip = false, @@ -143,7 +150,7 @@ describe("pypi manager", function() it( "should default to stock version if unable to find suitable versioned candidate during init and when force=true", function() - local ctx = create_dummy_context { force = true } + local ctx = test_helpers.create_context { install_opts = { force = true } } spy.on(ctx.stdio_sink, "stderr") stub(ctx, "promote_cwd") stub(ctx.fs, "file_exists") @@ -157,7 +164,7 @@ describe("pypi manager", function() stub(spawn, "python3", mockx.returns(Result.success())) spawn.python3.on_call_with({ "--version" }).returns(Result.success { stdout = "Python 3.5.0" }) - installer.exec_in_context(ctx, function() + ctx:execute(function() pypi.init { package = { name = "cmake-language-server", version = "0.1.10" }, upgrade_pip = true, @@ -180,7 +187,7 @@ describe("pypi manager", function() ) it("should prioritize stock python", function() - local ctx = create_dummy_context { force = true } + local ctx = test_helpers.create_context { install_opts = { force = true } } spy.on(ctx.stdio_sink, "stderr") stub(ctx, "promote_cwd") stub(ctx.fs, "file_exists") @@ -190,7 +197,7 @@ describe("pypi manager", function() stub(spawn, "python3", mockx.returns(Result.success())) spawn.python3.on_call_with({ "--version" }).returns(Result.success { stdout = "Python 3.8.0" }) - installer.exec_in_context(ctx, function() + ctx:execute(function() pypi.init { package = { name = "cmake-language-server", version = "0.1.10" }, upgrade_pip = true, @@ -210,10 +217,11 @@ describe("pypi manager", function() end) it("should install", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() stub(ctx.fs, "file_exists") ctx.fs.file_exists.on_call_with(match.ref(ctx.fs), "venv/bin/python").returns(true) - installer.exec_in_context(ctx, function() + + ctx:execute(function() pypi.install("pypi-package", "1.0.0") end) @@ -234,12 +242,12 @@ describe("pypi manager", function() end) it("should write output", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() stub(ctx.fs, "file_exists") ctx.fs.file_exists.on_call_with(match.ref(ctx.fs), "venv/bin/python").returns(true) spy.on(ctx.stdio_sink, "stdout") - installer.exec_in_context(ctx, function() + ctx:execute(function() pypi.install("pypi-package", "1.0.0") end) @@ -247,11 +255,11 @@ describe("pypi manager", function() end) it("should install extra specifier", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() stub(ctx.fs, "file_exists") ctx.fs.file_exists.on_call_with(match.ref(ctx.fs), "venv/bin/python").returns(true) - installer.exec_in_context(ctx, function() + ctx:execute(function() pypi.install("pypi-package", "1.0.0", { extra = "lsp", }) @@ -274,10 +282,10 @@ describe("pypi manager", function() end) it("should install extra packages", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() stub(ctx.fs, "file_exists") ctx.fs.file_exists.on_call_with(match.ref(ctx.fs), "venv/bin/python").returns(true) - installer.exec_in_context(ctx, function() + ctx:execute(function() pypi.install("pypi-package", "1.0.0", { extra_packages = { "extra-package" }, install_extra_args = { "--proxy", "http://localhost:9000" }, diff --git a/tests/mason-core/installer/managers/std_spec.lua b/tests/mason-core/installer/managers/std_spec.lua index dea342bc..20caac18 100644 --- a/tests/mason-core/installer/managers/std_spec.lua +++ b/tests/mason-core/installer/managers/std_spec.lua @@ -1,12 +1,22 @@ -local installer = require "mason-core.installer" local match = require "luassert.match" local std = require "mason-core.installer.managers.std" local stub = require "luassert.stub" +local test_helpers = require "mason-test.helpers" describe("std unpack [Unix]", function() + local snapshot + + before_each(function() + snapshot = assert.snapshot() + end) + + after_each(function() + snapshot:revert() + end) + it("should unpack .gz", function() - local ctx = create_dummy_context() - installer.exec_in_context(ctx, function() + local ctx = test_helpers.create_context() + ctx:execute(function() std.unpack "file.gz" end) @@ -21,12 +31,12 @@ describe("std unpack [Unix]", function() end) it("should use gtar if available", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() stub(ctx.fs, "unlink") stub(vim.fn, "executable") vim.fn.executable.on_call_with("gtar").returns(1) - installer.exec_in_context(ctx, function() + ctx:execute(function() std.unpack "file.tar.gz" end) @@ -35,9 +45,9 @@ describe("std unpack [Unix]", function() end) it("should unpack .tar", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() stub(ctx.fs, "unlink") - installer.exec_in_context(ctx, function() + ctx:execute(function() std.unpack "file.tar" end) @@ -48,9 +58,9 @@ describe("std unpack [Unix]", function() end) it("should unpack .tar.bz2", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() stub(ctx.fs, "unlink") - installer.exec_in_context(ctx, function() + ctx:execute(function() std.unpack "file.tar.bz2" end) @@ -61,9 +71,9 @@ describe("std unpack [Unix]", function() end) it("should unpack .tar.gz", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() stub(ctx.fs, "unlink") - installer.exec_in_context(ctx, function() + ctx:execute(function() std.unpack "file.tar.gz" end) @@ -74,9 +84,9 @@ describe("std unpack [Unix]", function() end) it("should unpack .tar.xz", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() stub(ctx.fs, "unlink") - installer.exec_in_context(ctx, function() + ctx:execute(function() std.unpack "file.tar.xz" end) @@ -87,9 +97,9 @@ describe("std unpack [Unix]", function() end) it("should unpack .tar.zst", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() stub(ctx.fs, "unlink") - installer.exec_in_context(ctx, function() + ctx:execute(function() std.unpack "file.tar.zst" end) @@ -101,9 +111,9 @@ describe("std unpack [Unix]", function() end) it("should unpack .vsix", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() stub(ctx.fs, "unlink") - installer.exec_in_context(ctx, function() + ctx:execute(function() std.unpack "file.vsix" end) @@ -114,9 +124,9 @@ describe("std unpack [Unix]", function() end) it("should unpack .zip", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() stub(ctx.fs, "unlink") - installer.exec_in_context(ctx, function() + ctx:execute(function() std.unpack "file.zip" end) @@ -129,8 +139,8 @@ end) describe("std clone", function() it("should clone", function() - local ctx = create_dummy_context() - installer.exec_in_context(ctx, function() + local ctx = test_helpers.create_context() + ctx:execute(function() std.clone "https://github.com/williamboman/mason.nvim" end) @@ -146,8 +156,8 @@ describe("std clone", function() end) it("should clone and checkout rev", function() - local ctx = create_dummy_context() - installer.exec_in_context(ctx, function() + local ctx = test_helpers.create_context() + ctx:execute(function() std.clone("https://github.com/williamboman/mason.nvim", { rev = "e1fd03b1856cb5ad8425f49e18353dc524b02f91", recursive = true, diff --git a/tests/mason-core/installer/registry/providers/cargo_spec.lua b/tests/mason-core/installer/registry/compilers/cargo_spec.lua index 1bdad5f4..69ac446d 100644 --- a/tests/mason-core/installer/registry/providers/cargo_spec.lua +++ b/tests/mason-core/installer/registry/compilers/cargo_spec.lua @@ -1,9 +1,9 @@ local Purl = require "mason-core.purl" local Result = require "mason-core.result" -local cargo = require "mason-core.installer.registry.providers.cargo" -local installer = require "mason-core.installer" +local cargo = require "mason-core.installer.compiler.compilers.cargo" local providers = require "mason-core.providers" local stub = require "luassert.stub" +local test_helpers = require "mason-test.helpers" ---@param overrides Purl local function purl(overrides) @@ -94,12 +94,22 @@ describe("cargo provider :: parsing", function() end) describe("cargo provider :: installing", function() + local snapshot + + before_each(function() + snapshot = assert.snapshot() + end) + + after_each(function() + snapshot:revert() + end) + it("should install cargo packages", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() local manager = require "mason-core.installer.managers.cargo" stub(manager, "install", mockx.returns(Result.success())) - local result = installer.exec_in_context(ctx, function() + local result = ctx:execute(function() return cargo.install(ctx, { crate = "crate-name", version = "1.2.0", @@ -120,6 +130,16 @@ describe("cargo provider :: installing", function() end) describe("cargo provider :: versions", function() + local snapshot + + before_each(function() + snapshot = assert.snapshot() + end) + + after_each(function() + snapshot:revert() + end) + it("should recognize github cargo source", function() stub(providers.github, "get_all_tags", function() return Result.success { "1.0.0", "2.0.0", "3.0.0" } diff --git a/tests/mason-core/installer/registry/providers/composer_spec.lua b/tests/mason-core/installer/registry/compilers/composer_spec.lua index 8b771ff9..c184adf5 100644 --- a/tests/mason-core/installer/registry/providers/composer_spec.lua +++ b/tests/mason-core/installer/registry/compilers/composer_spec.lua @@ -1,8 +1,8 @@ local Purl = require "mason-core.purl" local Result = require "mason-core.result" -local composer = require "mason-core.installer.registry.providers.composer" -local installer = require "mason-core.installer" +local composer = require "mason-core.installer.compiler.compilers.composer" local stub = require "luassert.stub" +local test_helpers = require "mason-test.helpers" ---@param overrides Purl local function purl(overrides) @@ -26,12 +26,22 @@ describe("composer provider :: parsing", function() end) describe("composer provider :: installing", function() + local snapshot + + before_each(function() + snapshot = assert.snapshot() + end) + + after_each(function() + snapshot:revert() + end) + it("should install composer packages", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() local manager = require "mason-core.installer.managers.composer" stub(manager, "install", mockx.returns(Result.success())) - local result = installer.exec_in_context(ctx, function() + local result = ctx:execute(function() return composer.install(ctx, { package = "vendor/package", version = "1.2.0", diff --git a/tests/mason-core/installer/registry/providers/gem_spec.lua b/tests/mason-core/installer/registry/compilers/gem_spec.lua index 965cdbe8..b38bba33 100644 --- a/tests/mason-core/installer/registry/providers/gem_spec.lua +++ b/tests/mason-core/installer/registry/compilers/gem_spec.lua @@ -1,8 +1,8 @@ local Purl = require "mason-core.purl" local Result = require "mason-core.result" -local gem = require "mason-core.installer.registry.providers.gem" -local installer = require "mason-core.installer" +local gem = require "mason-core.installer.compiler.compilers.gem" local stub = require "luassert.stub" +local test_helpers = require "mason-test.helpers" ---@param overrides Purl local function purl(overrides) @@ -31,12 +31,22 @@ describe("gem provider :: parsing", function() end) describe("gem provider :: installing", function() + local snapshot + + before_each(function() + snapshot = assert.snapshot() + end) + + after_each(function() + snapshot:revert() + end) + it("should install gem packages", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() local manager = require "mason-core.installer.managers.gem" stub(manager, "install", mockx.returns(Result.success())) - local result = installer.exec_in_context(ctx, function() + local result = ctx:execute(function() return gem.install(ctx, { package = "package", version = "5.2.0", diff --git a/tests/mason-core/installer/registry/providers/generic/build_spec.lua b/tests/mason-core/installer/registry/compilers/generic/build_spec.lua index 443cb99a..8b8baeab 100644 --- a/tests/mason-core/installer/registry/providers/generic/build_spec.lua +++ b/tests/mason-core/installer/registry/compilers/generic/build_spec.lua @@ -1,8 +1,8 @@ local Purl = require "mason-core.purl" local Result = require "mason-core.result" -local generic = require "mason-core.installer.registry.providers.generic" -local installer = require "mason-core.installer" +local generic = require "mason-core.installer.compiler.compilers.generic" local stub = require "luassert.stub" +local test_helpers = require "mason-test.helpers" ---@param overrides Purl local function purl(overrides) @@ -119,12 +119,22 @@ describe("generic provider :: build :: parsing", function() end) describe("generic provider :: build :: installing", function() + local snapshot + + before_each(function() + snapshot = assert.snapshot() + end) + + after_each(function() + snapshot:revert() + end) + it("should install", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() local common = require "mason-core.installer.managers.common" stub(common, "run_build_instruction", mockx.returns(Result.success())) - local result = installer.exec_in_context(ctx, function() + local result = ctx:execute(function() return generic.install(ctx, { build = { run = "make", diff --git a/tests/mason-core/installer/registry/providers/generic/download_spec.lua b/tests/mason-core/installer/registry/compilers/generic/download_spec.lua index 4bcb1976..4046d898 100644 --- a/tests/mason-core/installer/registry/providers/generic/download_spec.lua +++ b/tests/mason-core/installer/registry/compilers/generic/download_spec.lua @@ -1,9 +1,9 @@ local Purl = require "mason-core.purl" local Result = require "mason-core.result" -local generic = require "mason-core.installer.registry.providers.generic" -local installer = require "mason-core.installer" local match = require "luassert.match" +local generic = require "mason-core.installer.compiler.compilers.generic" local stub = require "luassert.stub" +local test_helpers = require "mason-test.helpers" ---@param overrides Purl local function purl(overrides) @@ -99,12 +99,22 @@ describe("generic provider :: download :: parsing", function() end) describe("generic provider :: download :: installing", function() + local snapshot + + before_each(function() + snapshot = assert.snapshot() + end) + + after_each(function() + snapshot:revert() + end) + it("should install generic packages", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() local common = require "mason-core.installer.managers.common" stub(common, "download_files", mockx.returns(Result.success())) - local result = installer.exec_in_context(ctx, function() + local result = ctx:execute(function() return generic.install(ctx, { downloads = { { diff --git a/tests/mason-core/installer/registry/providers/github/build_spec.lua b/tests/mason-core/installer/registry/compilers/github/build_spec.lua index 17667d2c..0adc00fe 100644 --- a/tests/mason-core/installer/registry/providers/github/build_spec.lua +++ b/tests/mason-core/installer/registry/compilers/github/build_spec.lua @@ -1,6 +1,6 @@ local Purl = require "mason-core.purl" local Result = require "mason-core.result" -local github = require "mason-core.installer.registry.providers.github" +local github = require "mason-core.installer.compiler.compilers.github" ---@param overrides Purl local function purl(overrides) diff --git a/tests/mason-core/installer/registry/providers/github/release_spec.lua b/tests/mason-core/installer/registry/compilers/github/release_spec.lua index a6648b33..3cfbabc5 100644 --- a/tests/mason-core/installer/registry/providers/github/release_spec.lua +++ b/tests/mason-core/installer/registry/compilers/github/release_spec.lua @@ -1,11 +1,11 @@ local Purl = require "mason-core.purl" local Result = require "mason-core.result" local common = require "mason-core.installer.managers.common" -local github = require "mason-core.installer.registry.providers.github" -local installer = require "mason-core.installer" +local compiler = require "mason-core.installer.compiler" +local github = require "mason-core.installer.compiler.compilers.github" local match = require "luassert.match" -local registry_installer = require "mason-core.installer.registry" local stub = require "luassert.stub" +local test_helpers = require "mason-test.helpers" ---@param overrides Purl local function purl(overrides) @@ -198,7 +198,7 @@ describe("github provider :: release :: parsing", function() end) it("should upsert version overrides", function() - local result = registry_installer.parse({ + local result = compiler.parse({ schema = "registry+v1", source = { id = "pkg:github/owner/repo@1.2.3", @@ -252,7 +252,7 @@ describe("github provider :: release :: parsing", function() end) it("should override source if version override provides its own purl id", function() - local result = registry_installer.parse({ + local result = compiler.parse({ schema = "registry+v1", source = { id = "pkg:github/owner/repo@1.2.3", @@ -280,14 +280,24 @@ describe("github provider :: release :: parsing", function() end) describe("github provider :: release :: installing", function() + local snapshot + + before_each(function() + snapshot = assert.snapshot() + end) + + after_each(function() + snapshot:revert() + end) + it("should install github release assets", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() local std = require "mason-core.installer.managers.std" stub(std, "download_file", mockx.returns(Result.success())) stub(std, "unpack", mockx.returns(Result.success())) stub(common, "download_files", mockx.returns(Result.success())) - local result = installer.exec_in_context(ctx, function() + local result = ctx:execute(function() return github.install(ctx, { repo = "namespace/name", asset = { diff --git a/tests/mason-core/installer/registry/providers/golang_spec.lua b/tests/mason-core/installer/registry/compilers/golang_spec.lua index 6ba57272..8a3abc8a 100644 --- a/tests/mason-core/installer/registry/providers/golang_spec.lua +++ b/tests/mason-core/installer/registry/compilers/golang_spec.lua @@ -1,8 +1,8 @@ local Purl = require "mason-core.purl" local Result = require "mason-core.result" -local golang = require "mason-core.installer.registry.providers.golang" -local installer = require "mason-core.installer" +local golang = require "mason-core.installer.compiler.compilers.golang" local stub = require "luassert.stub" +local test_helpers = require "mason-test.helpers" ---@param overrides Purl local function purl(overrides) @@ -27,12 +27,22 @@ describe("golang provider :: parsing", function() end) describe("golang provider :: installing", function() + local snapshot + + before_each(function() + snapshot = assert.snapshot() + end) + + after_each(function() + snapshot:revert() + end) + it("should install golang packages", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() local manager = require "mason-core.installer.managers.golang" stub(manager, "install", mockx.returns(Result.success())) - local result = installer.exec_in_context(ctx, function() + local result = ctx:execute(function() return golang.install(ctx, { package = "namespace/package", version = "v1.5.0", diff --git a/tests/mason-core/installer/registry/providers/luarocks_spec.lua b/tests/mason-core/installer/registry/compilers/luarocks_spec.lua index 0a4ea9ad..b8642fcf 100644 --- a/tests/mason-core/installer/registry/providers/luarocks_spec.lua +++ b/tests/mason-core/installer/registry/compilers/luarocks_spec.lua @@ -1,9 +1,9 @@ local Purl = require "mason-core.purl" local Result = require "mason-core.result" -local installer = require "mason-core.installer" -local luarocks = require "mason-core.installer.registry.providers.luarocks" +local luarocks = require "mason-core.installer.compiler.compilers.luarocks" local match = require "luassert.match" local stub = require "luassert.stub" +local test_helpers = require "mason-test.helpers" ---@param overrides Purl local function purl(overrides) @@ -53,13 +53,23 @@ describe("luarocks provider :: parsing", function() end) describe("luarocks provider :: installing", function() + local snapshot + + before_each(function() + snapshot = assert.snapshot() + end) + + after_each(function() + snapshot:revert() + end) + it("should install luarocks packages", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() local manager = require "mason-core.installer.managers.luarocks" local ret_val = Result.success() stub(manager, "install", mockx.returns(ret_val)) - local result = installer.exec_in_context(ctx, function() + local result = ctx:execute(function() return luarocks.install(ctx, { package = "namespace/name", version = "1.0.0", diff --git a/tests/mason-core/installer/registry/providers/npm_spec.lua b/tests/mason-core/installer/registry/compilers/npm_spec.lua index b39d092a..680df5bc 100644 --- a/tests/mason-core/installer/registry/providers/npm_spec.lua +++ b/tests/mason-core/installer/registry/compilers/npm_spec.lua @@ -1,8 +1,8 @@ local Purl = require "mason-core.purl" local Result = require "mason-core.result" -local installer = require "mason-core.installer" -local npm = require "mason-core.installer.registry.providers.npm" +local npm = require "mason-core.installer.compiler.compilers.npm" local stub = require "luassert.stub" +local test_helpers = require "mason-test.helpers" ---@param overrides Purl local function purl(overrides) @@ -27,13 +27,23 @@ describe("npm provider :: parsing", function() end) describe("npm provider :: installing", function() + local snapshot + + before_each(function() + snapshot = assert.snapshot() + end) + + after_each(function() + snapshot:revert() + end) + it("should install npm packages", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() local manager = require "mason-core.installer.managers.npm" stub(manager, "init", mockx.returns(Result.success())) stub(manager, "install", mockx.returns(Result.success())) - local result = installer.exec_in_context(ctx, function() + local result = ctx:execute(function() return npm.install(ctx, { package = "@namespace/package", version = "v1.5.0", diff --git a/tests/mason-core/installer/registry/providers/nuget_spec.lua b/tests/mason-core/installer/registry/compilers/nuget_spec.lua index 2437d8de..f514e666 100644 --- a/tests/mason-core/installer/registry/providers/nuget_spec.lua +++ b/tests/mason-core/installer/registry/compilers/nuget_spec.lua @@ -1,8 +1,8 @@ local Purl = require "mason-core.purl" local Result = require "mason-core.result" -local installer = require "mason-core.installer" -local nuget = require "mason-core.installer.registry.providers.nuget" +local nuget = require "mason-core.installer.compiler.compilers.nuget" local stub = require "luassert.stub" +local test_helpers = require "mason-test.helpers" ---@param overrides Purl local function purl(overrides) @@ -26,12 +26,22 @@ describe("nuget provider :: parsing", function() end) describe("nuget provider :: installing", function() + local snapshot + + before_each(function() + snapshot = assert.snapshot() + end) + + after_each(function() + snapshot:revert() + end) + it("should install nuget packages", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() local manager = require "mason-core.installer.managers.nuget" stub(manager, "install", mockx.returns(Result.success())) - local result = installer.exec_in_context(ctx, function() + local result = ctx:execute(function() return nuget.install(ctx, { package = "package", version = "1.5.0", diff --git a/tests/mason-core/installer/registry/providers/opam_spec.lua b/tests/mason-core/installer/registry/compilers/opam_spec.lua index c0f73b02..c2c7638e 100644 --- a/tests/mason-core/installer/registry/providers/opam_spec.lua +++ b/tests/mason-core/installer/registry/compilers/opam_spec.lua @@ -1,8 +1,8 @@ local Purl = require "mason-core.purl" local Result = require "mason-core.result" -local installer = require "mason-core.installer" -local opam = require "mason-core.installer.registry.providers.opam" +local opam = require "mason-core.installer.compiler.compilers.opam" local stub = require "luassert.stub" +local test_helpers = require "mason-test.helpers" ---@param overrides Purl local function purl(overrides) @@ -26,12 +26,22 @@ describe("opam provider :: parsing", function() end) describe("opam provider :: installing", function() + local snapshot + + before_each(function() + snapshot = assert.snapshot() + end) + + after_each(function() + snapshot:revert() + end) + it("should install opam packages", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() local manager = require "mason-core.installer.managers.opam" stub(manager, "install", mockx.returns(Result.success())) - local result = installer.exec_in_context(ctx, function() + local result = ctx:execute(function() return opam.install(ctx, { package = "package", version = "1.5.0", diff --git a/tests/mason-core/installer/registry/providers/openvsx_spec.lua b/tests/mason-core/installer/registry/compilers/openvsx_spec.lua index 1452ea0f..d3868a69 100644 --- a/tests/mason-core/installer/registry/providers/openvsx_spec.lua +++ b/tests/mason-core/installer/registry/compilers/openvsx_spec.lua @@ -1,10 +1,10 @@ local Purl = require "mason-core.purl" local Result = require "mason-core.result" local common = require "mason-core.installer.managers.common" -local installer = require "mason-core.installer" local match = require "luassert.match" -local openvsx = require "mason-core.installer.registry.providers.openvsx" +local openvsx = require "mason-core.installer.compiler.compilers.openvsx" local stub = require "luassert.stub" +local test_helpers = require "mason-test.helpers" ---@param overrides Purl local function purl(overrides) @@ -117,13 +117,10 @@ end) describe("openvsx provider :: download :: installing", function() it("should install openvsx assets", function() - local ctx = create_dummy_context() - local std = require "mason-core.installer.managers.std" - stub(std, "download_file", mockx.returns(Result.success())) - stub(std, "unpack", mockx.returns(Result.success())) + local ctx = test_helpers.create_context() stub(common, "download_files", mockx.returns(Result.success())) - local result = installer.exec_in_context(ctx, function() + local result = ctx:execute(function() return openvsx.install(ctx, { download = { file = "file-1.10.1.jar", diff --git a/tests/mason-core/installer/registry/providers/pypi_spec.lua b/tests/mason-core/installer/registry/compilers/pypi_spec.lua index 539ba53b..61742b4e 100644 --- a/tests/mason-core/installer/registry/providers/pypi_spec.lua +++ b/tests/mason-core/installer/registry/compilers/pypi_spec.lua @@ -1,9 +1,9 @@ local Purl = require "mason-core.purl" local Result = require "mason-core.result" -local installer = require "mason-core.installer" -local pypi = require "mason-core.installer.registry.providers.pypi" +local pypi = require "mason-core.installer.compiler.compilers.pypi" local settings = require "mason.settings" local stub = require "luassert.stub" +local test_helpers = require "mason-test.helpers" ---@param overrides Purl local function purl(overrides) @@ -44,8 +44,18 @@ describe("pypi provider :: parsing", function() end) describe("pypi provider :: installing", function() + local snapshot + + before_each(function() + snapshot = assert.snapshot() + end) + + after_each(function() + snapshot:revert() + end) + it("should install pypi packages", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() local manager = require "mason-core.installer.managers.pypi" stub(manager, "init", mockx.returns(Result.success())) stub(manager, "install", mockx.returns(Result.success())) @@ -56,7 +66,7 @@ describe("pypi provider :: installing", function() }, } - local result = installer.exec_in_context(ctx, function() + local result = ctx:execute(function() return pypi.install(ctx, { package = "package", extra = "lsp", diff --git a/tests/mason-core/installer/registry/expr_spec.lua b/tests/mason-core/installer/registry/expr_spec.lua index 65994dfa..944a5983 100644 --- a/tests/mason-core/installer/registry/expr_spec.lua +++ b/tests/mason-core/installer/registry/expr_spec.lua @@ -1,6 +1,6 @@ local Result = require "mason-core.result" local _ = require "mason-core.functional" -local expr = require "mason-core.installer.registry.expr" +local expr = require "mason-core.installer.compiler.expr" local match = require "luassert.match" describe("registry expressions", function() diff --git a/tests/mason-core/installer/registry/installer_spec.lua b/tests/mason-core/installer/registry/installer_spec.lua index 51d9035e..93c91444 100644 --- a/tests/mason-core/installer/registry/installer_spec.lua +++ b/tests/mason-core/installer/registry/installer_spec.lua @@ -1,12 +1,13 @@ local Result = require "mason-core.result" -local installer = require "mason-core.installer.registry" +local compiler = require "mason-core.installer.compiler" local match = require "luassert.match" local spy = require "luassert.spy" local stub = require "luassert.stub" -local util = require "mason-core.installer.registry.util" +local test_helpers = require "mason-test.helpers" +local util = require "mason-core.installer.compiler.util" ----@type InstallerProvider -local dummy_provider = { +---@type InstallerCompiler +local dummy_compiler = { ---@param source RegistryPackageSource ---@param purl Purl ---@param opts PackageInstallOpts @@ -36,9 +37,9 @@ local dummy_provider = { describe("registry installer :: parsing", function() it("should parse valid package specs", function() - installer.register_provider("dummy", dummy_provider) + compiler.register_compiler("dummy", dummy_compiler) - local result = installer.parse({ + local result = compiler.parse({ schema = "registry+v1", source = { id = "pkg:dummy/package-name@v1.2.3", @@ -48,7 +49,7 @@ describe("registry installer :: parsing", function() local parsed = result:get_or_nil() assert.is_true(result:is_success()) - assert.is_true(match.is_ref(dummy_provider)(parsed.provider)) + assert.is_true(match.is_ref(dummy_compiler)(parsed.compiler)) assert.same({ name = "package-name", scheme = "pkg", @@ -63,9 +64,9 @@ describe("registry installer :: parsing", function() end) it("should keep unmapped fields", function() - installer.register_provider("dummy", dummy_provider) + compiler.register_compiler("dummy", dummy_compiler) - local result = installer.parse({ + local result = compiler.parse({ schema = "registry+v1", source = { id = "pkg:dummy/package-name@v1.2.3", @@ -83,9 +84,9 @@ describe("registry installer :: parsing", function() end) it("should reject incompatible schema versions", function() - installer.register_provider("dummy", dummy_provider) + compiler.register_compiler("dummy", dummy_compiler) - local result = installer.parse({ + local result = compiler.parse({ schema = "registry+v1337", source = { id = "pkg:dummy/package-name@v1.2.3", @@ -98,9 +99,9 @@ describe("registry installer :: parsing", function() end) it("should use requested version", function() - installer.register_provider("dummy", dummy_provider) + compiler.register_compiler("dummy", dummy_compiler) - local result = installer.parse({ + local result = compiler.parse({ schema = "registry+v1", source = { id = "pkg:dummy/package-name@v1.2.3", @@ -119,9 +120,9 @@ describe("registry installer :: parsing", function() end) it("should handle PLATFORM_UNSUPPORTED", function() - installer.register_provider("dummy", dummy_provider) + compiler.register_compiler("dummy", dummy_compiler) - local result = installer.compile({ + local result = compiler.compile({ schema = "registry+v1", source = { id = "pkg:dummy/package-name@v1.2.3", @@ -133,9 +134,9 @@ describe("registry installer :: parsing", function() end) it("should error upon parsing failures", function() - installer.register_provider("dummy", dummy_provider) + compiler.register_compiler("dummy", dummy_compiler) - local result = installer.compile({ + local result = compiler.compile({ schema = "registry+v1", source = { id = "pkg:dummy/package-name@v1.2.3", @@ -148,14 +149,24 @@ describe("registry installer :: parsing", function() end) describe("registry installer :: compiling", function() + local snapshot + + before_each(function() + snapshot = assert.snapshot() + end) + + after_each(function() + snapshot:revert() + end) + it("should run compiled installer function successfully", function() - installer.register_provider("dummy", dummy_provider) - spy.on(dummy_provider, "get_versions") + compiler.register_compiler("dummy", dummy_compiler) + spy.on(dummy_compiler, "get_versions") ---@type PackageInstallOpts local opts = {} - local result = installer.compile({ + local result = compiler.compile({ schema = "registry+v1", source = { id = "pkg:dummy/package-name@v1.2.3", @@ -165,21 +176,21 @@ describe("registry installer :: compiling", function() assert.is_true(result:is_success()) local installer_fn = result:get_or_throw() - local ctx = create_dummy_context(opts) - local installer_result = require("mason-core.installer").exec_in_context(ctx, installer_fn) + local ctx = test_helpers.create_context() + local installer_result = ctx:execute(installer_fn) assert.same(Result.success(), installer_result) - assert.spy(dummy_provider.get_versions).was_not_called() + assert.spy(dummy_compiler.get_versions).was_not_called() end) it("should ensure valid version", function() - installer.register_provider("dummy", dummy_provider) - spy.on(dummy_provider, "get_versions") + compiler.register_compiler("dummy", dummy_compiler) + spy.on(dummy_compiler, "get_versions") ---@type PackageInstallOpts local opts = { version = "v2.0.0" } - local result = installer.compile({ + local result = compiler.compile({ schema = "registry+v1", source = { id = "pkg:dummy/package-name@v1.2.3", @@ -189,12 +200,12 @@ describe("registry installer :: compiling", function() assert.is_true(result:is_success()) local installer_fn = result:get_or_throw() - local ctx = create_dummy_context(opts) - local installer_result = require("mason-core.installer").exec_in_context(ctx, installer_fn) + local ctx = test_helpers.create_context { install_opts = opts } + local installer_result = ctx:execute(installer_fn) assert.same(Result.success(), installer_result) - assert.spy(dummy_provider.get_versions).was_called(1) - assert.spy(dummy_provider.get_versions).was_called_with({ + assert.spy(dummy_compiler.get_versions).was_called(1) + assert.spy(dummy_compiler.get_versions).was_called_with({ name = "package-name", scheme = "pkg", type = "dummy", @@ -205,13 +216,13 @@ describe("registry installer :: compiling", function() end) it("should reject invalid version", function() - installer.register_provider("dummy", dummy_provider) - spy.on(dummy_provider, "get_versions") + compiler.register_compiler("dummy", dummy_compiler) + spy.on(dummy_compiler, "get_versions") ---@type PackageInstallOpts local opts = { version = "v13.3.7" } - local result = installer.compile({ + local result = compiler.compile({ schema = "registry+v1", source = { id = "pkg:dummy/package-name@v1.2.3", @@ -221,14 +232,14 @@ describe("registry installer :: compiling", function() assert.is_true(result:is_success()) local installer_fn = result:get_or_throw() - local ctx = create_dummy_context(opts) + local ctx = test_helpers.create_context { install_opts = opts } local err = assert.has_error(function() - require("mason-core.installer").exec_in_context(ctx, installer_fn) + ctx:execute(installer_fn) end) assert.equals([[Version "v13.3.7" is not available.]], err) - assert.spy(dummy_provider.get_versions).was_called(1) - assert.spy(dummy_provider.get_versions).was_called_with({ + assert.spy(dummy_compiler.get_versions).was_called(1) + assert.spy(dummy_compiler.get_versions).was_called_with({ name = "package-name", scheme = "pkg", type = "dummy", @@ -239,12 +250,12 @@ describe("registry installer :: compiling", function() end) it("should raise errors upon installer failures", function() - installer.register_provider("dummy", dummy_provider) + compiler.register_compiler("dummy", dummy_compiler) ---@type PackageInstallOpts local opts = {} - local result = installer.compile({ + local result = compiler.compile({ schema = "registry+v1", source = { id = "pkg:dummy/package-name@v1.2.3", @@ -255,16 +266,16 @@ describe("registry installer :: compiling", function() assert.is_true(result:is_success()) local installer_fn = result:get_or_nil() - local ctx = create_dummy_context(opts) + local ctx = test_helpers.create_context() local err = assert.has_error(function() - require("mason-core.installer").exec_in_context(ctx, installer_fn) + ctx:execute(installer_fn) end) assert.equals("This is a failure.", err) end) it("should register links", function() - installer.register_provider("dummy", dummy_provider) - local link = require "mason-core.installer.registry.link" + compiler.register_compiler("dummy", dummy_compiler) + local link = require "mason-core.installer.compiler.link" stub(link, "bin", mockx.returns(Result.success())) stub(link, "share", mockx.returns(Result.success())) stub(link, "opt", mockx.returns(Result.success())) @@ -281,13 +292,13 @@ describe("registry installer :: compiling", function() ---@type PackageInstallOpts local opts = {} - local result = installer.compile(spec, opts) + local result = compiler.compile(spec, opts) assert.is_true(result:is_success()) local installer_fn = result:get_or_nil() - local ctx = create_dummy_context(opts) - local installer_result = require("mason-core.installer").exec_in_context(ctx, installer_fn) + local ctx = test_helpers.create_context() + local installer_result = ctx:execute(installer_fn) assert.is_true(installer_result:is_success()) for _, spy in ipairs { link.bin, link.share, link.opt } do diff --git a/tests/mason-core/installer/registry/link_spec.lua b/tests/mason-core/installer/registry/link_spec.lua index eb6af1cc..62777bc9 100644 --- a/tests/mason-core/installer/registry/link_spec.lua +++ b/tests/mason-core/installer/registry/link_spec.lua @@ -1,14 +1,25 @@ local Purl = require "mason-core.purl" local Result = require "mason-core.result" local fs = require "mason-core.fs" -local link = require "mason-core.installer.registry.link" +local link = require "mason-core.installer.compiler.link" local match = require "luassert.match" local path = require "mason-core.path" local stub = require "luassert.stub" +local test_helpers = require "mason-test.helpers" describe("registry linker", function() + local snapshot + + before_each(function() + snapshot = assert.snapshot() + end) + + after_each(function() + snapshot:revert() + end) + it("should expand bin table", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() stub(ctx.fs, "file_exists") stub(ctx.fs, "chmod") stub(ctx.fs, "fstat") @@ -45,7 +56,7 @@ describe("registry linker", function() end) it("should chmod executable if necessary", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() stub(ctx.fs, "file_exists") stub(ctx.fs, "chmod") stub(ctx.fs, "fstat") @@ -74,7 +85,7 @@ describe("registry linker", function() end) it("should interpolate bin table", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() stub(ctx.fs, "file_exists") stub(ctx.fs, "chmod") stub(ctx.fs, "fstat") @@ -106,7 +117,7 @@ describe("registry linker", function() end) it("should delegate bin paths", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() stub(ctx.fs, "file_exists") stub(ctx.fs, "chmod") stub(ctx.fs, "fstat") @@ -144,7 +155,7 @@ describe("registry linker", function() end) it("should register share links", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() stub(ctx.fs, "file_exists") stub(fs.sync, "file_exists") stub(vim.fn, "glob") @@ -192,7 +203,7 @@ describe("registry linker", function() end) it("should register opt links", function() - local ctx = create_dummy_context() + local ctx = test_helpers.create_context() stub(ctx.fs, "file_exists") stub(fs.sync, "file_exists") stub(vim.fn, "glob") diff --git a/tests/mason-core/installer/registry/util_spec.lua b/tests/mason-core/installer/registry/util_spec.lua index 851164d0..be687f36 100644 --- a/tests/mason-core/installer/registry/util_spec.lua +++ b/tests/mason-core/installer/registry/util_spec.lua @@ -1,8 +1,8 @@ local Result = require "mason-core.result" -local installer = require "mason-core.installer" local match = require "luassert.match" local platform = require "mason-core.platform" -local util = require "mason-core.installer.registry.util" +local test_helpers = require "mason-test.helpers" +local util = require "mason-core.installer.compiler.util" describe("registry installer util", function() it("should coalesce single target", function() @@ -40,8 +40,8 @@ describe("registry installer util", function() end) it("should accept valid version", function() - local ctx = create_dummy_context { version = "1.0.0" } - local result = installer.exec_in_context(ctx, function() + local ctx = test_helpers.create_context { install_opts = { version = "1.0.0" } } + local result = ctx:execute(function() return util.ensure_valid_version(function() return Result.success { "1.0.0", "2.0.0", "3.0.0" } end) @@ -50,8 +50,8 @@ describe("registry installer util", function() end) it("should reject invalid version", function() - local ctx = create_dummy_context { version = "13.3.7" } - local result = installer.exec_in_context(ctx, function() + local ctx = test_helpers.create_context { install_opts = { version = "13.3.7" } } + local result = ctx:execute(function() return util.ensure_valid_version(function() return Result.success { "1.0.0", "2.0.0", "3.0.0" } end) @@ -60,8 +60,8 @@ describe("registry installer util", function() end) it("should gracefully accept version if unable to resolve available versions", function() - local ctx = create_dummy_context { version = "13.3.7" } - local result = installer.exec_in_context(ctx, function() + local ctx = test_helpers.create_context { install_opts = { version = "13.3.7" } } + local result = ctx:execute(function() return util.ensure_valid_version(function() return Result.failure() end) @@ -70,8 +70,8 @@ describe("registry installer util", function() end) it("should accept version if in force mode", function() - local ctx = create_dummy_context { version = "13.3.7", force = true } - local result = installer.exec_in_context(ctx, function() + local ctx = test_helpers.create_context { install_opts = { version = "13.3.7", force = true } } + local result = ctx:execute(function() return util.ensure_valid_version(function() return Result.success { "1.0.0" } end) diff --git a/tests/mason-core/installer/runner_spec.lua b/tests/mason-core/installer/runner_spec.lua new file mode 100644 index 00000000..b39a75ac --- /dev/null +++ b/tests/mason-core/installer/runner_spec.lua @@ -0,0 +1,300 @@ +local InstallHandle = require "mason-core.installer.handle" +local InstallLocation = require "mason-core.installer.location" +local InstallRunner = require "mason-core.installer.runner" +local fs = require "mason-core.fs" +local match = require "luassert.match" +local spy = require "luassert.spy" +local stub = require "luassert.stub" +local Semaphore = require("mason-core.async.control").Semaphore +local a = require "mason-core.async" +local registry = require "mason-registry" +local settings = require "mason.settings" + +describe("install runner ::", function() + local dummy = registry.get_package "dummy" + local dummy2 = registry.get_package "dummy2" + + local snapshot + + before_each(function() + snapshot = assert.snapshot() + end) + + after_each(function() + snapshot:revert() + end) + + before_each(function() + dummy:uninstall() + dummy2:uninstall() + end) + + describe("locking ::", function() + it("should respect semaphore locks", function() + local semaphore = Semaphore.new(1) + local location = InstallLocation.new(settings.current.install_root_dir) + local dummy_handle = InstallHandle.new(dummy) + local runner_1 = InstallRunner.new(location, dummy_handle, semaphore) + local runner_2 = InstallRunner.new(location, InstallHandle.new(dummy2), semaphore) + + stub(dummy.spec.source, "install", function() + a.sleep(10000) + end) + spy.on(dummy2.spec.source, "install") + + runner_1:execute {} + runner_2:execute {} + + assert.wait(function() + assert.spy(dummy.spec.source.install).was_called(1) + assert.spy(dummy2.spec.source.install).was_not_called() + end) + + dummy_handle:terminate() + + assert.wait(function() + assert.spy(dummy2.spec.source.install).was_called(1) + end) + end) + + it("should write lockfile", function() + local semaphore = Semaphore.new(1) + local location = InstallLocation.new(settings.current.install_root_dir) + local dummy_handle = InstallHandle.new(dummy) + local runner = InstallRunner.new(location, dummy_handle, semaphore) + + spy.on(fs.async, "write_file") + + runner:execute {} + + assert.wait(function() + assert.spy(fs.async.write_file).was_called_with(location:lockfile(dummy.name), vim.fn.getpid()) + end) + end) + + it("should abort installation if installation lock exists", function() + local semaphore = Semaphore.new(1) + local location = InstallLocation.new(settings.current.install_root_dir) + local dummy_handle = InstallHandle.new(dummy) + local runner = InstallRunner.new(location, dummy_handle, semaphore) + + stub(fs.async, "file_exists") + stub(fs.async, "read_file") + fs.async.file_exists.on_call_with(location:lockfile(dummy.name)).returns(true) + fs.async.read_file.on_call_with(location:lockfile(dummy.name)).returns "1337" + + local callback = spy.new() + runner:execute({}, callback) + + assert.wait(function() + assert.spy(callback).was_called() + assert.spy(callback).was_called_with( + false, + "Lockfile exists, installation is already running in another process (pid: 1337). Run with :MasonInstall --force to bypass." + ) + end) + end) + + it("should not abort installation if installation lock exists with force=true", function() + local semaphore = Semaphore.new(1) + local location = InstallLocation.new(settings.current.install_root_dir) + local dummy_handle = InstallHandle.new(dummy) + local runner = InstallRunner.new(location, dummy_handle, semaphore) + + stub(fs.async, "file_exists") + stub(fs.async, "read_file") + fs.async.file_exists.on_call_with(location:lockfile(dummy.name)).returns(true) + fs.async.read_file.on_call_with(location:lockfile(dummy.name)).returns "1337" + + local callback = spy.new() + runner:execute({ force = true }, callback) + + assert.wait(function() + assert.spy(callback).was_called() + assert.spy(callback).was_called_with(true, nil) + end) + end) + + it("should release lock after successful installation", function() + local semaphore = Semaphore.new(1) + local location = InstallLocation.new(settings.current.install_root_dir) + local dummy_handle = InstallHandle.new(dummy) + local runner = InstallRunner.new(location, dummy_handle, semaphore) + + local callback = spy.new() + runner:execute({}, callback) + + assert.wait(function() + assert.is_true(fs.sync.file_exists(location:lockfile(dummy.name))) + end) + assert.wait(function() + assert.spy(callback).was_called() + end) + assert.is_false(fs.sync.file_exists(location:lockfile(dummy.name))) + end) + end) + + it("should initialize install location", function() + local location = InstallLocation.new(settings.current.install_root_dir) + local runner = InstallRunner.new(location, InstallHandle.new(registry.get_package "dummy"), Semaphore.new(1)) + + spy.on(location, "initialize") + + runner:execute {} + + assert.wait(function() + assert.spy(location.initialize).was_called(1) + end) + end) + + describe("receipt ::", function() + it("should write receipt", function() + local location = InstallLocation.new(settings.current.install_root_dir) + local runner = + InstallRunner.new(location, InstallHandle.new(registry.get_package "dummy"), Semaphore.new(1)) + + runner:execute {} + + assert.wait(function() + local receipt_file = location:package "dummy/mason-receipt.json" + assert.is_true(fs.sync.file_exists(receipt_file)) + assert.is_true(match.tbl_containing { + name = "dummy", + schema_version = "1.2", + metrics = match.tbl_containing { + completion_time = match.is_number(), + start_time = match.is_number(), + }, + source = match.same { + id = "pkg:mason/dummy@1.0.0", + type = "registry+v1", + }, + links = match.same { + bin = {}, + opt = {}, + share = {}, + }, + }(vim.json.decode(fs.sync.read_file(receipt_file)))) + end) + end) + end) + + it("should emit failures", function() + local registry_spy = spy.new() + local package_spy = spy.new() + registry:once("package:install:failed", registry_spy) + dummy:once("install:failed", package_spy) + + local location = InstallLocation.new(settings.current.install_root_dir) + local handle = InstallHandle.new(registry.get_package "dummy") + local runner = InstallRunner.new(location, handle, Semaphore.new(1)) + + stub(dummy.spec.source, "install", function() + error("I've made a mistake.", 0) + end) + + local callback = spy.new() + runner:execute({}, callback) + + assert.wait(function() + assert.spy(registry_spy).was_called(1) + assert.spy(registry_spy).was_called_with(match.is_ref(dummy), match.is_ref(handle), "I've made a mistake.") + assert.spy(package_spy).was_called(1) + assert.spy(package_spy).was_called_with(match.is_ref(handle), "I've made a mistake.") + + assert.spy(callback).was_called(1) + assert.spy(callback).was_called_with(false, "I've made a mistake.") + end, 10) + end) + + it("should terminate installation", function() + local location = InstallLocation.new(settings.current.install_root_dir) + local handle = InstallHandle.new(registry.get_package "dummy") + local runner = InstallRunner.new(location, handle, Semaphore.new(1)) + + local capture = spy.new() + stub(dummy.spec.source, "install", function() + capture() + handle:terminate() + a.sleep(0) + capture() + end) + + local callback = spy.new() + + runner:execute({}, callback) + + assert.wait(function() + assert.spy(callback).was_called(1) + assert.spy(callback).was_called_with(false, "Installation was aborted.") + + assert.spy(capture).was_called(1) + end) + end) + + it("should write debug logs when debug=true", function() + local location = InstallLocation.new(settings.current.install_root_dir) + local handle = InstallHandle.new(registry.get_package "dummy") + local runner = InstallRunner.new(location, handle, Semaphore.new(1)) + + stub(dummy.spec.source, "install", function(ctx) + ctx.stdio_sink.stdout "Hello " + ctx.stdio_sink.stderr "world!" + end) + + local callback = spy.new() + runner:execute({ debug = true }, callback) + + assert.wait(function() + assert.spy(callback).was_called() + assert.spy(callback).was_called_with(true, nil) + end) + assert.is_true(fs.sync.file_exists(location:package "dummy/mason-debug.log")) + assert.equals("Hello world!", fs.sync.read_file(location:package "dummy/mason-debug.log")) + end) + + it("should not retain installation directory on failure", function() + local location = InstallLocation.new(settings.current.install_root_dir) + local handle = InstallHandle.new(registry.get_package "dummy") + local runner = InstallRunner.new(location, handle, Semaphore.new(1)) + + stub(dummy.spec.source, "install", function(ctx) + ctx.stdio_sink.stderr "Something will go terribly wrong.\n" + error("This went terribly wrong.", 0) + end) + + local callback = spy.new() + runner:execute({}, callback) + + assert.wait(function() + assert.spy(callback).was_called() + assert.spy(callback).was_called_with(false, "This went terribly wrong.") + end) + assert.is_false(fs.sync.dir_exists(location:staging "dummy")) + assert.is_false(fs.sync.dir_exists(location:package "dummy")) + end) + + it("should retain installation directory on failure and debug=true", function() + local location = InstallLocation.new(settings.current.install_root_dir) + local handle = InstallHandle.new(registry.get_package "dummy") + local runner = InstallRunner.new(location, handle, Semaphore.new(1)) + + stub(dummy.spec.source, "install", function(ctx) + ctx.stdio_sink.stderr "Something will go terribly wrong.\n" + error("This went terribly wrong.", 0) + end) + + local callback = spy.new() + runner:execute({ debug = true }, callback) + + assert.wait(function() + assert.spy(callback).was_called() + assert.spy(callback).was_called_with(false, "This went terribly wrong.") + end) + assert.is_true(fs.sync.dir_exists(location:staging "dummy")) + assert.equals( + "Something will go terribly wrong.\nThis went terribly wrong.\n", + fs.sync.read_file(location:staging "dummy/mason-debug.log") + ) + end) +end) |
