diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e7d90f0..ce10721 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,33 +1,48 @@ ---- name: CI + on: - pull_request: ~ push: - branches: - - master + branches: [ main ] + pull_request: + branches: [ main ] + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true jobs: - build: - name: Run tests + commit_lint: + runs-on: ubuntu-latest + steps: + # Check commit messages + - uses: webiny/action-conventional-commits@v1.1.0 + + test: runs-on: ubuntu-latest + timeout-minutes: 10 + strategy: - fail-fast: true matrix: - neovim_branch: ["v0.8.1", "nightly"] + neovim_branch: + - 'v0.9.5' + - 'nightly' + + env: + NVIM_TEST_VERSION: ${{ matrix.neovim_branch }} steps: - # Checkout packer - - uses: actions/checkout@v2 - - # Prepare taken from telescope - - name: Prepare - run: | - mkdir -p _neovim - curl -sL https://github.com/neovim/neovim/releases/download/${{ matrix.neovim_branch }}/nvim-linux64.tar.gz | tar xzf - --strip-components=1 -C "${PWD}/_neovim" - - - name: Run tests - run: | - export PATH="${PWD}/_neovim/bin:${PATH}" - export VIM="${PWD}/_neovim/share/nvim/runtime" - nvim --version - make test + - name: Checkout + uses: actions/checkout@v3 + + - uses: leafo/gh-actions-lua@v9 + with: + luaVersion: "5.1.5" + + - uses: leafo/gh-actions-luarocks@v4 + + - name: Download nvim-test + run: make nvim-test + + - name: Run Test + run: make test diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2d07b94 --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ + +nvim-test: + git clone https://github.com/lewis6991/nvim-test + nvim-test/bin/nvim-test --init + +.PHONY: test +test: nvim-test + nvim-test/bin/nvim-test test \ + --lpath=$(PWD)/lua/?.lua \ + diff --git a/test/pluginspec_spec.lua b/test/pluginspec_spec.lua new file mode 100644 index 0000000..19347d5 --- /dev/null +++ b/test/pluginspec_spec.lua @@ -0,0 +1,50 @@ +local helpers = require('nvim-test.helpers') +local exec_lua = helpers.exec_lua +local eq = helpers.eq + +describe('plugin spec formats', function() + before_each(function() + helpers.clear() + + -- Make pckr available + exec_lua('package.path = ...', package.path) + end) + + it('can process a simple string spec', function() + eq({ + ['gitsigns.nvim'] = { + install_path = '/gitsigns.nvim', + installed = false, + name = 'gitsigns.nvim', + revs = { }, + simple = true, + type = 'git', + url = 'https://github.com/lewis6991/gitsigns.nvim' + } }, exec_lua[[ + return require('pckr.plugin').process_spec { 'lewis6991/gitsigns.nvim' } + ]]) + end) + + it('can process a simple table spec', function() + exec_lua[[ + require('pckr.plugin').process_spec { + } + ]] + eq({ + ['gitsigns.nvim'] = { + install_path = '/gitsigns.nvim', + installed = false, + name = 'gitsigns.nvim', + revs = { }, + simple = false, + tag = 'v0.7', + type = 'git', + url = 'https://github.com/lewis6991/gitsigns.nvim' + } }, exec_lua[[ + return require('pckr.plugin').process_spec { + { 'lewis6991/gitsigns.nvim', tag = "v0.7" } + } + ]]) + end) + +end) diff --git a/tests/helpers.lua b/tests/helpers.lua deleted file mode 100644 index 7187970..0000000 --- a/tests/helpers.lua +++ /dev/null @@ -1,27 +0,0 @@ -local util = require 'packer.util' - -local M = { base_dir = '/tmp/__packer_tests__' } - ----Create a fake git repository ----@param name string ----@param base string -function M.create_git_dir(name, base) - base = base or M.base_dir - local repo_path = util.join_paths(base, name) - local path = util.join_paths(repo_path, '.git') - if vim.fn.isdirectory(path) > 0 then - M.cleanup_dirs(path) - end - vim.fn.mkdir(path, 'p') - return repo_path -end - ----Remove directories created for test purposes ----@vararg string -function M.cleanup_dirs(...) - for _, dir in ipairs { ... } do - vim.fn.delete(dir, 'rf') - end -end - -return M diff --git a/tests/local_plugin_spec.lua b/tests/local_plugin_spec.lua deleted file mode 100644 index eb99d96..0000000 --- a/tests/local_plugin_spec.lua +++ /dev/null @@ -1,32 +0,0 @@ -local a = require('plenary.async_lib.tests') -local local_plugin = require('packer.plugin_types.local') -local packer_path = vim.fn.stdpath('data') .. '/site/pack/packer/start/' -local helpers = require('tests.helpers') - -a.describe('Local plugin -', function() - a.describe('installer', function() - local local_plugin_path - local repo_name = 'test.nvim' - local plugin_install_path = packer_path .. repo_name - - before_each(function() - vim.fn.mkdir(packer_path, 'p') - local_plugin_path = helpers.create_git_dir(repo_name) - end) - - after_each(function() helpers.cleanup_dirs(local_plugin_path, plugin_install_path) end) - - a.it('should create a symlink', function() - local plugin_spec = { - name = local_plugin_path, - path = local_plugin_path, - install_path = plugin_install_path - } - - local_plugin.setup(plugin_spec) - plugin_spec.installer({task_update = function() end})() - - assert.equal('link', vim.loop.fs_lstat(plugin_install_path).type) - end) - end) -end) 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 diff --git a/tests/packer_plugin_utils_spec.lua b/tests/packer_plugin_utils_spec.lua deleted file mode 100644 index 9181847..0000000 --- a/tests/packer_plugin_utils_spec.lua +++ /dev/null @@ -1,24 +0,0 @@ -local a = require('plenary.async_lib.tests') -local plugin_utils = require("packer.plugin_utils") -local packer_path = vim.fn.stdpath("data") .. "/site/pack/packer/start/" - -a.describe("Packer post update hooks", function() - local test_plugin_path = packer_path .. "test_plugin/" - local run_hook = plugin_utils.post_update_hook - - before_each(function() vim.fn.mkdir(test_plugin_path, "p") end) - - after_each(function() vim.fn.delete(test_plugin_path, "rf") end) - - a.it("should run the command in the correct folder", function() - local plugin_spec = { - name = "test/test_plugin", - install_path = test_plugin_path, - run = "touch 'this_file_should_exist'" - } - - run_hook(plugin_spec, {task_update = function() end}) - - assert.truthy(vim.loop.fs_stat(test_plugin_path .. "this_file_should_exist")) - end) -end) diff --git a/tests/packer_use_spec.lua b/tests/packer_use_spec.lua deleted file mode 100644 index a1350b9..0000000 --- a/tests/packer_use_spec.lua +++ /dev/null @@ -1,28 +0,0 @@ -local packer = require("packer") -local use = packer.__use -local packer_path = vim.fn.stdpath("data").."/site/pack/packer/start/" - -describe("Packer use tests", function() - after_each(function() - packer.reset() - end) - - it("should set the correct install path", function () - local spec = {"test/plugin1"} - packer.startup(function() - use(spec) - end) - packer.__manage_all() - assert.truthy(spec.install_path) - assert.equal(spec.install_path, packer_path .. spec.name) - end) - - it("should add metadata to a plugin from a spec", function () - local spec = {"test/plugin1"} - packer.startup(function() - use(spec) - end) - packer.__manage_all() - assert.equal(spec.name, "test/plugin1") - end) -end) diff --git a/tests/plugin_utils_spec.lua b/tests/plugin_utils_spec.lua deleted file mode 100644 index 9bb9c9f..0000000 --- a/tests/plugin_utils_spec.lua +++ /dev/null @@ -1,77 +0,0 @@ -local a = require('plenary.async_lib.tests') -local async = require('packer.async').sync -local plugin_utils = require('packer.plugin_utils') -local helpers = require("tests.helpers") - -local fmt = string.format - -a.describe('Plugin utils -', function() - - a.describe('find_missing_plugins', function() - local repo_name = "test.nvim" - local path - - plugin_utils.cfg({start_dir = helpers.base_dir}) - - before_each(function() path = helpers.create_git_dir(repo_name) end) - - after_each(function() helpers.cleanup_dirs("tmp/packer") end) - - a.it('should pick up plugins with a different remote URL', function() - local test_repo_name = fmt('user2/%s', repo_name) - local plugins = { - [repo_name] = { - opt = false, - type = "git", - name = repo_name, - remote_url = function() - return async(function() - return {ok = {remote = fmt('https://github.com/%s', test_repo_name)}} - end) - end - } - } - local result = plugin_utils.find_missing_plugins(plugins, {}, {[path] = true})() - assert.truthy(result) - assert.equal(1, #vim.tbl_keys(result)) - end) - - a.it('should not pick up plugins with the same remote URL', function() - local test_repo_name = fmt('user1/%s', repo_name) - local plugins = { - [repo_name] = { - opt = false, - type = "git", - name = repo_name, - remote_url = function() - return async(function() - return {ok = {remote = fmt('https://github.com/%s', test_repo_name)}} - end) - end - } - } - local result = plugin_utils.find_missing_plugins(plugins, {}, {[path] = true})() - assert.truthy(result) - assert.equal(0, #result) - end) - - a.it('should handle ssh git urls', function() - local test_repo_name = fmt('user2/%s', repo_name) - local plugins = { - [repo_name] = { - opt = false, - type = "git", - name = repo_name, - remote_url = function() - return async(function() - return {ok = {remote = fmt('git@github.com:%s.git', test_repo_name)}} - end) - end - } - } - local result = plugin_utils.find_missing_plugins(plugins, {}, {[path] = true})() - assert.truthy(result) - assert.equal(1, #vim.tbl_keys(result)) - end) - end) -end)