Skip to content

Commit

Permalink
Add GHA test workflow, update setup section in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mfussenegger committed May 31, 2024
1 parent 5ce2018 commit bf74f90
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 27 deletions.
13 changes: 13 additions & 0 deletions .busted
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
return {
_all = {
coverage = false,
lpath = "lua/?.lua;lua/?/init.lua",
lua = "~/.luarocks/bin/nlua",
},
default = {
verbose = true
},
tests = {
verbose = true
},
}
37 changes: 37 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
name: luarocks test

on:
push:
branches:
- main
pull_request:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Install neovim
uses: rhysd/action-setup-vim@v1
with:
neovim: true
version: nightly
- name: Install Lua
uses: leso-kn/gh-actions-lua@master
with:
luaVersion: "5.1"
- name: Install Luarocks
uses: hishamhm/gh-actions-luarocks@master
with:
luarocksVersion: "3.11.0"

- name: Install nlua using luarocks make
run: luarocks make --local

- name: Run tests
run: |
luarocks test --local
98 changes: 71 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,43 +69,87 @@ If you don't need [luarocks] support, copy it into any folder in your `$PATH`.

## Luarocks setup

### Neovim Plugin setup

You can use the [plugin
template](https://github.com/nvim-lua/nvim-lua-plugin-template) to create a new
repository that contains nlua/busted based test setup.

### Manual configuration

- Install luarocks using a package manager. For example `pacman -S luarocks`
- Create a configuration file under `~/.luarocks/config-nlua.lua` with the following content:
- Install `nlua` via `luarocks`:

`luarocks 3.10.0` and above:
```bash
luarocks --local install nlua
```

```lua
lua_version = "5.1"
variables = {
LUA = "$HOME/.luarocks/bin/nlua" -- path to where nlua is installed
LUA_INCDIR = "/usr/include/luajit-2.1",
}
```
At this point you should be able to use `nlua`. Confirm it with:

`luarocks 3.9.2` and below:
```bash
echo "print(1 + 2)" | ~/.luarocks/bin/nlua
```

```lua
lua_version = "5.1"
variables = {
lua_interpreter = "nlua"
LUA_INCDIR = "/usr/include/luajit-2.1",
LUA_BINDIR = "$HOME/.luarocks/bin", -- path to where nlua is installed
}
```

- Create a wrapper script somewhere in `$PATH` - e.g. in `~/.local/bin/nluarocks` - with the following content:
### Use cases

```bash
#!/usr/bin/env bash
- Use it with busted:

LUAROCKS_CONFIG=$HOME/.luarocks/config-nlua.lua luarocks --local "$@"
```
```bash
luarocks --local install busted
busted --lua nlua spec/mytest_spec.lua
```

Now you should be able to install packages from luarocks using the Neovim interpreter. For example:
If you see a `module 'busted.runner'` not found error you need to update your `LUA_PATH`:

```bash
nluarocks install busted
```
```bash
eval $(luarocks path --no-bin)
busted --lua nlua spec/mytest_spec.lua
```

- Use `nlua` with `luarocks`

This allows package installation directly via `nlua` instead of a system `lua`

Create a `~./luarocks/config-nlua.lua` with the following contents.

For `luarocks 3.10.0` and above:

```lua
lua_version = "5.1"
variables = {
LUA = "$HOME/.luarocks/bin/nlua" -- path to where nlua is installed
LUA_INCDIR = "/usr/include/luajit-2.1",
}
```

For `luarocks 3.9.2` and below:

```lua
lua_version = "5.1"
variables = {
lua_interpreter = "nlua"
LUA_INCDIR = "/usr/include/luajit-2.1",
LUA_BINDIR = "$HOME/.luarocks/bin", -- path to where nlua is installed
}
```

To make using this custom configuration a bit easier, you can create a small wrapper.
Create a file called `nluarocks` somewhere in `$PATH` - e.g. in
`~/.local/bin/nluarocks` - with the following content:

```bash
#!/usr/bin/env bash
LUAROCKS_CONFIG=$HOME/.luarocks/config-nlua.lua luarocks --local "$@"
```

Now you should be able to install packages from `luarocks` using the `nvim`
Lua-interpreter. For example:

```bash
nluarocks install busted
```


[luarocks]: https://luarocks.org/
Expand Down
23 changes: 23 additions & 0 deletions nlua-scm-1.rockspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
rockspec_format = '3.0'
package = 'nlua'
version = 'scm-1'

source = {
url = 'git+https://github.com/mfussenegger/nlua'
}

deploy = {
wrap_bin_scripts = false,
}

test_dependencies = {
"nlua"
}

build = {
type = "builtin",
modules = {},
install = {
bin = { nlua = 'nlua', },
},
}
5 changes: 5 additions & 0 deletions spec/nlua_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe("nlua", function()
it("can access vim.namespace", function()
assert.are.same(vim.trim(" a"), "a")
end)
end)

0 comments on commit bf74f90

Please sign in to comment.