From f82e06fff2bdc12cedfc113a72692466e9d57e38 Mon Sep 17 00:00:00 2001 From: Yaro Date: Sat, 9 Nov 2024 23:01:43 +0300 Subject: [PATCH] Added test suite --- .busted | 16 +++++++ .github/actions/build/action.yml | 78 ++++++++++++++++++++++++++++++++ .github/workflows/test.yml | 23 ++++++++++ README.md | 2 +- lua-console.nvim-scm-1.rockspec | 16 +++++++ spec/nvim-shim.sh | 19 ++++++++ spec/unit/lua-console_spec.lua | 12 +++++ 7 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 .busted create mode 100644 .github/actions/build/action.yml create mode 100644 .github/workflows/test.yml create mode 100644 lua-console.nvim-scm-1.rockspec create mode 100755 spec/nvim-shim.sh create mode 100644 spec/unit/lua-console_spec.lua diff --git a/.busted b/.busted new file mode 100644 index 0000000..b0ffa14 --- /dev/null +++ b/.busted @@ -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, + }, +} diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml new file mode 100644 index 0000000..87ca369 --- /dev/null +++ b/.github/actions/build/action.yml @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..3856690 --- /dev/null +++ b/.github/workflows/test.yml @@ -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 }} diff --git a/README.md b/README.md index 028b63d..3785b05 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/lua-console.nvim-scm-1.rockspec b/lua-console.nvim-scm-1.rockspec new file mode 100644 index 0000000..d7dddba --- /dev/null +++ b/lua-console.nvim-scm-1.rockspec @@ -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', +} diff --git a/spec/nvim-shim.sh b/spec/nvim-shim.sh new file mode 100755 index 0000000..9bb3bcc --- /dev/null +++ b/spec/nvim-shim.sh @@ -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 diff --git a/spec/unit/lua-console_spec.lua b/spec/unit/lua-console_spec.lua new file mode 100644 index 0000000..1692fe3 --- /dev/null +++ b/spec/unit/lua-console_spec.lua @@ -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)