Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
gorillamoe committed Sep 6, 2024
1 parent 82a3aac commit 01c9ca3
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 48 deletions.
40 changes: 15 additions & 25 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,33 @@
name: kulala tests
---
name: Test

on:
push:
branches:
- main
pull_request: ~
pull_request_review:
types: [submitted]

jobs:
tests:
name: tests
if: github.event.review.state == 'approved'
name: Tests
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-22.04
rev: v0.10.0/nvim-linux64.tar.gz
rev: v0.10.0/nvim.appimage
steps:
- uses: actions/checkout@v4
- name: Restore cache.
- name: Restore cache
uses: actions/cache@v4
with:
path: _neovim
path: |
_neovim
~/.local/share/nvim/site/pack/vendor/start
key: ${{ runner.os }}-${{ matrix.rev }}

- name: Prepare dependencies
run: |
test -d _neovim || {
mkdir -p _neovim
curl -sL "https://github.com/neovim/neovim/releases/download/${{ matrix.rev }}" | tar xzf - --strip-components=1 -C "${PWD}/_neovim"
}
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
export PATH="${PWD}/_neovim/bin:${PATH}"
export VIM="${PWD}/_neovim/share/nvim/runtime"
nvim --headless -c 'TSInstallSync lua | quit'
run: ./scripts/tests.sh prepare ${{ matrix.rev }}

- name: Run tests
run: |
export PATH="${PWD}/_neovim/bin:${PATH}"
export VIM="${PWD}/_neovim/share/nvim/runtime"
nvim --version
/bin/bash ./scripts/test
run: ./scripts/tests.sh run
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ http-client.env.json
*.http
*graphql-schema.json
/http-examples
/_neovim
2 changes: 1 addition & 1 deletion lua/kulala/parser/curl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function M.parse(curl)
res.headers["user-agent"] = arg
elseif state == State.Header then
local header, value = Stringutils.cut(arg, ":")
res.headers[Stringutils.remove_extra_space(header):lower()] = Stringutils.remove_extra_space(value)
res.headers[Stringutils.remove_extra_space(header)] = Stringutils.remove_extra_space(value)
elseif state == State.Body then
res.body = arg
end
Expand Down
21 changes: 0 additions & 21 deletions scripts/test.sh

This file was deleted.

68 changes: 68 additions & 0 deletions scripts/tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env bash

# Copy from MIT licensed neotest plugin:
# https://github.com/nvim-neotest/neotest/blob/958a6bff41c7086fe8b46f7f320d0fd073cfc6a0/scripts/test

NVIM_DL_BASE="https://github.com/neovim/neovim/releases/download/"

prepare() {
local version=$1

if [[ ! -f _neovim/nvim ]] && [[ -n $version ]]; then
mkdir -p _neovim && curl -sL -o _neovim/nvim "${NVIM_DL_BASE}${version}" && chmod +x _neovim/nvim
_neovim/nvim --headless -c 'TSInstallSync lua | quit'
fi
if [[ ! -d ~/.local/share/nvim/site/pack/vendor/start/plenary.nvim ]]; then
git clone --depth 1 \
https://github.com/nvim-lua/plenary.nvim \
~/.local/share/nvim/site/pack/vendor/start/plenary.nvim
fi
if [[ ! -d ~/.local/share/nvim/site/pack/vendor/start/kulala.nvim ]]; then
ln -s "$(pwd)" ~/.local/share/nvim/site/pack/vendor/start
fi
}

run() {
type _neovim/nvim && nvim() { _neovim/nvim "$@"; }

local tempfile
tempfile=$(mktemp)

nvim --version

if [[ -n $1 ]]; then
nvim --headless --noplugin -u tests/init.vim -c "PlenaryBustedFile $1" | tee "${tempfile}"
else
nvim --headless --noplugin -u tests/init.vim -c "PlenaryBustedDirectory tests/ {minimal_init = 'tests/init.vim'}" | tee "${tempfile}"
fi

# Plenary doesn't emit exit code 1 when tests have errors during setup
errors=$(sed 's/\x1b\[[0-9;]*m//g' "${tempfile}" | awk '/(Errors|Failed) :/ {print $3}' | grep -v '0')

if [[ -n $errors ]]; then
echo "Tests failed"
exit 1
fi

exit 0
}

main() {
local action="$1"
shift
local args=$*
case $action in
"run")
run "$args"
;;
"prepare")
prepare "$args"
;;
*)
echo "Invalid action"
exit 1
;;
esac

}
main "$@"
3 changes: 2 additions & 1 deletion tests/parser/curl_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ describe("curl parse", function()
local parsed = CURL.parse(args)
assert.equal("GET", parsed.method)
assert.equal("https://example.com/get", parsed.url)
assert.equal("value", parsed.headers["header-key"])
assert.equal(parsed.headers["header-key"], nil)
assert.equal("value", parsed.headers["Header-Key"])
end)
end)

0 comments on commit 01c9ca3

Please sign in to comment.