Skip to content

Commit

Permalink
enable to test
Browse files Browse the repository at this point in the history
  • Loading branch information
cappyzawa committed Jun 16, 2022
1 parent 26219a8 commit ab366eb
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 6 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions lua/tests/test_spec.lua
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 2 additions & 1 deletion lua/trim/init.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local vim = vim
local config = require 'trim.config'
local trimmer = require 'trim.trimmer'

local M = {}

Expand All @@ -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'
Expand Down
10 changes: 5 additions & 5 deletions lua/trim/trimmer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions scripts/minimal_init.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set rtp+=.
set rtp+=../plenary.nvim/

runtime! plugin/plenary.vim

0 comments on commit ab366eb

Please sign in to comment.