diff options
| author | William Boman <william@redwill.se> | 2022-04-21 12:09:59 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-21 12:09:59 +0200 |
| commit | b68fcc6bb2c770495ff8e2508c06dfdd49abcc80 (patch) | |
| tree | df7c71efb59958deb21a18eeccf3e3c43c4cd704 /tests | |
| parent | run autogen_metadata.lua (diff) | |
| download | mason-b68fcc6bb2c770495ff8e2508c06dfdd49abcc80.tar mason-b68fcc6bb2c770495ff8e2508c06dfdd49abcc80.tar.gz mason-b68fcc6bb2c770495ff8e2508c06dfdd49abcc80.tar.bz2 mason-b68fcc6bb2c770495ff8e2508c06dfdd49abcc80.tar.lz mason-b68fcc6bb2c770495ff8e2508c06dfdd49abcc80.tar.xz mason-b68fcc6bb2c770495ff8e2508c06dfdd49abcc80.tar.zst mason-b68fcc6bb2c770495ff8e2508c06dfdd49abcc80.zip | |
chore: refactor remaining installers to async impl (#616)
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/core/fs_spec.lua | 24 | ||||
| -rw-r--r-- | tests/core/managers/gem_spec.lua | 18 | ||||
| -rw-r--r-- | tests/core/managers/git_spec.lua | 2 | ||||
| -rw-r--r-- | tests/core/managers/go_spec.lua | 19 | ||||
| -rw-r--r-- | tests/core/spawn_spec.lua | 15 | ||||
| -rw-r--r-- | tests/data_spec.lua | 17 | ||||
| -rw-r--r-- | tests/fs_spec.lua | 18 | ||||
| -rw-r--r-- | tests/platform_spec.lua | 137 |
8 files changed, 206 insertions, 44 deletions
diff --git a/tests/core/fs_spec.lua b/tests/core/fs_spec.lua new file mode 100644 index 00000000..121c57d6 --- /dev/null +++ b/tests/core/fs_spec.lua @@ -0,0 +1,24 @@ +local fs = require "nvim-lsp-installer.core.fs" +local lsp_installer = require "nvim-lsp-installer" + +describe("fs", function() + before_each(function() + lsp_installer.settings { + install_root_dir = "/foo", + } + end) + + it( + "refuses to rmrf paths outside of boundary", + async_test(function() + local e = assert.has.errors(function() + fs.rmrf "/thisisa/path" + end) + + assert.equal( + [[Refusing to rmrf "/thisisa/path" which is outside of the allowed boundary "/foo". Please report this error at https://github.com/williamboman/nvim-lsp-installer/issues/new]], + e + ) + end) + ) +end) diff --git a/tests/core/managers/gem_spec.lua b/tests/core/managers/gem_spec.lua index beab3968..90d0c390 100644 --- a/tests/core/managers/gem_spec.lua +++ b/tests/core/managers/gem_spec.lua @@ -97,10 +97,11 @@ strscan (default: 3.0.1) assert.spy(spawn.gem).was_called_with(match.tbl_containing { "list", cwd = "/tmp/install/dir", - env = match.all_of( - match.list_containing "GEM_HOME=/tmp/install/dir", - match.list_containing "GEM_PATH=/tmp/install/dir" - ), + env = match.tbl_containing { + GEM_HOME = "/tmp/install/dir", + GEM_PATH = "/tmp/install/dir", + PATH = match.matches "^/tmp/install/dir/bin:.*$", + }, }) assert.is_true(result:is_success()) assert.equals("0.44.0", result:get_or_nil()) @@ -139,10 +140,11 @@ solargraph (0.44.0 < 0.44.3) assert.spy(spawn.gem).was_called_with(match.tbl_containing { "outdated", cwd = "/tmp/install/dir", - env = match.all_of( - match.list_containing "GEM_HOME=/tmp/install/dir", - match.list_containing "GEM_PATH=/tmp/install/dir" - ), + env = match.tbl_containing { + GEM_HOME = "/tmp/install/dir", + GEM_PATH = "/tmp/install/dir", + PATH = match.matches "^/tmp/install/dir/bin:.*$", + }, }) assert.is_true(result:is_success()) assert.equals( diff --git a/tests/core/managers/git_spec.lua b/tests/core/managers/git_spec.lua index b73760ee..25e58f6e 100644 --- a/tests/core/managers/git_spec.lua +++ b/tests/core/managers/git_spec.lua @@ -42,6 +42,7 @@ describe("git manager", function() "clone", "--depth", "1", + vim.NIL, "https://github.com/williamboman/nvim-lsp-installer.git", ".", } @@ -60,6 +61,7 @@ describe("git manager", function() "clone", "--depth", "1", + vim.NIL, "https://github.com/williamboman/nvim-lsp-installer.git", ".", } diff --git a/tests/core/managers/go_spec.lua b/tests/core/managers/go_spec.lua index f299bf43..c7218335 100644 --- a/tests/core/managers/go_spec.lua +++ b/tests/core/managers/go_spec.lua @@ -1,4 +1,3 @@ -local match = require "luassert.match" local mock = require "luassert.mock" local stub = require "luassert.stub" local spy = require "luassert.spy" @@ -25,24 +24,24 @@ describe("go manager", function() ctx.requested_version = Optional.of "42.13.37" installer.run_installer(ctx, go.packages { "main-package", "supporting-package", "supporting-package2" }) assert.spy(ctx.spawn.go).was_called(3) - assert.spy(ctx.spawn.go).was_called_with(match.tbl_containing { + assert.spy(ctx.spawn.go).was_called_with { "install", "-v", "main-package@42.13.37", - env = match.list_containing "GOBIN=/tmp/install-dir", - }) - assert.spy(ctx.spawn.go).was_called_with(match.tbl_containing { + env = { GOBIN = "/tmp/install-dir" }, + } + assert.spy(ctx.spawn.go).was_called_with { "install", "-v", "supporting-package@latest", - env = match.list_containing "GOBIN=/tmp/install-dir", - }) - assert.spy(ctx.spawn.go).was_called_with(match.tbl_containing { + env = { GOBIN = "/tmp/install-dir" }, + } + assert.spy(ctx.spawn.go).was_called_with { "install", "-v", "supporting-package2@latest", - env = match.list_containing "GOBIN=/tmp/install-dir", - }) + env = { GOBIN = "/tmp/install-dir" }, + } end) ) diff --git a/tests/core/spawn_spec.lua b/tests/core/spawn_spec.lua index eec14c30..d4716b61 100644 --- a/tests/core/spawn_spec.lua +++ b/tests/core/spawn_spec.lua @@ -9,7 +9,7 @@ describe("async spawn", function() "should spawn commands and return stdout & stderr", async_test(function() local result = spawn.env { - env = { "FOO=bar" }, + env_raw = { "FOO=bar" }, } assert.is_true(result:is_success()) assert.equals("FOO=bar\n", result:get_or_nil().stdout) @@ -22,7 +22,7 @@ describe("async spawn", function() async_test(function() local stdio = process.in_memory_sink() local result = spawn.env { - env = { "FOO=bar" }, + env_raw = { "FOO=bar" }, stdio_sink = stdio.sink, } assert.is_true(result:is_success()) @@ -39,7 +39,7 @@ describe("async spawn", function() local result = spawn.bash { "-c", 'echo "Hello $VAR"', - env = { "VAR=world" }, + env = { VAR = "world" }, } assert.is_true(result:is_success()) @@ -54,12 +54,11 @@ describe("async spawn", function() spy.on(process, "spawn") local result = spawn.bash { vim.NIL, - spawn._when(true, "-c"), - spawn._when(false, "shouldnotbeincluded"), vim.NIL, + "-c", { vim.NIL, vim.NIL }, 'echo "Hello $VAR"', - env = { "VAR=world" }, + env = { VAR = "world" }, } assert.is_true(result:is_success()) @@ -73,7 +72,7 @@ describe("async spawn", function() stdout = match.is_function(), stderr = match.is_function(), }, - env = match.tbl_containing { "VAR=world" }, + env = match.list_containing "VAR=world", args = match.tbl_containing { "-c", 'echo "Hello $VAR"', @@ -89,7 +88,7 @@ describe("async spawn", function() async_test(function() local result = spawn.bash { { "-c", 'echo "Hello $VAR"' }, - env = { "VAR=world" }, + env = { VAR = "world" }, } assert.is_true(result:is_success()) diff --git a/tests/data_spec.lua b/tests/data_spec.lua index 0e13d44c..6a7e409c 100644 --- a/tests/data_spec.lua +++ b/tests/data_spec.lua @@ -1,5 +1,6 @@ local Data = require "nvim-lsp-installer.data" local spy = require "luassert.spy" +local match = require "luassert.match" describe("data", function() it("creates enums", function() @@ -132,4 +133,20 @@ describe("data", function() assert.equal("key1key3", memoized_fn("key1", "key3")) assert.spy(expensive_function).was_called(2) end) + + it("should evaluate functions lazily", function() + local impl = spy.new(function() + return {}, {} + end) + local lazy_fn = Data.lazy(impl) + assert.spy(impl).was_called(0) + local a, b = lazy_fn() + assert.spy(impl).was_called(1) + assert.is_true(match.is_table()(a)) + assert.is_true(match.is_table()(b)) + local new_a, new_b = lazy_fn() + assert.spy(impl).was_called(1) + assert.is_true(match.is_ref(a)(new_a)) + assert.is_true(match.is_ref(b)(new_b)) + end) end) diff --git a/tests/fs_spec.lua b/tests/fs_spec.lua deleted file mode 100644 index e227b9da..00000000 --- a/tests/fs_spec.lua +++ /dev/null @@ -1,18 +0,0 @@ -local fs = require "nvim-lsp-installer.fs" -local lsp_installer = require "nvim-lsp-installer" - -describe("fs", function() - before_each(function() - lsp_installer.settings { - install_root_dir = "/foo", - } - end) - - it("refuses to rmrf unsafe paths", function() - local e = assert.has.errors(function() - fs.rmrf "/thisisa/path" - end) - - assert.equal("Refusing to operate on path (/thisisa/path) outside of the servers root dir (/foo).", e) - end) -end) diff --git a/tests/platform_spec.lua b/tests/platform_spec.lua new file mode 100644 index 00000000..916b240b --- /dev/null +++ b/tests/platform_spec.lua @@ -0,0 +1,137 @@ +local stub = require "luassert.stub" +local spy = require "luassert.spy" +local match = require "luassert.match" + +describe("platform", function() + local function platform() + package.loaded["nvim-lsp-installer.platform"] = nil + return require "nvim-lsp-installer.platform" + end + + local function stub_mac() + stub(vim.fn, "has") + vim.fn.has.on_call_with("mac").returns(1) + vim.fn.has.on_call_with("unix").returns(1) + vim.fn.has.on_call_with(match._).returns(0) + end + + local function stub_linux() + stub(vim.fn, "has") + vim.fn.has.on_call_with("mac").returns(0) + vim.fn.has.on_call_with("unix").returns(1) + vim.fn.has.on_call_with(match._).returns(0) + end + + local function stub_windows() + stub(vim.fn, "has") + vim.fn.has.on_call_with("win32").returns(1) + vim.fn.has.on_call_with(match._).returns(0) + end + + it("should be able to detect macos", function() + stub_mac() + assert.is_true(platform().is_mac) + assert.is_true(platform().is_unix) + assert.is_false(platform().is_linux) + assert.is_false(platform().is_win) + end) + + it("should be able to detect linux", function() + stub_linux() + assert.is_false(platform().is_mac) + assert.is_true(platform().is_unix) + assert.is_true(platform().is_linux) + assert.is_false(platform().is_win) + end) + + it("should be able to detect windows", function() + stub_windows() + assert.is_false(platform().is_mac) + assert.is_false(platform().is_unix) + assert.is_false(platform().is_linux) + assert.is_true(platform().is_win) + end) + + it("should run correct case on linux", function() + local unix = spy.new() + local win = spy.new() + local mac = spy.new() + local linux = spy.new() + + stub_linux() + platform().when { + unix = unix, + win = win, + linux = linux, + mac = mac, + } + assert.spy(unix).was_not_called() + assert.spy(mac).was_not_called() + assert.spy(win).was_not_called() + assert.spy(linux).was_called(1) + end) + + it("should run correct case on mac", function() + local unix = spy.new() + local win = spy.new() + local mac = spy.new() + local linux = spy.new() + + stub_mac() + platform().when { + unix = unix, + win = win, + linux = linux, + mac = mac, + } + assert.spy(unix).was_not_called() + assert.spy(mac).was_called(1) + assert.spy(win).was_not_called() + assert.spy(linux).was_not_called() + end) + + it("should run correct case on windows", function() + local unix = spy.new() + local win = spy.new() + local mac = spy.new() + local linux = spy.new() + + stub_windows() + platform().when { + unix = unix, + win = win, + linux = linux, + mac = mac, + } + assert.spy(unix).was_not_called() + assert.spy(mac).was_not_called() + assert.spy(win).was_called(1) + assert.spy(linux).was_not_called() + end) + + it("should run correct case on mac (unix)", function() + local unix = spy.new() + local win = spy.new() + + stub_mac() + platform().when { + unix = unix, + win = win, + } + assert.spy(unix).was_called(1) + assert.spy(win).was_not_called() + end) + + it("should run correct case on linux (unix)", function() + local unix = spy.new() + local win = spy.new() + + stub_linux() + platform().when { + unix = unix, + win = win, + } + assert.spy(unix).was_called(1) + assert.spy(win).was_not_called() + end) +end) |
