Skip to content

Commit 6a6c702

Browse files
committed
chore: setup repo structure
1 parent 11d3e3e commit 6a6c702

16 files changed

+252
-1
lines changed

.github/workflows/makefile.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: CI / Tests
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
16+
- name: Setup Maven Action
17+
uses: s4u/setup-maven-action@v1.9.0
18+
19+
- uses: rhysd/action-setup-vim@v1
20+
with:
21+
neovim: true
22+
23+
- name: Install dependencies
24+
run: make install
25+
26+
- name: Run tests
27+
run: make test

.gitmodules

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[submodule "dependencies/neotest"]
2+
path = dependencies/neotest
3+
url = https://github.com/nvim-neotest/neotest
4+
[submodule "dependencies/nvim-treesitter"]
5+
path = dependencies/nvim-treesitter
6+
url = https://github.com/nvim-treesitter/nvim-treesitter.git
7+
[submodule "dependencies/plenary.nvim"]
8+
path = dependencies/plenary.nvim
9+
url = https://github.com/nvim-lua/plenary.nvim.git

Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
all: install test
3+
4+
test:
5+
./scripts/test
6+
7+
test-fail-fast:
8+
./scripts/test --fail-fast
9+
10+
install:
11+
git submodule update --init --recursive
12+
nvim --headless -u tests/minimal_init.vim -c "TSInstallSync bash | quit"
13+
14+
validate:
15+
stylua --check .
16+
17+
format:
18+
stylua .

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,22 @@
1-
# neotest-bash
1+
# neotest-bash
2+
3+
[Neotest](https://github.com/rcarriga/neotest) adapter for Bash, using Bashunit.
4+
5+
6+
## 🔧 Installation
7+
8+
It requires [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter)
9+
10+
Using vim-plug:
11+
```vim
12+
Plug 'rcasia/neotest-bash', { 'do': ':TSInstall bash' }
13+
```
14+
15+
## ⚙ Configuration
16+
```lua
17+
require("neotest").setup({
18+
adapters = {
19+
require("neotest-bash")
20+
}
21+
})
22+
```

dependencies/neotest

Submodule neotest added at 1e67a50

dependencies/nvim-treesitter

Submodule nvim-treesitter added at 5ec4217

dependencies/plenary.nvim

Submodule plenary.nvim added at 9ce85b0

lua/neotest-bash/core/dir_filter.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
DirFilter = {}
2+
3+
---Filter directories when searching for test files
4+
---@async
5+
---@param name string Name of directory
6+
---@param rel_path string Path to directory, relative to root
7+
---@param root string Root directory of project
8+
---@return boolean
9+
function DirFilter.filter_dir(name, rel_path, root)
10+
return false
11+
end
12+
13+
return DirFilter
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FileChecker = {}
2+
3+
---@async
4+
---@param file_path string
5+
---@return boolean
6+
function FileChecker.isTestFile(file_path)
7+
return false
8+
end
9+
10+
return FileChecker
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
local lib = require("neotest.lib")
2+
3+
PositionsDiscoverer = {}
4+
5+
---Given a file path, parse all the tests within it.
6+
---@async
7+
---@param file_path string Absolute file path
8+
---@return neotest.Tree | nil
9+
function PositionsDiscoverer:discover_positions(file_path)
10+
local query = [[]]
11+
12+
return lib.treesitter.parse_positions(file_path, query)
13+
end
14+
15+
return PositionsDiscoverer
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
local xml = require("neotest.lib.xml")
2+
local scan = require("plenary.scandir")
3+
local context_manager = require("plenary.context_manager")
4+
local with = context_manager.with
5+
local open = context_manager.open
6+
7+
ResultBuilder = {}
8+
9+
---@async
10+
---@param spec neotest.RunSpec
11+
---@param result neotest.StrategyResult
12+
---@param tree neotest.Tree
13+
---@return table<string, neotest.Result>
14+
function ResultBuilder.build_results(spec, result, tree)
15+
return nil
16+
end
17+
18+
return ResultBuilder

lua/neotest-bash/core/root_finder.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
local lib = require("neotest.lib")
2+
3+
SpecBuilder = {}
4+
---Find the project root directory given a current directory to work from.
5+
---Should no root be found, the adapter can still be used in a non-project context if a test file matches.
6+
---@async
7+
---@param dir string @Directory to treat as cwd
8+
---@return string | nil @Absolute root dir of test suite
9+
function SpecBuilder.findRoot(dir)
10+
return lib.files.match_root_pattern("????")(dir)
11+
end
12+
13+
return SpecBuilder
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
local RootFinder = require("neotest-bash.core.root_finder")
2+
3+
SpecBuilder = {}
4+
---@param args neotest.RunArgs
5+
---@return nil | neotest.RunSpec | neotest.RunSpec[]
6+
function SpecBuilder.build_spec(args)
7+
return nil
8+
end
9+
10+
return SpecBuilder

lua/neotest-bash/init.lua

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
local FileChecker = require("neotest-bash.core.file_checker")
2+
local RootFinder = require("neotest-bash.core.root_finder")
3+
local DirFilter = require("neotest-bash.core.dir_filter")
4+
local PositionsDiscoverer = require("neotest-bash.core.positions_discoverer")
5+
local SpecBuilder = require("neotest-bash.core.spec_builder")
6+
local ResultBuilder = require("neotest-bash.core.result_builder")
7+
8+
---@class neotest.Adapter
9+
---@field name string
10+
NeotestBashAdapter = { name = "neotest-bash" }
11+
12+
---Find the project root directory given a current directory to work from.
13+
---Should no root be found, the adapter can still be used in a non-project context if a test file matches.
14+
---@async
15+
---@param dir string @Directory to treat as cwd
16+
---@return string | nil @Absolute root dir of test suite
17+
function NeotestBashAdapter.root(dir)
18+
return RootFinder.findRoot(dir)
19+
end
20+
21+
---Filter directories when searching for test files
22+
---@async
23+
---@param name string Name of directory
24+
---@param rel_path string Path to directory, relative to root
25+
---@param root string Root directory of project
26+
---@return boolean
27+
function NeotestBashAdapter.filter_dir(name, rel_path, root)
28+
return DirFilter.filter_dir(name, rel_path, root)
29+
end
30+
31+
---@async
32+
---@param file_path string
33+
---@return boolean
34+
function NeotestBashAdapter.is_test_file(file_path)
35+
return FileChecker.isTestFile(file_path)
36+
end
37+
38+
---Given a file path, parse all the tests within it.
39+
---@async
40+
---@param file_path string Absolute file path
41+
---@return neotest.Tree | nil
42+
function NeotestBashAdapter.discover_positions(file_path)
43+
return PositionsDiscoverer:discover_positions(file_path)
44+
end
45+
46+
---@param args neotest.RunArgs
47+
---@return nil | neotest.RunSpec | neotest.RunSpec[]
48+
function NeotestBashAdapter.build_spec(args)
49+
return SpecBuilder.build_spec(args)
50+
end
51+
52+
---@async
53+
---@param spec neotest.RunSpec
54+
---@param result neotest.StrategyResult
55+
---@param tree neotest.Tree
56+
---@return table<string, neotest.Result>
57+
function NeotestBashAdapter.results(spec, result, tree)
58+
return ResultBuilder.build_results(spec, result, tree)
59+
end
60+
61+
return NeotestBashAdapter

scripts/test

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
4+
tempfile=$(mktemp)
5+
6+
7+
if [[ -n $1 ]] && [[ $1 == "--fail-fast" ]]; then
8+
echo "Running tests with --fail-fast"
9+
nvim --headless --noplugin -u tests/minimal_init.vim \
10+
-c "PlenaryBustedDirectory tests/ {minimal_init = 'tests/minimal_init.vim', sequential = true, keep_going = false}" | tee "${tempfile}"
11+
elif [[ -n $1 ]]; then
12+
nvim --headless --noplugin -u tests/minimal_init.vim -c "PlenaryBustedFile $1" | tee "${tempfile}"
13+
else
14+
nvim --headless --noplugin -u tests/minimal_init.vim \
15+
-c "PlenaryBustedDirectory tests/ {minimal_init = 'tests/minimal_init.vim'}" | tee "${tempfile}"
16+
fi
17+
18+
# Plenary doesn't emit exit code 1 when tests have errors during setup
19+
errors=$(sed 's/\x1b\[[0-9;]*m//g' "${tempfile}" | awk '/(Errors|Failed) :/ {print $3}' | grep -v '0')
20+
21+
rm "${tempfile}"
22+
23+
if [[ -n $errors ]]; then
24+
echo "Tests failed"
25+
exit 1
26+
fi
27+
28+
exit 0

tests/minimal_init.vim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
set runtimepath+=.
2+
set runtimepath+=./dependencies/plenary.nvim
3+
set runtimepath+=./dependencies/neotest
4+
set runtimepath+=./dependencies/nvim-treesitter
5+
runtime! plugin/plenary.vim

0 commit comments

Comments
 (0)