Skip to content

Commit d34e1b8

Browse files
author
Matthieu Coudron
committed
feat: introduce a testing framework
Enter `nix develop ./contrib` to get all the necessary dependencies. Run 'make test' to run tests. Tests could drive the API towards a more programmatic interface. This is just a bootstrap to future work.
1 parent 0f26e2a commit d34e1b8

File tree

10 files changed

+116
-20
lines changed

10 files changed

+116
-20
lines changed

.github/workflows/default.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: default
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
tests:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
- uses: cachix/install-nix-action@v18
11+
with:
12+
nix_path: nixpkgs=channel:nixos-unstable
13+
- run: |
14+
nix develop ./contrib -c make test

.luacheckrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- Use lua52 so we will no receive errors regarding to goto statements
2-
std = 'lua52'
2+
std = 'lua52+busted'
33

44
-- Rerun tests only if their modification time changed
55
cache = true

Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ lint:
33

44
format:
55
stylua .
6+
7+
test:
8+
# possible args to test_directory: sequential=true,keep_going=false
9+
# minimal.vim is generated when entering the flake, aka `nix develop ./contrib`
10+
nvim --headless -u minimal.vim -c "lua require('plenary.test_harness').test_directory('.', {minimal_init='minimal.vim'})"
11+

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ request method (e.g. `GET`) and run `rest.nvim`.
157157
4. Push to the branch (<kbd>git push origin my-new-feature</kbd>)
158158
5. Create a new Pull Request
159159

160+
To run the tests, enter a nix shell with `nix develop ./contrib`, then run `make
161+
test`.
160162

161163
## Related software
162164

contrib/flake.nix

+61-14
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,83 @@
1111
let
1212
pkgs = nixpkgs.legacyPackages.${system};
1313

