From aa45be80adc8bb407848c192d3f70bd6458d3eba Mon Sep 17 00:00:00 2001 From: olimorris Date: Tue, 8 Mar 2022 07:53:00 +0000 Subject: [PATCH] test: add initial tests and ci --- .github/workflows/ci.yml | 51 ++++++++++++++++++++++++++++++++++++++++ .gitignore | 2 ++ Makefile | 7 ++++++ tests/init_spec.lua | 35 +++++++++++++++++++++++++++ tests/minimal.vim | 11 +++++++++ 5 files changed, 106 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 Makefile create mode 100644 tests/init_spec.lua create mode 100644 tests/minimal.vim diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..056f4f8 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,51 @@ +name: Tests + +on: + push: + branches: [main] + pull_request: + branches: [main] + +# Cancel any in-progress CI runs for a PR if it is updated +concurrency: + group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }} + cancel-in-progress: true + +jobs: + unit_tests: + name: unit tests + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-20.04 + url: https://github.com/neovim/neovim/releases/download/nightly/nvim-linux64.tar.gz + - os: ubuntu-20.04 + url: https://github.com/neovim/neovim/releases/download/v0.6.0/nvim-linux64.tar.gz + + steps: + - uses: actions/checkout@v2 + - run: date +%F > todays-date + - name: Restore from todays cache + uses: actions/cache@v2 + with: + path: _neovim + key: ${{ runner.os }}-${{ matrix.url }}-${{ hashFiles('todays-date') }} + + - name: Prepare + run: | + test -d _neovim || { + mkdir -p _neovim + curl -sL ${{ matrix.url }} | tar xzf - --strip-components=1 -C "${PWD}/_neovim" + } + mkdir -p ~/.local/share/nvim/site/pack/vendor/start + git clone --depth 1 https://github.com/nvim-lua/plenary.nvim ~/.local/share/nvim/site/pack/vendor/start/plenary.nvim + ln -s $(pwd) ~/.local/share/nvim/site/pack/vendor/start + + - name: Run tests + run: | + export PATH="${PWD}/_neovim/bin:${PATH}" + export VIM="${PWD}/_neovim/share/nvim/runtime" + nvim --version + make test diff --git a/.gitignore b/.gitignore index 9bbbeea..7306d71 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ +plenary.nvim/ +tests/data/ .luarc.json diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b0b13b9 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +all: test + +test: + nvim --headless --noplugin -u tests/minimal.vim +Test + +check: + stylua --color always --check . diff --git a/tests/init_spec.lua b/tests/init_spec.lua new file mode 100644 index 0000000..79e20e2 --- /dev/null +++ b/tests/init_spec.lua @@ -0,0 +1,35 @@ +local e = vim.fn.fnameescape +local session_dir = vim.fn.getcwd() .. "/tests/data/" +require("persisted").setup({ + dir = session_dir +}) + +describe("With default settings", function() + after_each(function() + -- vim.fn.system("rm -rf " .. e(session_dir)) + end) + + it("saves a session", function() + -- Edit a buffer + vim.cmd(":e tests/data/test.txt") + vim.cmd(":w") + + -- Save the session + require("persisted").save() + + -- Check that it is written to disk + assert.equals(vim.g.persisting, true) + assert.equals(vim.fn.system("ls tests/data | wc -l"), "2\n") + end) + + it("loads a session", function() + -- Load a session + require("persisted").load() + + -- Read the buffers contents + local content = vim.fn.getline(1, '$') + + assert.equals(content[1], "This is a test file") + end) + +end) diff --git a/tests/minimal.vim b/tests/minimal.vim new file mode 100644 index 0000000..da1e24a --- /dev/null +++ b/tests/minimal.vim @@ -0,0 +1,11 @@ +if !isdirectory('plenary.nvim') + !git clone https://github.com/nvim-lua/plenary.nvim.git plenary.nvim + !git -C plenary.nvim reset --hard 1338bbe8ec6503ca1517059c52364ebf95951458 +endif + +set runtimepath+=plenary.nvim,. +set noswapfile +set noundofile + +runtime plugin/plenary.vim +command Test PlenaryBustedDirectory tests/ {minimal_init = 'tests/minimal.vim'}