Skip to content

Commit 2dcf249

Browse files
committed
chore: plenary tests POC
1 parent 9ac1e05 commit 2dcf249

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

lua/nvim-tree/utils.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ M.is_wsl = vim.fn.has("wsl") == 1
1111
-- false for WSL
1212
M.is_windows = vim.fn.has("win32") == 1 or vim.fn.has("win32unix") == 1
1313

14+
function M._is_windows()
15+
return vim.fn.has("win32") == 1 or vim.fn.has("win32unix") == 1
16+
end
17+
1418
---@param haystack string
1519
---@param needle string
1620
---@return boolean
@@ -299,7 +303,7 @@ end
299303
---@param path string
300304
---@return string
301305
function M.canonical_path(path)
302-
if M.is_windows and path:match("^%a:") then
306+
if M._is_windows() and path:match("^%a:") then
303307
return path:sub(1, 1):upper() .. path:sub(2)
304308
end
305309
return path

scripts/test.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ set -e
55
# TODO add ability for user to specify a test file or directory
66

77
REPO_DIR="$(git rev-parse --show-toplevel)"
8+
export REPO_DIR
9+
810
PLENARY_DIR="${REPO_DIR}/plenary.nvim"
11+
export PLENARY_DIR
912

1013
nvim --headless \
1114
--clean \
1215
--noplugin \
13-
-c "set runtimepath+=${PLENARY_DIR}" \
16+
-u "tests/minimal_init.lua" \
1417
-c "lua require('plenary.test_harness').test_directory('tests/', { minimal_init = './tests/minimal_init.lua' })" \
1518
-c "qa!"
1619

tests/minimal_init.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
11
-- this file is necessary for the minimal_init option which directs the spawned nvim test instances be run with --noplugin
2+
3+
-- ensure that this nvim-tree is not overridden by installed versions in .local/share/nvim/site etc.
4+
vim.o.runtimepath = vim.env.REPO_DIR .. "," .. vim.o.runtimepath
5+
6+
-- plenary will append ,.,$HOME/src/nvim-tree/master/plenary.nvim in the spawned test instances, however we want this here to prevent overrides
7+
vim.o.runtimepath = vim.env.PLENARY_DIR .. "," .. vim.o.runtimepath
8+

tests/unit/utils_spec.lua

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---@type Luassert
22
local assert = require("luassert")
3+
local stub = require("luassert.stub")
34

45
local utils = require("nvim-tree.utils")
56

@@ -8,10 +9,29 @@ describe("utils.path_add_trailing", function()
89
end)
910

1011
it("trailing added", function()
11-
assert.equals(utils.path_add_trailing("foo"), "foo/")
12+
assert.equals("foo/", utils.path_add_trailing("foo"))
1213
end)
1314

1415
it("trailing already present", function()
15-
assert.equals(utils.path_add_trailing("foo/"), "foo/")
16+
assert.equals("foo/", utils.path_add_trailing("foo/"))
17+
end)
18+
end)
19+
20+
describe("utils.canonical_path", function()
21+
22+
before_each(function()
23+
stub(vim.fn, "has")
24+
end)
25+
26+
after_each(function()
27+
end)
28+
29+
it("is windows", function()
30+
vim.fn.has.on_call_with("win32unix").returns(1)
31+
assert.equals("C:\\foo\\bar", utils.canonical_path("c:\\foo\\bar"), "should be uppercase drive")
32+
end)
33+
34+
it("not windows", function()
35+
assert.equals("c:\\foo\\bar", utils.canonical_path("c:\\foo\\bar"))
1636
end)
1737
end)

0 commit comments

Comments
 (0)