Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add testing using plenary and linting using luacheck #10

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Linting

on: [push, pull_request]

jobs:
selene:
name: selene
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: NTBBloodbath/[email protected]
with:
# Github secret token
token: ${{ secrets.GITHUB_TOKEN }}
# selene arguments
args: --display-style=quiet .
# selene version
version: 0.12.1
stylua:
name: stylua
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: JohnnyMorganz/stylua-action@v3
with:
version: latest
token: ${{ secrets.GITHUB_TOKEN }}
args: --color always --check lua
47 changes: 47 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Tests

on: [push, pull_request]

jobs:
tests:
name: unit tests
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
rev: nightly/nvim-linux64.tar.gz
manager: sudo apt-get
packages: -y ripgrep
- os: ubuntu-latest
rev: v0.9.0/nvim-linux64.tar.gz
manager: sudo apt-get
packages: -y ripgrep
steps:
- uses: actions/checkout@v3
- run: date +%F > todays-date
- name: Restore from todays cache
uses: actions/cache@v3
with:
path: _neovim
key: ${{ runner.os }}-${{ matrix.rev }}-${{ hashFiles('todays-date') }}

- name: Prepare
run: |
${{ matrix.manager }} update
${{ matrix.manager }} install ${{ matrix.packages }}
test -d _neovim || {
mkdir -p _neovim
curl -sL "https://github.com/neovim/neovim/releases/download/${{ matrix.rev }}" | 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
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.PHONY: test lint init

TESTS_DIR := tests/
PLUGIN_DIR := lua/

MINIMAL_INIT := ./scripts/minimal_init.vim

test:
nvim --headless --noplugin -u ${MINIMAL_INIT} \
-c "PlenaryBustedDirectory ${TESTS_DIR} { minimal_init = '${MINIMAL_INIT}' }"

lint:
selene .

format:
stylua --glob lua/**/*.lua tests/**/*.lua
22 changes: 22 additions & 0 deletions lua/tshjkl/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,28 @@ local nav = require('tshjkl.nav')

local M = {}

---@class TshjklKeymaps
---@field toggle any
---@field toggle_outer any
---@field parent any
---@field next any
---@field prev any
---@field child any
---@field toggle_named any

---@class TshjklMarks
---@field parent table
---@field child table
---@field next table
---@field prev table
---@field current table

---@class TshjklConfig
---@field select_current_node boolean
---@field keymaps TshjklKeymaps
---@field marks TshjklMarks

---@type TshjklConfig
local default_config = {
-- false to highlight only. Note that enabling this will hide the highlighting of child nodes
select_current_node = true,
Expand Down
7 changes: 7 additions & 0 deletions scripts/minimal_init.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set rtp+=.
set rtp+=../plenary.nvim/
set rtp+=../tree-sitter-lua/

runtime! plugin/plenary.vim
runtime! plugin/ts_lua.vim
runtime! plugin/tshjkl.lua
1 change: 1 addition & 0 deletions selene.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
std="vim"
10 changes: 10 additions & 0 deletions tests/tshjkl/example_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
local plugin = require('tshjkl')
local assert = require('luassert')

describe('setup with no custom options', function()
it('example spec', function()
-- TODO remove this example spec and add actual tests later
plugin.setup({})
assert.equals(plugin.did_setup, true)
end)
end)
55 changes: 55 additions & 0 deletions vim.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[selene]
base = "lua51"
name = "vim"

[vim]
any = true

[[describe.args]]
type = "string"
[[describe.args]]
type = "function"

[[it.args]]
type = "string"
[[it.args]]
type = "function"

[[before_each.args]]
type = "function"
[[after_each.args]]
type = "function"

[assert.is_not]
any = true

[assert.matches]
any = true

[assert.has_error]
any = true

[[assert.equals.args]]
type = "any"
[[assert.equals.args]]
type = "any"
[[assert.equals.args]]
type = "any"
required = false

[[assert.same.args]]
type = "any"
[[assert.same.args]]
type = "any"

[[assert.truthy.args]]
type = "any"

[[assert.falsy.args]]
type = "any"

[[assert.spy.args]]
type = "any"

[[assert.stub.args]]
type = "any"
Loading