Skip to content

Commit

Permalink
Remove full busted, make plenary.busted
Browse files Browse the repository at this point in the history
  • Loading branch information
tjdevries committed Dec 9, 2020
1 parent 7d555b5 commit 3182878
Show file tree
Hide file tree
Showing 81 changed files with 2,342 additions and 7,379 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
test:
nvim --headless -c 'lua require("plenary.test_harness"):test_directory("luaunit", "./tests/plenary/lu/")'
nvim --headless -c 'lua require("plenary.test_harness"):test_directory("busted", "./tests/plenary/bu/")'
nvim --headless -c 'PlenaryBustedDirectory tests/plenary/ tests/minimal_init.vim'
69 changes: 23 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,69 +45,46 @@ assert(result == "# plenary.nvim")

### plenary.test_harness

Supports both `busted` and `luaunit` style testing.
Supports (simple) busted-style testing. It implements a mock-ed busted interface, that will allow you to run simple
busted style tests in separate neovim instances.

#### Busted

See test files in `./tests/plenary/bu`.

Add the following line to the beginning of your test file:

```lua
require('plenary.test_harness'):setup_busted()
```

And then you can run your tests from command line by doing:
To run the current spec file in a floating window, you can use the keymap `<Plug>PlenaryTestFile`. For example:

```
-> nvim --headless -c 'lua require("plenary.test_harness"):test_directory("busted", "./tests/plenary/bu/", true)'
Loading Tests For: /home/tj/plugins/plenary.nvim/tests/plenary/bu/uses_nvim_spec.lua+
1 success / 0 failures / 0 errors / 0 pending : 0.000263 seconds
Loading Tests For: /home/tj/plugins/plenary.nvim/tests/plenary/bu/simple_busted_spec.lua+
1 success / 0 failures / 0 errors / 0 pending : 0.000255 seconds%
nmap <leader>t <Plug>PlenaryTestFile
```

OR you can run from within Neovim (in a new nvim instance, so you don't need to worry about hot reloading or anyything like that)
To run a whole directory from the command line, you could do something like:

```vim
lua require("plenary.test_harness"):test_directory("busted", "./tests/plenary/bu/")
```
nvim --headless -c 'PlenaryBustedDirectory tests/plenary/ tests/minimal_init.vim'
```

#### LuaUnit

See test files in `./tests/plenary/lu`. For example

```lua
local lu = require("luaunit")
Where the first argument is the directory you'd like to test. It will search for files with
the pattern `*_spec.lua` and execute them in parallel in separate neovim instances.

local Path = require("plenary.path")
local test_harness = require("plenary.test_harness")
The second argument is an optional init.vim to specify so that you can make reproducible tests!

TestPath = {}
The exit code is 0 when success and 1 when fail, so you can use it easily in a `Makefile`!

function TestPath:testReadme()
local p = Path:new("README.md")

lu.assertEquals(p.raw, "README.md")
end
NOTE:

function TestPath:testAbsolute()
local p = Path:new("README.md")
So far, the only supported busted items are:

lu.assertEquals(p:absolute(), vim.fn.fnamemodify("README.md", ":p"))
end
```
- `describe`
- `it`
- `pending`
- `assert.*` etc. (from luassert, which is bundled)

Running the command:

```
$ nvim --headless -c 'lua require("plenary.test_harness"):test_directory("luaunit", "./tests/plenary/lu/", true)'
```
OTHER NOTE:

This is awesome because it uses the vim lua APi in the tests and in the code! Which is always a hassle when
writing Lua plugins for Neovim. This makes it possible to actually write tests and get the results
We used to support `luaunit` and original `busted` but it turns out it was way too hard and not worthwhile
for the difficulty of getting them setup, particularly on other platforms or in CI. Now, we have a dep free
(or at least, no other installation steps necessary) `busted` implementation that can be used more easily.

I will make the test harness a little nicer to use in the future, but that's the general idea.
Please take a look at the new APIs and make any issues for things that aren't clear. I am happy to fix them
and make it work well :)


### plenary.popup
Expand Down
5 changes: 0 additions & 5 deletions lua/busted/README.md

This file was deleted.

164 changes: 0 additions & 164 deletions lua/busted/block.lua

This file was deleted.

69 changes: 0 additions & 69 deletions lua/busted/compatibility.lua

This file was deleted.

Loading

0 comments on commit 3182878

Please sign in to comment.