From e305f1af33f77150d9b0abbcafd4673d355bdc5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Harnes?= Date: Wed, 6 Dec 2023 19:25:13 +0100 Subject: [PATCH] ci: add initial util test --- .github/workflows/ci.yml | 22 ++++++++++++++++++++++ .gitignore | 2 +- tests/init.lua | 33 +++++++++++++++++++++++++++++++++ tests/run | 3 +++ tests/util_spec.lua | 8 ++++++++ 5 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 tests/init.lua create mode 100755 tests/run create mode 100644 tests/util_spec.lua diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bb0ee0a..5a727e1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.gitignore b/.gitignore index 19bfd3e..451bff4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -*.md +.tests doc/tags diff --git a/tests/init.lua b/tests/init.lua new file mode 100644 index 0000000..e6608fb --- /dev/null +++ b/tests/init.lua @@ -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() diff --git a/tests/run b/tests/run new file mode 100755 index 0000000..f37e539 --- /dev/null +++ b/tests/run @@ -0,0 +1,3 @@ +#!/bin/sh + +nvim --headless -u tests/init.lua -c "PlenaryBustedDirectory tests/ {minimal_init = 'tests/init.lua', sequential = true}" diff --git a/tests/util_spec.lua b/tests/util_spec.lua new file mode 100644 index 0000000..4d4225d --- /dev/null +++ b/tests/util_spec.lua @@ -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)