diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..0d63aec --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,42 @@ +name: Tests + +on: [push, pull_request] + +jobs: + unit_tests: + name: unit tests + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-22.04 + url: https://github.com/neovim/neovim/releases/download/nightly/nvim-linux64.tar.gz + steps: + - uses: actions/checkout@v2 + - run: date +%F > todays-date + - name: Restore cache for today's nightly. + uses: actions/cache@v2 + with: + path: | + _neovim + key: ${{ runner.os }}-x64-${{ hashFiles('todays-date') }} + + - name: Prepare + run: | + mkdir -p ~/.local/share/nvim/site/pack/vendor/start + git clone --depth 1 https://github.com/nvim-lua/plenary.nvim ~/.local/share/nvim/site/pack/vendor/start/plenary.nvim + + ln -s $(pwd) ~/.local/share/nvim/site/pack/vendor/start + + # sudo apt install go + test -d _neovim || { + mkdir -p _neovim + curl -sL ${{ matrix.url }} | tar xzf - --strip-components=1 -C "${PWD}/_neovim" + } + + - name: Run tests + run: | + export PATH="${PWD}/_neovim/bin:${PATH}" + nvim --headless -u tests/minimal.vim -c "q" + make test diff --git a/Makefile b/Makefile index 457aeaf..1e2bdf5 100644 --- a/Makefile +++ b/Makefile @@ -5,3 +5,6 @@ lint: fmt: stylua --config-path stylua.toml --glob 'lua/**/*.lua' -- lua + +test: + nvim --headless --noplugin -u tests/minimal.vim -c "PlenaryBustedDirectory tests/ {minimal_init = 'tests/minimal.vim'}" diff --git a/lua/openingh/utils.lua b/lua/openingh/utils.lua index 0907206..ff01696 100644 --- a/lua/openingh/utils.lua +++ b/lua/openingh/utils.lua @@ -78,6 +78,12 @@ end -- opens a url in the correct OS function M.open_url(url) + -- when running in test env store the url + if vim.g.test then + vim.g.OPENINGH_RESULT = url + return true + end + -- order here matters -- wsl must come before win -- wsl must come before linux diff --git a/tests/minimal.vim b/tests/minimal.vim new file mode 100644 index 0000000..0c6dda4 --- /dev/null +++ b/tests/minimal.vim @@ -0,0 +1,21 @@ +set rtp +=. +set rtp +=../plenary.nvim/ + + +runtime! plugin/plenary.vim + + +set noswapfile +set nobackup + +filetype indent off +set nowritebackup +set noautoindent +set nocindent +set nosmartindent +set indentexpr= + + +lua << EOF +require("plenary/busted") +EOF diff --git a/tests/openingh_spec.lua b/tests/openingh_spec.lua new file mode 100644 index 0000000..e6d09f8 --- /dev/null +++ b/tests/openingh_spec.lua @@ -0,0 +1,42 @@ +vim.g.test = true + +describe("busted should run", function() + it("should start test", function() + vim.cmd([[packadd openingh.nvim]]) + local status = require("plenary.reload").reload_module(".nvim") + assert.are.same(status, nil) + end) + + it("require('openingh')", function() + local status = require("openingh") + assert.truthy(status) + end) +end) + +describe("openingh should set user commands", function() + it("should set :OpenInGHRepo", function() + local status = vim.fn.exists(":OpenInGHRepo") + assert.truthy(status) + end) + + it("should set :OpenInGHFile", function() + local status = vim.fn.exists(":OpenInGHFile") + assert.truthy(status) + end) +end) + +describe("openingh should open", function() + it("repo on :OpenInGHRepo", function() + vim.cmd("OpenInGHRepo") + local status = vim.g.OPENINGH_RESULT + assert.truthy(status) + end) + + it("file on :OpenInGHFile", function() + vim.cmd("e ./README.md") + vim.cmd("OpenInGHFile") + + local status = vim.g.OPENINGH_RESULT + assert.truthy(status) + end) +end)