-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref: improve test runner to use nvim
- Loading branch information
1 parent
381d2a3
commit 17672e1
Showing
4 changed files
with
30 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,37 @@ | ||
local M = {} | ||
|
||
local log = require("shared.logger").create_logger({ log_level = "debug" }) | ||
|
||
--- Run a test | ||
---@param name string | ||
---@param cb function | ||
function M.run(name, cb) | ||
print("Running test: " .. name) | ||
log.debug("Running test: " .. name) | ||
cb() | ||
print("Test passed: " .. name) | ||
log.debug("Test passed: " .. name) | ||
end | ||
|
||
---Check if a file is a test file | ||
---@param file string | ||
---@return boolean | ||
local function is_test_file(file) | ||
return file:match(".*_test.lua$") | ||
end | ||
|
||
--- Find and run all tests | ||
function M.test() | ||
local files = vim.fs.find( | ||
is_test_file, | ||
{ type = "file", path = vim.fn.getcwd() .. "/lua" } | ||
) | ||
|
||
for _, file in ipairs(files) do | ||
local relative_path = file:gsub(".*/ollero.nvim/lua/", "") | ||
local require_path = relative_path:gsub(".lua", ""):gsub("/", ".") | ||
require(require_path) | ||
print(".") | ||
end | ||
print("\n") | ||
end | ||
|
||
return M |