mirror of
https://github.com/TimUntersberger/neogit
synced 2024-09-16 14:24:09 +02:00
test(refactor): improve directory layout for tests
This commit is contained in:
parent
85d910e334
commit
00983e343f
14 changed files with 22 additions and 38 deletions
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"test-branches": {
|
"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",
|
"kind": "term",
|
||||||
"env": {
|
"env": {
|
||||||
"NEOGIT_LOG_CONSOLE": true,
|
"NEOGIT_LOG_CONSOLE": true,
|
||||||
|
@ -8,7 +8,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"test-process": {
|
"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",
|
"kind": "term",
|
||||||
"env": {
|
"env": {
|
||||||
"NEOGIT_LOG_CONSOLE": true,
|
"NEOGIT_LOG_CONSOLE": true,
|
||||||
|
@ -16,7 +16,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"test-all": {
|
"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",
|
"kind": "term",
|
||||||
"env": {
|
"env": {
|
||||||
"NEOGIT_LOG_CONSOLE": true,
|
"NEOGIT_LOG_CONSOLE": true,
|
||||||
|
|
|
@ -20,7 +20,7 @@ else
|
||||||
ensure_installed("nvim-telescope/telescope.nvim")
|
ensure_installed("nvim-telescope/telescope.nvim")
|
||||||
end
|
end
|
||||||
|
|
||||||
require("plenary.test_harness").test_directory("tests", {
|
require("plenary.test_harness").test_directory("tests/specs", {
|
||||||
minimal_init = "tests/minimal_init.lua",
|
minimal_init = "tests/minimal_init.lua",
|
||||||
sequential = true,
|
sequential = true,
|
||||||
})
|
})
|
||||||
|
|
|
@ -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)
|
|
|
@ -1,11 +1,13 @@
|
||||||
require("plenary.async").tests.add_to_env()
|
require("plenary.async").tests.add_to_env()
|
||||||
|
local util = require("tests.util.util")
|
||||||
local eq = assert.are.same
|
local eq = assert.are.same
|
||||||
|
|
||||||
local process = require("neogit.process")
|
local process = require("neogit.process")
|
||||||
|
|
||||||
describe("process execution", function()
|
describe("process execution", function()
|
||||||
it("basic command", 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(result)
|
||||||
assert.are.same(result.stdout, {
|
assert.are.same(result.stdout, {
|
||||||
"This is a test file",
|
"This is a test file",
|
||||||
|
@ -17,7 +19,8 @@ describe("process execution", function()
|
||||||
})
|
})
|
||||||
end)
|
end)
|
||||||
it("can cat a file", function()
|
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(result)
|
||||||
assert.are.same(result.stdout, {
|
assert.are.same(result.stdout, {
|
||||||
|
@ -74,8 +77,10 @@ describe("process execution", function()
|
||||||
assert.are.same(result.stdout, input)
|
assert.are.same(result.stdout, input)
|
||||||
end)
|
end)
|
||||||
it("basic command trim", function()
|
it("basic command trim", function()
|
||||||
local result =
|
local result = process
|
||||||
process.new({ cmd = { "cat", "process_test" }, cwd = "./tests" }):spawn_blocking(1000):trim()
|
.new({ cmd = { "cat", "process_test" }, cwd = util.get_test_files_dir() })
|
||||||
|
:spawn_blocking(1000)
|
||||||
|
:trim()
|
||||||
assert(result)
|
assert(result)
|
||||||
assert.are.same(result.stdout, {
|
assert.are.same(result.stdout, {
|
||||||
"This is a test file",
|
"This is a test file",
|
|
@ -2,7 +2,7 @@ local status = require("neogit.status")
|
||||||
local a = require("plenary.async")
|
local a = require("plenary.async")
|
||||||
local M = {}
|
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
|
-- very naiive implementation, we only use this to generate unique folder names
|
||||||
local function random_string(length)
|
local function random_string(length)
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
M.project_dir = vim.fn.getcwd()
|
||||||
|
|
||||||
---Checks if both lists contain the same values. This does NOT check ordering.
|
---Checks if both lists contain the same values. This does NOT check ordering.
|
||||||
---@param l1 any[]
|
---@param l1 any[]
|
||||||
---@param l2 any[]
|
---@param l2 any[]
|
||||||
|
@ -18,4 +20,10 @@ function M.lists_equal(l1, l2)
|
||||||
return true
|
return true
|
||||||
end
|
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
|
return M
|
||||||
|
|
Loading…
Reference in a new issue