diff --git a/.busted b/.busted new file mode 100644 index 0000000..61d98b0 --- /dev/null +++ b/.busted @@ -0,0 +1,13 @@ +return { + _all = { + coverage = false, + lpath = "lua/?.lua;lua/?/init.lua", + lua = "~/.luarocks/bin/nlua", + }, + default = { + verbose = true + }, + tests = { + verbose = true + }, +} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0217cfa..d9a65a8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -4,7 +4,7 @@ on: pull_request: ~ push: branches: - - master + - main jobs: build: @@ -22,18 +22,21 @@ jobs: with: path: _neovim key: ${{ runner.os }}-x64-${{ hashFiles('todays-date') }} - - - name: Prepare plenary - run: | - 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: Setup neovim uses: rhysd/action-setup-vim@v1 with: neovim: true version: ${{ matrix.neovim_version }} + - name: Setup Lua + uses: leso-kn/gh-actions-lua@master + with: + luaVersion: "5.1" + + - name: Setup Luarocks + uses: hishamhm/gh-actions-luarocks@master + with: + luarocksVersion: "3.11.0" + - name: Run tests - run: | - nvim --headless --noplugin -u tests/minimal.vim -c "PlenaryBustedDirectory tests/ {minimal_init = 'tests/minimal.vim'}" + run: luarocks test --local diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d14386a --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/luarocks +/lua_modules +/.luarocks diff --git a/README.md b/README.md index 0a3e5bf..a8ec610 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,13 @@ This repository is a template for Neovim plugins written in Lua. The intention is that you use this template to create a new repository where you then adapt this readme and add your plugin code. The template includes the following: -- GitHub workflows to run linters and tests -- Packaging of tagged releases and upload to [LuaRocks](https://luarocks.org/) - if a [`LUAROCKS_API_KEY`](https://luarocks.org/settings/api-keys) is added - to the [GitHub Actions secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository) -- Minimal test setup +- GitHub workflows and configurations to run linters and tests +- Packaging of tagged releases and upload to [LuaRocks][luarocks] + if a [`LUAROCKS_API_KEY`][luarocks-api-key] is added + to the [GitHub Actions secrets][gh-actions-secrets] +- Minimal test setup: + - A `scm` [rockspec][rockspec-format], `nvim-lua-plugin-scm-1.rockspec` + - A `.busted` file - EditorConfig - A .luacheckrc @@ -22,6 +24,11 @@ To get started writing a Lua plugin, I recommend reading `:help lua-guide` and Anything that the majority of plugin authors will want to have is in scope of this starter template. Anything that is controversial is out-of-scope. +## Usage + +- Click [Use this template][use-this-template]. Do not fork. +- Rename `nvim-lua-plugin-scm-1.rockspec` and change the `package` name + to the name of your plugin. ## Template License @@ -41,19 +48,36 @@ The remainder of the README is text that can be preserved in your plugin: ### Run tests -Running tests requires [plenary.nvim][plenary] to be checked out in the parent directory of *this* repository. +Running tests requires either + +- [luarocks][luarocks] +- or [busted][busted] and [nlua][nlua] + +to be installed[^1]. + +[^1]: The test suite assumes that `nlua` has been installed + using luarocks into `~/.luarocks/bin/`. + You can then run: ```bash -nvim --headless --noplugin -u tests/minimal.vim -c "PlenaryBustedDirectory tests/ {minimal_init = 'tests/minimal.vim'}" +luarocks test --local +# or +busted ``` Or if you want to run a single test file: ```bash -nvim --headless --noplugin -u tests/minimal.vim -c "PlenaryBustedDirectory tests/path_to_file.lua {minimal_init = 'tests/minimal.vim'}" +luarocks test spec/path_to_file.lua --local +# or +busted spec/path_to_file.lua ``` - -[nvim-lua-guide]: https://github.com/nanotee/nvim-lua-guide -[plenary]: https://github.com/nvim-lua/plenary.nvim +[rockspec-format]: https://github.com/luarocks/luarocks/wiki/Rockspec-format +[luarocks]: https://luarocks.org +[luarocks-api-key]: https://luarocks.org/settings/api-keys +[gh-actions-secrets]: https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository +[busted]: https://lunarmodules.github.io/busted/ +[nlua]: https://github.com/mfussenegger/nlua +[use-this-template]: https://github.com/new?template_name=nvim-lua-plugin-template&template_owner=nvim-lua diff --git a/nvim-lua-plugin-scm-1.rockspec b/nvim-lua-plugin-scm-1.rockspec new file mode 100644 index 0000000..94689e9 --- /dev/null +++ b/nvim-lua-plugin-scm-1.rockspec @@ -0,0 +1,23 @@ +rockspec_format = '3.0' +-- TODO: Rename this file and set the package +package = "nvim-lua-plugin" +version = "scm-1" +source = { + -- TODO: Update this URL + url = "git+https://github.com/nvim-lua/nvim-lua-plugin-template" +} +dependencies = { + -- Add runtime dependencies here + -- e.g. "plenary.nvim", +} +test_dependencies = { + "nlua" +} +build = { + type = "builtin", + copy_directories = { + -- Add runtimepath directories, like + -- 'plugin', 'ftplugin', 'doc' + -- here. DO NOT add 'lua' or 'lib'. + }, +} diff --git a/tests/example_spec.lua b/spec/example_spec.lua similarity index 100% rename from tests/example_spec.lua rename to spec/example_spec.lua diff --git a/tests/minimal.vim b/tests/minimal.vim deleted file mode 100644 index 7547e39..0000000 --- a/tests/minimal.vim +++ /dev/null @@ -1,3 +0,0 @@ -set rtp+=. -set rtp+=../plenary.nvim -runtime! plugin/plenary.vim