-
-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add fully functional testing suite and basic
core.dirman
tests (
- Loading branch information
Showing
11 changed files
with
120 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: Run tests | ||
on: | ||
pull_request: ~ | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
name: Run tests | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Run tests | ||
uses: nvim-neorocks/nvim-busted-action@v1 | ||
with: | ||
nvim_version: stable |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
local tests = require("neorg.tests") | ||
local Path = require("pathlib") | ||
|
||
describe("core.dirman tests", function() | ||
local dirman = tests | ||
.neorg_with("core.dirman", { | ||
workspaces = { | ||
test = "./test-workspace", | ||
}, | ||
}).modules | ||
.get_module("core.dirman") | ||
|
||
describe("workspace-related functions", function() | ||
it("properly expands workspace paths", function() | ||
assert.same(dirman.get_workspaces(), { | ||
default = Path.cwd(), | ||
test = Path.cwd() / "test-workspace", | ||
}) | ||
end) | ||
|
||
it("properly sets and retrieves workspaces", function() | ||
assert.is_true(dirman.set_workspace("test")) | ||
|
||
assert.equal(dirman.get_current_workspace()[1], "test") | ||
end) | ||
|
||
it("properly creates and writes files", function() | ||
local ws_path = (Path.cwd() / "test-workspace") | ||
|
||
dirman.create_file("example-file", "test", { | ||
no_open = true, | ||
}) | ||
|
||
finally(function() | ||
vim.fn.delete(ws_path:tostring(), "rf") | ||
end) | ||
|
||
assert.equal(vim.fn.filereadable((ws_path / "example-file.norg"):tostring()), 1) | ||
end) | ||
end) | ||
end) |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--[[ | ||
This file contains a variety of utility functions for writing Neorg tests. | ||
The functions used here should be generalized and moved out into a separate rock on luarocks.org in due time. | ||
Neorg sets up `busted` using `neolua` (a wrapper around neovim) as its test interpreter. This allows access to all | ||
Neovim-related APIs natively. The entire process occurs in the flake.nix file. | ||
--]] | ||
|
||
local tests = {} | ||
|
||
--- Sets up Neorg with a given module. | ||
---@param module_name string The name of the module to load. | ||
---@param configuration table? The configuration for the module. | ||
---@return table #The main Neorg table with the setup() function called. | ||
function tests.neorg_with(module_name, configuration) | ||
local neorg = require("neorg") | ||
|
||
neorg.setup({ | ||
load = { | ||
["core.defaults"] = {}, | ||
[module_name] = { config = configuration }, | ||
}, | ||
}) | ||
|
||
return neorg | ||
end | ||
|
||
--- Runs a callback in the context of a given file. | ||
---@param filename string The name of the file (used to determine filetype) | ||
---@param content string The content of the buffer. | ||
---@param callback fun(bufnr: number) The function to execute with the buffer number provided. | ||
function tests.in_file(filename, content, callback) | ||
local buf = vim.api.nvim_create_buf(false, true) | ||
vim.api.nvim_buf_set_name(buf, filename) | ||
vim.api.nvim_buf_set_lines(buf, 0, -1, true, vim.split(content, "\n")) | ||
|
||
callback(buf) | ||
|
||
vim.api.nvim_buf_delete(buf, { force = true }) | ||
end | ||
|
||
return tests |
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