Skip to content

Commit

Permalink
add testing framework
Browse files Browse the repository at this point in the history
  • Loading branch information
tronikelis committed Nov 1, 2024
1 parent 888b46c commit fdf6171
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: ci

on:
push

jobs:
ci:
runs-on: ubuntu-latest
steps:
- name: Cloning repo
uses: actions/checkout@v4

- name: Run tests
run: "./run_tests.sh"

17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM nickblah/luajit:2-luarocks

RUN apt-get update && apt-get install -y build-essential

RUN luarocks install busted
RUN echo "$(luarocks path --bin)" >> ~/.profile

# install neovim
RUN <<EOF
curl -LO https://github.com/neovim/neovim/releases/latest/download/nvim-linux64.tar.gz
rm -rf /opt/nvim
tar -C /opt -xzf nvim-linux64.tar.gz
EOF

ENV PATH="$PATH:/opt/nvim-linux64/bin"

CMD ["/bin/bash", "-c", "cd ~/test && busted ."]
8 changes: 8 additions & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

docker build -t tronikel/conflict-marker.nvim-test .

docker run --rm \
-v ./lua:/root/.config/nvim/lua/ \
-v ./test:/root/test/ \
tronikel/conflict-marker.nvim-test:latest
5 changes: 5 additions & 0 deletions test/.busted
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
return {
_all = {
lua = "./lua.sh",
},
}
3 changes: 3 additions & 0 deletions test/lua.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

nvim -c "set loadplugins" -l "$@"
34 changes: 34 additions & 0 deletions test/main_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
describe("main", function()
local nvim

local buf
local lines

before_each(function()
buf = 0
lines = {
[[<<<<<<< HEAD]],
[[local value = 5 + 7]],
[[print(value)]],
[[print(string.format("value is %d", value))]],
[[=======]],
[[local value = 1 - 1]],
[[>>>>>>> new_branch]],
}

nvim = vim.fn.jobstart(
{ "nvim", "--embed", "--headless", "-c", 'lua require("conflict-marker").setup()' },
{ rpc = true }
)
vim.fn.rpcrequest(nvim, "nvim_buf_set_lines", buf, 0, -1, true, lines)
end)

after_each(function()
vim.fn.jobstop(nvim)
end)

it("sets lines correctly", function()
local result = vim.fn.rpcrequest(nvim, "nvim_buf_get_lines", buf, 0, -1, true)
assert.is_same(result, lines)
end)
end)

0 comments on commit fdf6171

Please sign in to comment.