diff options
| author | William Boman <william@redwill.se> | 2023-10-13 01:53:41 +0200 |
|---|---|---|
| committer | William Boman <william@redwill.se> | 2025-02-19 09:23:19 +0100 |
| commit | f1e58d3ce7ab3bdb3036b791811896a0220703ad (patch) | |
| tree | ce44529583dcf72844b206fe8578f0ada5ef153f /tests | |
| parent | refactor(installer): move initializations to InstallContext constructor (diff) | |
| download | mason-f1e58d3ce7ab3bdb3036b791811896a0220703ad.tar mason-f1e58d3ce7ab3bdb3036b791811896a0220703ad.tar.gz mason-f1e58d3ce7ab3bdb3036b791811896a0220703ad.tar.bz2 mason-f1e58d3ce7ab3bdb3036b791811896a0220703ad.tar.lz mason-f1e58d3ce7ab3bdb3036b791811896a0220703ad.tar.xz mason-f1e58d3ce7ab3bdb3036b791811896a0220703ad.tar.zst mason-f1e58d3ce7ab3bdb3036b791811896a0220703ad.zip | |
refactor(path): use InstallLocation to produce paths, remove static path methods
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/mason-core/installer/linker_spec.lua | 60 | ||||
| -rw-r--r-- | tests/mason/setup_spec.lua | 14 |
2 files changed, 40 insertions, 34 deletions
diff --git a/tests/mason-core/installer/linker_spec.lua b/tests/mason-core/installer/linker_spec.lua index 9684f57d..eb5ce394 100644 --- a/tests/mason-core/installer/linker_spec.lua +++ b/tests/mason-core/installer/linker_spec.lua @@ -41,18 +41,19 @@ describe("linker", function() it("should symlink executable on Unix", function() local dummy = registry.get_package "dummy" + local ctx = test_helpers.create_context() + 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(ctx.location:bin "my-executable").returns(false) + fs.async.file_exists.on_call_with(ctx.location:bin "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 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) @@ -62,35 +63,36 @@ describe("linker", function() 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") + .was_called_with(path.concat { dummy:get_install_path(), "another-executable" }, ctx.location:bin "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" + ctx.location:bin "my-executable" ) end) it("should write executable wrapper on Windows", function() + local dummy = registry.get_package "dummy" + local ctx = test_helpers.create_context() + 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") - 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(ctx.location:bin "my-executable").returns(false) + fs.async.file_exists.on_call_with(ctx.location:bin "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 ctx = test_helpers.create_context() ctx:link_bin("my-executable", path.concat { "nested", "path", "my-executable" }) ctx:link_bin("another-executable", "another-executable") @@ -100,17 +102,19 @@ describe("linker", function() 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", + ctx.location:bin "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", + ctx.location:bin "my-executable.cmd", WIN_CMD_SCRIPT:format(path.concat { dummy:get_install_path(), "nested", "path", "my-executable" }) ) end) it("should symlink share files", function() local dummy = registry.get_package "dummy" + local ctx = test_helpers.create_context() + stub(fs.async, "mkdirp") stub(fs.async, "dir_exists") stub(fs.async, "file_exists") @@ -118,11 +122,10 @@ describe("linker", function() stub(fs.async, "write_file") -- 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) + fs.async.file_exists.on_call_with(ctx.location:share "share-file").returns(false) + fs.async.file_exists.on_call_with(ctx.location:share(path.concat { "nested", "share-file" })).returns(false) - 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) + fs.async.dir_exists.on_call_with(ctx.location:share "nested/path").returns(false) -- mock existent source files fs.async.file_exists.on_call_with(path.concat { dummy:get_install_path(), "share-file" }).returns(true) @@ -130,7 +133,6 @@ describe("linker", function() .on_call_with(path.concat { dummy:get_install_path(), "nested", "path", "to", "share-file" }) .returns(true) - 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" @@ -142,36 +144,36 @@ describe("linker", function() 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") + .was_called_with(path.concat { dummy:get_install_path(), "share-file" }, ctx.location:share "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" + ctx.location:share "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") + assert.spy(fs.async.mkdirp).was_called_with(ctx.location:share "nested/path") end) it("should copy share files on Windows", function() + local dummy = registry.get_package "dummy" + local ctx = test_helpers.create_context() + 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, "mkdirp") stub(fs.async, "dir_exists") stub(fs.async, "file_exists") stub(fs.async, "copy_file") -- 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) + fs.async.file_exists.on_call_with(ctx.location:share "share-file").returns(false) + fs.async.file_exists.on_call_with(ctx.location:share(path.concat { "nested", "share-file" })).returns(false) - 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) + fs.async.dir_exists.on_call_with(ctx.location:share "nested/path").returns(false) -- mock existent source files fs.async.file_exists.on_call_with(path.concat { dummy:get_install_path(), "share-file" }).returns(true) @@ -179,7 +181,6 @@ describe("linker", function() .on_call_with(path.concat { dummy:get_install_path(), "nested", "path", "to", "share-file" }) .returns(true) - 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" @@ -190,15 +191,14 @@ describe("linker", function() assert.spy(fs.async.copy_file).was_called(2) assert .spy(fs.async.copy_file) - .was_called_with(path.concat { dummy:get_install_path(), "share-file" }, path.share_prefix "share-file", { excl = true }) + .was_called_with(path.concat { dummy:get_install_path(), "share-file" }, ctx.location:share "share-file", { excl = true }) assert.spy(fs.async.copy_file).was_called_with( path.concat { dummy:get_install_path(), "nested", "path", "to", "share-file" }, - path.share_prefix "nested/path/share-file", + ctx.location:share "nested/path/share-file", { excl = true } ) 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") + assert.spy(fs.async.mkdirp).was_called_with(ctx.location:share "nested/path") end) end) diff --git a/tests/mason/setup_spec.lua b/tests/mason/setup_spec.lua index b733edd0..68871119 100644 --- a/tests/mason/setup_spec.lua +++ b/tests/mason/setup_spec.lua @@ -1,6 +1,6 @@ +local InstallLocation = require "mason-core.installer.location" local mason = require "mason" local match = require "luassert.match" -local path = require "mason-core.path" local settings = require "mason.settings" describe("mason setup", function() @@ -12,32 +12,38 @@ describe("mason setup", function() it("should enhance the PATH environment", function() mason.setup() - assert.equals(("%s:/usr/local/bin:/usr/bin"):format(path.bin_prefix()), vim.env.PATH) + local global_location = InstallLocation.global() + assert.equals(("%s:/usr/local/bin:/usr/bin"):format(global_location:bin()), vim.env.PATH) end) it("should prepend the PATH environment", function() mason.setup { PATH = "prepend" } - assert.equals(("%s:/usr/local/bin:/usr/bin"):format(path.bin_prefix()), vim.env.PATH) + local global_location = InstallLocation.global() + assert.equals(("%s:/usr/local/bin:/usr/bin"):format(global_location:bin()), vim.env.PATH) end) it("should append PATH", function() mason.setup { PATH = "append" } - assert.equals(("/usr/local/bin:/usr/bin:%s"):format(path.bin_prefix()), vim.env.PATH) + local global_location = InstallLocation.global() + assert.equals(("/usr/local/bin:/usr/bin:%s"):format(global_location:bin()), vim.env.PATH) end) it("shouldn't modify PATH", function() local PATH = vim.env.PATH + local global_location = InstallLocation.global() mason.setup { PATH = "skip" } assert.equals(PATH, vim.env.PATH) end) it("should set MASON env", function() assert.is_nil(vim.env.MASON) + local global_location = InstallLocation.global() mason.setup() assert.equals(vim.fn.expand "~/.local/share/nvim/mason", vim.env.MASON) end) it("should set up user commands", function() + local global_location = InstallLocation.global() mason.setup() local user_commands = vim.api.nvim_get_commands {} |