14-
mkPackage = luaVersion:
15-
pkgs."lua${luaVersion}Packages".luarocks;
16-
1714
mkDevShell = luaVersion:
1815
let
19-
luaPkgs = pkgs."lua${luaVersion}".pkgs;
16+
# luaPkgs = pkgs."lua${luaVersion}".pkgs;
2017
luaEnv = pkgs."lua${luaVersion}".withPackages (lp: with lp; [
2118
luacheck
2219
luarocks
23-
(pkgs.lib.hiPrio plenary-nvim)
2420
]);
21+
neovimConfig = pkgs.neovimUtils.makeNeovimConfig {
22+
plugins = with pkgs.vimPlugins; [
23+
{
24+
plugin = packer-nvim;
25+
type = "lua";
26+
config = ''
27+
require('packer').init({
28+
luarocks = {
29+
python_cmd = 'python' -- Set the python command to use for running hererocks
30+
},
31+
})
32+
-- require my own manual config
33+
require('init-manual')
34+
'';
35+
}
36+
{ plugin = (nvim-treesitter.withPlugins (
37+
plugins: with plugins; [
38+
tree-sitter-lua
39+
tree-sitter-http
40+
tree-sitter-json
41+
]
42+
));
43+
}
44+
{ plugin = plenary-nvim; }
45+
];
46+
customRC = "";
47+
wrapRc = false;
48+
};
49+
myNeovim = pkgs.wrapNeovimUnstable pkgs.neovim-unwrapped neovimConfig;
2550
in
26-
luaPkgs.luarocks.overrideAttrs (oa: {
27-
name = "luarocks-dev";
28-
buildInputs = oa.buildInputs ++ [
51+
pkgs.mkShell {
52+
name = "rest-nvim";
53+
buildInputs = [
2954
pkgs.sumneko-lua-language-server
3055
luaEnv
3156
pkgs.stylua
57+
myNeovim
3258
# pkgs.neovim # assume user has one already installed
3359
];
34-
});
60+
61+
shellHook = let
62+
myVimPackage = with pkgs.vimPlugins; {
63+
start = [ plenary-nvim (nvim-treesitter.withPlugins (
64+
plugins: with plugins; [
65+
tree-sitter-lua
66+
tree-sitter-http
67+
tree-sitter-json
68+
]
69+
))];
70+
# opt = map (x: x.plugin) pluginsPartitioned.right;
71+
};
72+
# };
73+
packDirArgs.myNeovimPackages = myVimPackage;
74+
in
75+
''
76+
cat <<-EOF > minimal.vim
77+
set rtp+=.
78+
set packpath^=${pkgs.vimUtils.packDir packDirArgs}
79+
EOF
80+
'';
81+
};
3582

3683
in
3784
{
3885

39-
packages = {
40-
default = self.packages.${system}.luarocks-51;
41-
luarocks-51 = mkPackage "5_1";
42-
luarocks-52 = mkPackage "52";
43-
};
86+
# packages = {
87+
# default = self.packages.${system}.luarocks-51;
88+
# luarocks-51 = mkPackage "5_1";
89+
# luarocks-52 = mkPackage "5_2";
90+
# };
4491

4592
devShells = {
4693
default = self.devShells.${system}.luajit;

lua/rest-nvim/curl/init.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ end
197197

198198
-- curl_cmd runs curl with the passed options, gets or creates a new buffer
199199
-- and then the results are printed to the recently obtained/created buffer
200-
-- @param opts curl arguments
200+
-- @param opts (table) curl arguments:
201+
-- - yank_dry_run (boolean): displays the command
202+
-- - arguments are forwarded to plenary
201203
M.curl_cmd = function(opts)
202204
if opts.dry_run then
203205
local res = curl[opts.method](opts)

lua/rest-nvim/init.lua

+8
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ rest.run = function(verbose)
2020
return
2121
end
2222

23+
return rest.run_request(result, verbose)
24+
end
25+
26+
rest.run_request = function(req, verbose)
27+
28+
local result = req
2329
Opts = {
2430
method = result.method:lower(),
2531
url = result.url,
@@ -74,4 +80,6 @@ rest.last = function()
7480
end
7581
end
7682

83+
rest.request = request
84+
7785
return rest

lua/rest-nvim/request/init.lua

+6-2
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,12 @@ end
241241

242242
local M = {}
243243
M.get_current_request = function()
244-
local curpos = vim.fn.getcurpos()
245-
local bufnr = vim.api.nvim_win_get_buf(0)
244+
return M.buf_get_request(vim.api.nvim_win_get_buf(0), vim.fn.getcurpos())
245+
end
246+
247+
M.buf_get_request = function(bufnr, curpos)
248+
curpos = curpos or vim.fn.getcurpos()
249+
bufnr = bufnr or vim.api.nvim_win_get_buf(0)
246250

247251
local start_line = start_request()
248252
if start_line == 0 then

rest.nvim-scm-1.rockspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
local MAJOR, REV = "scm", "-1"
1+
local MAJOR, REV = "0.1", "-2"
22
rockspec_format = "3.0"
33
package = "rest.nvim"
44
version = MAJOR .. REV
@@ -19,7 +19,7 @@ dependencies = {
1919
}
2020

2121
source = {
22-
url = "http://github.com/rest-nvim/rest.nvim/archive/v" .. MAJOR .. ".zip",
22+
url = "http://github.com/rest-nvim/rest.nvim/archive/" .. MAJOR .. ".zip",
2323
dir = "rest.nvim-" .. MAJOR,
2424
}
2525

tests/main_spec.lua

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
local rest = require('rest-nvim')
2+
local v = vim
3+
4+
describe("rest testing framework", function()
5+
6+
it('test create users', function()
7+
8+
v.api.nvim_cmd({cmd='edit', args = {'tests/post_create_user.http'}}, {})
9+
10+
-- first argument is for verbosity
11+
rest.run(false)
12+
end)
13+
end)

0 commit comments

Comments
 (0)