chore: improve test coverage

main
olimorris 2022-04-06 23:23:02 +01:00
parent 23151e4db6
commit f886f9a2ec
8 changed files with 74 additions and 3 deletions

3
.gitignore vendored
View File

@ -1,4 +1,3 @@
plenary.nvim/ plenary.nvim/
tests/default_data/ !tests/**/*
tests/custom_data/
.luarc.json .luarc.json

View File

@ -1,7 +1,10 @@
all: test all: test
test: test:
nvim --headless --noplugin -u tests/minimal.vim +Setup
nvim --headless --noplugin -u tests/minimal.vim +TestAutoloading
nvim --headless --noplugin -u tests/minimal.vim +Test nvim --headless --noplugin -u tests/minimal.vim +Test
nvim --headless --noplugin -u tests/minimal.vim +TearDown
check: check:
stylua --color always --check . stylua --color always --check .

View File

@ -0,0 +1,21 @@
local e = vim.fn.fnameescape
local session_dir = vim.fn.getcwd() .. "/tests/dummy_data/"
require("persisted").setup({
dir = session_dir,
autoload = true,
autosave = true,
allowed_dirs = { vim.fn.getcwd() },
})
describe("With custom settings:", function()
-- after_each(function()
-- vim.fn.system("rm -rf " .. e(session_dir))
-- end)
it("autoloads a file with allowed_dirs", function()
local content = vim.fn.getline(1, '$')
assert.equals(content[1], "If you're reading this, I guess auto-loading works")
end)
end)

View File

@ -0,0 +1,16 @@
local e = vim.fn.fnameescape
local session_dir = vim.fn.getcwd() .. "/tests/dummy_data/"
require("persisted").setup({
dir = session_dir,
autoload = true,
autosave = true,
})
describe("With custom settings:", function()
it("autoloads a file", function()
local content = vim.fn.getline(1, '$')
assert.equals(content[1], "If you're reading this, I guess auto-loading works")
end)
end)

View File

@ -8,4 +8,7 @@ set noswapfile
set noundofile set noundofile
runtime plugin/plenary.vim runtime plugin/plenary.vim
command Setup PlenaryBustedFile tests/setup/create_sessions_spec.lua
command TestAutoloading PlenaryBustedDirectory tests/autoload {minimal_init = 'tests/minimal.vim'}
command Test PlenaryBustedDirectory tests/ {minimal_init = 'tests/minimal.vim'} command Test PlenaryBustedDirectory tests/ {minimal_init = 'tests/minimal.vim'}
command TearDown PlenaryBustedFile tests/teardown/clean_up_dirs.lua

View File

@ -0,0 +1,22 @@
pcall(vim.fn.system, "rm -rf tests/dummy_data")
local session_dir = vim.fn.getcwd() .. "/tests/dummy_data/"
require("persisted").setup({
dir = session_dir,
autoload = true,
autosave = true,
})
describe("As part of the setup", function()
it("a session is created to autoload from", function()
vim.cmd(":e tests/stubs/test_autoload.txt")
vim.cmd(":w")
require("persisted").save()
end)
-- it("autoloads a file", function()
-- local content = vim.fn.getline(1, '$')
-- assert.equals(content[1], "This is a test file for custom config")
-- end)
end)

View File

@ -0,0 +1 @@
If you're reading this, I guess auto-loading works

View File

@ -0,0 +1,6 @@
describe("As part of the teardown", function()
it("dummy data is deleted", function()
pcall(vim.fn.system, "rm -rf tests/dummy_data")
pcall(vim.fn.system, "rm -rf tests/default_data")
end)
end)