diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..413af35 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,54 @@ +name: CI + +on: [push, pull_request] + +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 + manager: sudo apt-get + packages: -y fd-find + - os: ubuntu-20.04 + url: https://github.com/neovim/neovim/releases/download/v0.7.0/nvim-linux64.tar.gz + manager: sudo apt-get + packages: -y fd-find + - os: macos-10.15 + url: https://github.com/neovim/neovim/releases/download/nightly/nvim-macos.tar.gz + manager: brew + packages: fd + - os: macos-10.15 + url: https://github.com/neovim/neovim/releases/download/v0.7.0/nvim-macos.tar.gz + manager: brew + packages: fd + 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: | + ${{ matrix.manager }} update + ${{ matrix.manager }} install ${{ matrix.packages }} + 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/Makefile b/Makefile index 0e02f4c..d8e7650 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,5 @@ +test: + nvim --headless --noplugin -u scripts/minimal_init.vim -c "PlenaryBustedDirectory lua/tests/ { minimal_init = './scripts/minimal_init.vim' }" + lint: luacheck lua/trim diff --git a/lua/tests/test_spec.lua b/lua/tests/test_spec.lua new file mode 100644 index 0000000..c790eb5 --- /dev/null +++ b/lua/tests/test_spec.lua @@ -0,0 +1,10 @@ +local eq = assert.are.same +local trimmer = require 'trim.trimmer' +local config = require 'trim.config' + +describe("trimmer.trim", function() + -- TODO + it("should be true", function() + eq(true, true) + end) +end) diff --git a/lua/trim/init.lua b/lua/trim/init.lua index 1648e3e..4376398 100644 --- a/lua/trim/init.lua +++ b/lua/trim/init.lua @@ -1,5 +1,6 @@ local vim = vim local config = require 'trim.config' +local trimmer = require 'trim.trimmer' local M = {} @@ -25,7 +26,7 @@ M.setup = function(cfg) pattern = '*', callback = function() if not has_value(cfg.disable, vim.bo.filetype) then - require 'trim.trimmer'.trim(cfg.patterns) + trimmer.trim(cfg.patterns) end end, group = 'TrimNvim' diff --git a/lua/trim/trimmer.lua b/lua/trim/trimmer.lua index c0415bc..9a03f7f 100644 --- a/lua/trim/trimmer.lua +++ b/lua/trim/trimmer.lua @@ -4,11 +4,11 @@ local api = vim.api local trimmer = {} trimmer.trim = function(patterns) - local save = vim.fn.winsaveview() - for _, v in pairs(patterns) do - api.nvim_exec(string.format("keepjumps keeppatterns silent! %s", v), false) - end - vim.fn.winrestview(save) + local save = vim.fn.winsaveview() + for _, v in pairs(patterns) do + api.nvim_exec(string.format("keepjumps keeppatterns silent! %s", v), false) + end + vim.fn.winrestview(save) end return trimmer diff --git a/scripts/minimal_init.vim b/scripts/minimal_init.vim new file mode 100644 index 0000000..da29e2f --- /dev/null +++ b/scripts/minimal_init.vim @@ -0,0 +1,4 @@ +set rtp+=. +set rtp+=../plenary.nvim/ + +runtime! plugin/plenary.vim