diff --git a/Makefile b/Makefile index 2272acb..919721b 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ 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 +TestGitBranching nvim --headless --noplugin -u tests/minimal.vim +Test nvim --headless --noplugin -u tests/minimal.vim +TearDown diff --git a/test_git_branching.txt b/test_git_branching.txt new file mode 100644 index 0000000..e69de29 diff --git a/tests/git_branching/git_branching_spec.lua b/tests/git_branching/git_branching_spec.lua new file mode 100644 index 0000000..e885542 --- /dev/null +++ b/tests/git_branching/git_branching_spec.lua @@ -0,0 +1,33 @@ +pcall(vim.fn.system, "rm -rf tests/git_branch_data") + +local session_dir = vim.fn.getcwd() .. "/tests/git_branch_data/" +require("persisted").setup({ + dir = session_dir, + use_git_branch = true, +}) + +describe("Git Branching", function() + it("creates a session", function() + vim.fn.system("mkdir tests/git_branch_data") + vim.fn.system("cd tests/git_branch_data && git init") + + assert.equals(vim.fn.system("ls tests/git_branch_data | wc -l"), "0\n") + + vim.cmd(":e tests/stubs/test_git_branching.txt") + vim.cmd(":w tests/git_branch_data/test_git_branching.txt") + + require("persisted").save() + assert.equals(vim.fn.system("ls tests/git_branch_data | wc -l"), "2\n") + end) + + it("ensures the session has the branch name in", function() + -- Workout what the name should be + local pattern = "/" + local name = vim.fn.getcwd():gsub(pattern, "%%") .. "_main.vim" + local session = vim.fn.glob(session_dir .. "*.vim", true, true)[1] + + session:gsub(session_dir .. "/", "") + assert.equals(session, vim.fn.getcwd() .. "/tests/git_branch_data/" .. name) + -- assert.equals(sessions[1]:gsub(pattern, "%%"), name) + end) +end) diff --git a/tests/minimal.vim b/tests/minimal.vim index e38889e..8956ed5 100644 --- a/tests/minimal.vim +++ b/tests/minimal.vim @@ -8,7 +8,8 @@ set noswapfile set noundofile runtime plugin/plenary.vim -command Setup PlenaryBustedFile tests/setup/create_sessions_spec.lua +command Setup PlenaryBustedDirectory tests/setup {minimal_init = 'tests/minimal.vim'} command TestAutoloading PlenaryBustedDirectory tests/autoload {minimal_init = 'tests/minimal.vim'} +command TestGitBranching PlenaryBustedDirectory tests/git_branching {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/stubs/test_git_branching.txt b/tests/stubs/test_git_branching.txt new file mode 100644 index 0000000..57c0b71 --- /dev/null +++ b/tests/stubs/test_git_branching.txt @@ -0,0 +1 @@ +Git branching is awesome diff --git a/tests/teardown/clean_up_dirs.lua b/tests/teardown/clean_up_dirs.lua index f627986..0d63b7f 100644 --- a/tests/teardown/clean_up_dirs.lua +++ b/tests/teardown/clean_up_dirs.lua @@ -1,6 +1,7 @@ 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/git_branch_data") pcall(vim.fn.system, "rm -rf tests/default_data") end) end)