chore: add testing for user commands

This commit is contained in:
Ali Almohaya 2022-10-30 02:03:40 +03:00
parent cb378a6d8c
commit 264f7897bf
No known key found for this signature in database
GPG key ID: 4B80BC43FC6007E0
5 changed files with 114 additions and 0 deletions

42
.github/workflows/ci.yml vendored Normal file
View file

@ -0,0 +1,42 @@
name: Tests
on: [push, pull_request]
jobs:
unit_tests:
name: unit tests
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-22.04
url: https://github.com/neovim/neovim/releases/download/nightly/nvim-linux64.tar.gz
steps:
- uses: actions/checkout@v2
- run: date +%F > todays-date
- name: Restore cache for today's nightly.
uses: actions/cache@v2
with:
path: |
_neovim
key: ${{ runner.os }}-x64-${{ hashFiles('todays-date') }}
- name: Prepare
run: |
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
# sudo apt install go
test -d _neovim || {
mkdir -p _neovim
curl -sL ${{ matrix.url }} | tar xzf - --strip-components=1 -C "${PWD}/_neovim"
}
- name: Run tests
run: |
export PATH="${PWD}/_neovim/bin:${PATH}"
nvim --headless -u tests/minimal.vim -c "q"
make test

View file

@ -5,3 +5,6 @@ lint:
fmt:
stylua --config-path stylua.toml --glob 'lua/**/*.lua' -- lua
test:
nvim --headless --noplugin -u tests/minimal.vim -c "PlenaryBustedDirectory tests/ {minimal_init = 'tests/minimal.vim'}"

View file

@ -78,6 +78,12 @@ end
-- opens a url in the correct OS
function M.open_url(url)
-- when running in test env store the url
if vim.g.test then
vim.g.OPENINGH_RESULT = url
return true
end
-- order here matters
-- wsl must come before win
-- wsl must come before linux

21
tests/minimal.vim Normal file
View file

@ -0,0 +1,21 @@
set rtp +=.
set rtp +=../plenary.nvim/
runtime! plugin/plenary.vim
set noswapfile
set nobackup
filetype indent off
set nowritebackup
set noautoindent
set nocindent
set nosmartindent
set indentexpr=
lua << EOF
require("plenary/busted")
EOF

42
tests/openingh_spec.lua Normal file
View file

@ -0,0 +1,42 @@
vim.g.test = true
describe("busted should run", function()
it("should start test", function()
vim.cmd([[packadd openingh.nvim]])
local status = require("plenary.reload").reload_module(".nvim")
assert.are.same(status, nil)
end)
it("require('openingh')", function()
local status = require("openingh")
assert.truthy(status)
end)
end)
describe("openingh should set user commands", function()
it("should set :OpenInGHRepo", function()
local status = vim.fn.exists(":OpenInGHRepo")
assert.truthy(status)
end)
it("should set :OpenInGHFile", function()
local status = vim.fn.exists(":OpenInGHFile")
assert.truthy(status)
end)
end)
describe("openingh should open", function()
it("repo on :OpenInGHRepo", function()
vim.cmd("OpenInGHRepo")
local status = vim.g.OPENINGH_RESULT
assert.truthy(status)
end)
it("file on :OpenInGHFile", function()
vim.cmd("e ./README.md")
vim.cmd("OpenInGHFile")
local status = vim.g.OPENINGH_RESULT
assert.truthy(status)
end)
end)