Skip to content

Commit

Permalink
ci: add initial util test
Browse files Browse the repository at this point in the history
  • Loading branch information
HakonHarnes committed Dec 6, 2023
1 parent d2afa30 commit e305f1a
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 1 deletion.
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,30 @@ name: CI
on: [push, pull_request]

jobs:
tests:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Install Neovim
shell: bash
run: |
mkdir -p /tmp/nvim
wget -q https://github.com/neovim/neovim/releases/download/nightly/nvim.appimage -O /tmp/nvim/nvim.appimage
cd /tmp/nvim
chmod a+x ./nvim.appimage
./nvim.appimage --appimage-extract
echo "/tmp/nvim/squashfs-root/usr/bin/" >> $GITHUB_PATH
- name: Run Tests
run: |
nvim --version
[ ! -d tests ] && exit 0
nvim --headless -u tests/init.lua -c "PlenaryBustedDirectory tests/ {minimal_init = 'tests/init.lua', sequential = true}"
docs:
runs-on: ubuntu-latest
needs: tests
if: ${{ github.ref == 'refs/heads/main' }}
steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
*.md
.tests
doc/tags
33 changes: 33 additions & 0 deletions tests/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
local M = {}

function M.root(root)
local f = debug.getinfo(1, "S").source:sub(2)
return vim.fn.fnamemodify(f, ":p:h:h") .. "/" .. (root or "")
end

---@param plugin string
function M.load(plugin)
local name = plugin:match(".*/(.*)")
local package_root = M.root(".tests/site/pack/deps/start/")
if not vim.loop.fs_stat(package_root .. name) then
print("Installing " .. plugin)
vim.fn.mkdir(package_root, "p")
vim.fn.system({
"git",
"clone",
"--depth=1",
"https://github.com/" .. plugin .. ".git",
package_root .. "/" .. name,
})
end
end

function M.setup()
vim.cmd([[set runtimepath=$VIMRUNTIME]])
vim.opt.runtimepath:append(M.root())
vim.opt.packpath = { M.root(".tests/site") }

M.load("nvim-lua/plenary.nvim")
end

M.setup()
3 changes: 3 additions & 0 deletions tests/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

nvim --headless -u tests/init.lua -c "PlenaryBustedDirectory tests/ {minimal_init = 'tests/init.lua', sequential = true}"
8 changes: 8 additions & 0 deletions tests/util_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
local util = require("img-clip.util")

describe("util", function()
it("can get the directory path from the file path", function()
local dir_path = util.get_dir_path_from_filepath("/home/user/project/image.png")
assert.same("/home/user/project/", dir_path)
end)
end)

0 comments on commit e305f1a

Please sign in to comment.