Skip to content

Commit

Permalink
Added test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
YaroSpace committed Nov 9, 2024
1 parent 255afdb commit f82e06f
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 1 deletion.
16 changes: 16 additions & 0 deletions .busted
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
return {
_all = {
coverage = false,
-- lpath = "lua/?.lua;lua/?/init.lua;spec/?.lua",
lua = 'spec/nvim-shim.sh',
-- lua = 'nlua',
ROOT = {'spec'}
},
default = {
verbose = true
},
unit = {
ROOT = {'spec/unit'},
verbose = true,
},
}
78 changes: 78 additions & 0 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
name: 'Nvim Busted Action'
description: 'Test Neovim plugins with Busted'
author: 'Marc Jakobi'
branding:
color: 'purple'
icon: 'moon'
inputs:
nvim_version:
description: |
Version of Neovim to install. Valid values are 'stable', 'nightly' or version tag such
as 'v0.9.2'. Note that this value must exactly match to a tag name when installing the
specific version.
required: false
default: 'stable'
luarocks_version:
description: Version of LuaRocks to install.
required: false
default: '3.11.1'
before:
description: Script to run before running tests.
required: false
default: ''
runs:
using: "composite"
steps:

- uses: actions/cache@v3
id: cache-luarocks
name: Restore cache for luarocks packages.
with:
path: |
~/.luarocks
key: ${{ runner.os }}-luarocks-${{ inputs.luarocks_version }}
restore-keys: |
${{ runner.os }}-luarocks-
- run: date +%F > todays-date
shell: bash
- name: Restore cache for today's Neovim nightly.
if: ${{ inputs.nvim_version }} == 'nightly'
uses: actions/cache@v3
with:
path: _neovim
key: ${{ runner.os }}-x64-${{ hashFiles('todays-date') }}

- uses: rhysd/action-setup-vim@v1
with:
neovim: true
version: ${{ inputs.nvim_version }}

- name: Setup Lua
uses: leso-kn/gh-actions-lua@master
with:
luaVersion: "5.1"

- name: Setup LuaRocks
uses: hishamhm/gh-actions-luarocks@master
# FIXME: caching .luarocks doesn't set up the environment variables (PATH, LUA_PATH, ...) properly
# if: steps.cache-luarocks.outputs.cache-hit != 'true'
with:
luarocksVersion: ${{ inputs.luarocks_version }}

- name: Run 'before' script
if: ${{ inputs.before != '' }}
run: ${{ inputs.before }}
shell: bash

- name: Install busted and nlua
if: steps.cache-luarocks.outputs.cache-hit != 'true'
run: |
luarocks install busted --local
luarocks install nlua --local
shell: bash

- run: busted --run unit
# - run: luarocks test --local
shell: bash
23 changes: 23 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
name: Run tests
on:
pull_request: ~
push:
branches:
- main
- develop
jobs:
build:
name: Run tests
runs-on: ubuntu-latest
strategy:
matrix:
neovim_version: ['stable']
# neovim_version: ['nightly', 'stable']

steps:
- uses: actions/checkout@v4
- name: Run tests
uses: ./.github/actions/build
with:
nvim_version: ${{ matrix.neovim_version }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 💻 Lua console
# 💻 Lua console [![main](https://github.com/yarospace/lua-console.nvim/actions/workflows/test.yml/badge.svg?branch=main)] [![develop](https://github.com/yarospace/lua-console.nvim/actions/workflows/test.yml/badge.svg?branch=develop)]

**lua-console.nvim** is yet another REPL console to execute Lua, configure Neovim, explore its API and settings.
Acts as a user friendly replacement of command mode - messages loop and as a handy scratch pad to store and test code gists.
Expand Down
16 changes: 16 additions & 0 deletions lua-console.nvim-scm-1.rockspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
rockspec_format = '3.0'
package = 'lua-console.nvim'
version = 'scm-1'

test_dependencies = {
'lua >= 5.1',
-- 'nlua',
}

source = {
url = 'git://github.com/yarospace/' .. package,
}

build = {
type = 'builtin',
}
19 changes: 19 additions & 0 deletions spec/nvim-shim.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

export XDG_CONFIG_HOME='spec/xdg/config'
export XDG_STATE_HOME='spec/xdg/local/state'
export XDG_DATA_HOME='spec/xdg/local/share'

PLUGINS_PATH='nvim/site/pack/testing/start'
PLUGIN_NAME='lua-console.nvim'

mkdir -p ${XDG_DATA_HOME}/${PLUGINS_PATH}
ln -s $(pwd) ${XDG_DATA_HOME}/${PLUGINS_PATH}/${PLUGIN_NAME}
nvim --cmd 'set loadplugins' -l $@

nvim -l $@
exit_code=$?

rm -rf ${XDG_DATA_HOME}/nvim

exit $exit_code
12 changes: 12 additions & 0 deletions spec/unit/lua-console_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
describe('Lua-console', function()
local console

setup(function()
utils = require('lua-console.utils')
end)

it('test', function()
-- vim.print(utils)
assert.same(1,1)
end)
end)

0 comments on commit f82e06f

Please sign in to comment.