diff --git a/.gitignore b/.gitignore index e6646c9..212e7d1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ plenary.nvim/ -tests/default_data/ -tests/custom_data/ +!tests/**/* .luarc.json diff --git a/Makefile b/Makefile index b0b13b9..2272acb 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,10 @@ all: 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 +TearDown check: stylua --color always --check . diff --git a/tests/autoload/autoload_allowed_dir_spec.lua b/tests/autoload/autoload_allowed_dir_spec.lua new file mode 100644 index 0000000..7cce379 --- /dev/null +++ b/tests/autoload/autoload_allowed_dir_spec.lua @@ -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) diff --git a/tests/autoload/autoload_session_spec.lua b/tests/autoload/autoload_session_spec.lua new file mode 100644 index 0000000..6479ada --- /dev/null +++ b/tests/autoload/autoload_session_spec.lua @@ -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) diff --git a/tests/minimal.vim b/tests/minimal.vim index da1e24a..e38889e 100644 --- a/tests/minimal.vim +++ b/tests/minimal.vim @@ -8,4 +8,7 @@ set noswapfile set noundofile runtime plugin/plenary.vim -command Test PlenaryBustedDirectory tests/ {minimal_init = 'tests/minimal.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 TearDown PlenaryBustedFile tests/teardown/clean_up_dirs.lua diff --git a/tests/setup/create_sessions_spec.lua b/tests/setup/create_sessions_spec.lua new file mode 100644 index 0000000..4fa88d1 --- /dev/null +++ b/tests/setup/create_sessions_spec.lua @@ -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) diff --git a/tests/stubs/test_autoload.txt b/tests/stubs/test_autoload.txt new file mode 100644 index 0000000..0509b5f --- /dev/null +++ b/tests/stubs/test_autoload.txt @@ -0,0 +1 @@ +If you're reading this, I guess auto-loading works diff --git a/tests/teardown/clean_up_dirs.lua b/tests/teardown/clean_up_dirs.lua new file mode 100644 index 0000000..f627986 --- /dev/null +++ b/tests/teardown/clean_up_dirs.lua @@ -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)