diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f348c87..ae75811 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,43 +1,35 @@ -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: | # TODO: Cache apt dependencies + sudo apt-get update && sudo apt-get install -y libfuse2 + ./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 diff --git a/.gitignore b/.gitignore index 9a3e221..4b465d2 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ http-client.env.json *.http *graphql-schema.json /http-examples +/_neovim diff --git a/lua/kulala/parser/curl.lua b/lua/kulala/parser/curl.lua index 743b3d5..1adf729 100644 --- a/lua/kulala/parser/curl.lua +++ b/lua/kulala/parser/curl.lua @@ -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 diff --git a/scripts/test.sh b/scripts/test.sh deleted file mode 100644 index 15523b4..0000000 --- a/scripts/test.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -# Copy from MIT licensed neotest plugin: https://raw.githubusercontent.com/nvim-neotest/neotest/master/scripts/test -tempfile=".test_output.tmp" - -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') - -rm "${tempfile}" - -if [[ -n $errors ]]; then - echo "Tests failed" - exit 1 -fi - -exit 0 diff --git a/scripts/tests.sh b/scripts/tests.sh new file mode 100755 index 0000000..d1589e7 --- /dev/null +++ b/scripts/tests.sh @@ -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 "$@" diff --git a/tests/parser/curl_spec.lua b/tests/parser/curl_spec.lua index bc24615..4e2e68f 100644 --- a/tests/parser/curl_spec.lua +++ b/tests/parser/curl_spec.lua @@ -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)