Skip to content

chore: POC plenary test #3063

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/luals-out/
/luals/
/plenary.nvim/
# backup vim files
*~
3 changes: 2 additions & 1 deletion .luarc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"workspace": {
"library": [
"$VIMRUNTIME/lua/vim",
"${3rd}/luv/library"
"${3rd}/luv/library",
"plenary.nvim"
]
},
"diagnostics": {
Expand Down
6 changes: 5 additions & 1 deletion lua/nvim-tree/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ M.is_wsl = vim.fn.has("wsl") == 1
-- false for WSL
M.is_windows = vim.fn.has("win32") == 1 or vim.fn.has("win32unix") == 1

function M._is_windows()
return vim.fn.has("win32") == 1 or vim.fn.has("win32unix") == 1
end

---@param haystack string
---@param needle string
---@return boolean
Expand Down Expand Up @@ -299,7 +303,7 @@ end
---@param path string
---@return string
function M.canonical_path(path)
if M.is_windows and path:match("^%a:") then
if M._is_windows() and path:match("^%a:") then
return path:sub(1, 1):upper() .. path:sub(2)
end
return path
Expand Down
19 changes: 19 additions & 0 deletions scripts/test.sh
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a command in Makefile (e.g. make test) that runs this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. It can then run in CI.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

set -e

# TODO add ability for user to specify a test file or directory

REPO_DIR="$(git rev-parse --show-toplevel)"
export REPO_DIR

PLENARY_DIR="${REPO_DIR}/plenary.nvim"
export PLENARY_DIR

nvim --headless \
--clean \
--noplugin \
-u "tests/minimal_init.lua" \
-c "lua require('plenary.test_harness').test_directory('tests/', { minimal_init = './tests/minimal_init.lua' })" \
-c "qa!"

8 changes: 8 additions & 0 deletions tests/minimal_init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- this file is necessary for the minimal_init option which directs the spawned nvim test instances be run with --noplugin

-- ensure that this nvim-tree is not overridden by installed versions in .local/share/nvim/site etc.
vim.o.runtimepath = vim.env.REPO_DIR .. "," .. vim.o.runtimepath

-- plenary will append ,.,$HOME/src/nvim-tree/master/plenary.nvim in the spawned test instances, however we want this here to prevent overrides
vim.o.runtimepath = vim.env.PLENARY_DIR .. "," .. vim.o.runtimepath

37 changes: 37 additions & 0 deletions tests/unit/utils_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---@type Luassert
local assert = require("luassert")
local stub = require("luassert.stub")

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

describe("utils.path_add_trailing", function()
before_each(function()
end)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intended?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops... didn't need that one...


it("trailing added", function()
assert.equals("foo/", utils.path_add_trailing("foo"))
end)

it("trailing already present", function()
assert.equals("foo/", utils.path_add_trailing("foo/"))
end)
end)

describe("utils.canonical_path", function()

before_each(function()
stub(vim.fn, "has")
end)

after_each(function()
end)

it("is windows", function()
vim.fn.has.on_call_with("win32unix").returns(1)
assert.equals("C:\\foo\\bar", utils.canonical_path("c:\\foo\\bar"), "should be uppercase drive")
end)

it("not windows", function()
assert.equals("c:\\foo\\bar", utils.canonical_path("c:\\foo\\bar"))
end)
end)
Loading