test(refactor): improve directory layout for tests

This commit is contained in:
Price Hiller 2023-07-15 16:16:22 -05:00
parent 85d910e334
commit 00983e343f
No known key found for this signature in database
14 changed files with 22 additions and 38 deletions

View file

@ -1,6 +1,6 @@
{
"test-branches": {
"cmd": "nvim --headless -c \"lua require(\\\"plenary.test_harness\\\").test_directory('tests/branch_popup_spec.lua', {minimal_init = \\\"tests/init.lua\\\", sequential = true })\"",
"cmd": "nvim --headless -c \"lua require(\\\"plenary.test_harness\\\").test_directory('tests/specs/branch_popup_spec.lua', {minimal_init = \\\"tests/init.lua\\\", sequential = true })\"",
"kind": "term",
"env": {
"NEOGIT_LOG_CONSOLE": true,
@ -8,7 +8,7 @@
}
},
"test-process": {
"cmd": "nvim --headless -c \"lua require(\\\"plenary.test_harness\\\").test_directory('./tests/process_spec.lua', {minimal_init = \\\"tests/init.lua\\\", sequential = true })\"",
"cmd": "nvim --headless -c \"lua require(\\\"plenary.test_harness\\\").test_directory('./tests/specs/process_spec.lua', {minimal_init = \\\"tests/init.lua\\\", sequential = true })\"",
"kind": "term",
"env": {
"NEOGIT_LOG_CONSOLE": true,
@ -16,7 +16,7 @@
}
},
"test-all": {
"cmd": "nvim --headless -c \"lua require(\\\"plenary.test_harness\\\").test_directory('tests', {minimal_init = \\\"tests/init.lua\\\", sequential = true })\"",
"cmd": "nvim --headless -c \"lua require(\\\"plenary.test_harness\\\").test_directory('tests/specs', {minimal_init = \\\"tests/init.lua\\\", sequential = true })\"",
"kind": "term",
"env": {
"NEOGIT_LOG_CONSOLE": true,

View file

@ -20,7 +20,7 @@ else
ensure_installed("nvim-telescope/telescope.nvim")
end
require("plenary.test_harness").test_directory("tests", {
require("plenary.test_harness").test_directory("tests/specs", {
minimal_init = "tests/minimal_init.lua",
sequential = true,
})

View file

@ -1,29 +0,0 @@
local eq = assert.are.same
describe("proof of concept", function()
it("should work", function()
assert(true)
end)
it("should have access to vim global", function()
assert.is_not_nil(vim)
end)
it("should be able to interact with vim", function()
vim.cmd("let g:val = v:true")
eq(true, vim.g.val)
end)
it("has access to buffers", function()
require("neogit").setup()
vim.cmd("Neogit")
-- 1 is the neogit buffer just opened
-- 2 The hidden console buffer
for _, b in ipairs(vim.api.nvim_list_bufs()) do
local name = vim.api.nvim_buf_get_name(b)
local ft = vim.api.nvim_buf_get_option(b, "filetype")
local buftype = vim.api.nvim_buf_get_option(b, "buftype")
end
eq({ 1, 2 }, vim.api.nvim_list_bufs())
end)
end)

View file

@ -1,11 +1,13 @@
require("plenary.async").tests.add_to_env()
local util = require("tests.util.util")
local eq = assert.are.same
local process = require("neogit.process")
describe("process execution", function()
it("basic command", function()
local result = process.new({ cmd = { "cat", "process_test" }, cwd = "./tests" }):spawn_blocking(1000)
local result =
process.new({ cmd = { "cat", "process_test" }, cwd = util.get_test_files_dir() }):spawn_blocking(1000)
assert(result)
assert.are.same(result.stdout, {
"This is a test file",
@ -17,7 +19,8 @@ describe("process execution", function()
})
end)
it("can cat a file", function()
local result = process.new({ cmd = { "cat", "a.txt" }, cwd = "./tests" }):spawn_blocking(1000)
local result =
process.new({ cmd = { "cat", "a.txt" }, cwd = util.get_test_files_dir() }):spawn_blocking(1000)
assert(result)
assert.are.same(result.stdout, {
@ -74,8 +77,10 @@ describe("process execution", function()
assert.are.same(result.stdout, input)
end)
it("basic command trim", function()
local result =
process.new({ cmd = { "cat", "process_test" }, cwd = "./tests" }):spawn_blocking(1000):trim()
local result = process
.new({ cmd = { "cat", "process_test" }, cwd = util.get_test_files_dir() })
:spawn_blocking(1000)
:trim()
assert(result)
assert.are.same(result.stdout, {
"This is a test file",

View file

@ -2,7 +2,7 @@ local status = require("neogit.status")
local a = require("plenary.async")
local M = {}
local project_dir = vim.fn.getcwd()
local project_dir = require("tests.util.util").project_dir
-- very naiive implementation, we only use this to generate unique folder names
local function random_string(length)

View file

@ -1,5 +1,7 @@
local M = {}
M.project_dir = vim.fn.getcwd()
---Checks if both lists contain the same values. This does NOT check ordering.
---@param l1 any[]
---@param l2 any[]
@ -18,4 +20,10 @@ function M.lists_equal(l1, l2)
return true
end
---Returns the path to the raw test files directory
---@return string
function M.get_test_files_dir()
return M.project_dir .. "/tests/test_files/"
end
return M