From 652cd3b150e3f3d5686610ba6b6cc215d2517906 Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Fri, 5 Jan 2024 04:21:45 +0000 Subject: [PATCH 01/11] Update test suite to run on macOS and Windows --- .github/workflows/CI.yml | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 5ac3491..d488b8e 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -16,19 +16,33 @@ jobs: shell: bash strategy: matrix: - os: [ubuntu-latest] - + os: + - ubuntu-latest + - macos-latest + - windows-latest + vim: + - 'v9.0.2190' + - 'v8.2.5172' + steps: - - uses: actions/checkout@v1.0.0 - - name: Install dependencies + - uses: actions/checkout@v4 + - name: Install coverage dependencies + if: ${{ matrix.os == 'ubuntu-latest' }} run: | sudo apt-get update - sudo apt-get install -y libcurl4-openssl-dev libelf-dev libdw-dev cmake vim kcov - - name: Run tests + sudo apt-get install -y libcurl4-openssl-dev libelf-dev libdw-dev cmake kcov + - uses: rhysd/action-setup-vim@v1 + with: + version: ${{ matrix.vim }} + - name: Run tests without coverage + if: ${{ matrix.os != 'ubuntu-latest' }} + run: | + TEST_DIR=$(pwd)/test VIMS=./vims ./test/test.sh + - name: Run tests with coverage + if: ${{ matrix.os == 'ubuntu-latest' }} run: | mkdir -p coverage TEST_DIR=$(pwd)/test VIMS=./vims kcov coverage ./test/test.sh - name: Upload coverage + if: ${{ matrix.os == 'ubuntu-latest' }} run: bash <(curl -s https://codecov.io/bash) -s coverage - - From 3e9b30ba49bc140c041b66af1f3415f647e19a4d Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Fri, 5 Jan 2024 04:27:02 +0000 Subject: [PATCH 02/11] Vim versions only exist for some releases --- .github/workflows/CI.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index d488b8e..d19c189 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -21,8 +21,8 @@ jobs: - macos-latest - windows-latest vim: - - 'v9.0.2190' - - 'v8.2.5172' + - 'v9.0.2189' + - 'v8.2.4286' steps: - uses: actions/checkout@v4 From e80f06d1f0cec872bbff5500f44041a7744b23aa Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Fri, 5 Jan 2024 06:23:20 +0000 Subject: [PATCH 03/11] Add bats --- .gitmodules | 3 +++ test/bats | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 test/bats diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..91716b4 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "test/bats"] + path = test/bats + url = https://github.com/bats-core/bats-core.git diff --git a/test/bats b/test/bats new file mode 160000 index 0000000..3d3f63d --- /dev/null +++ b/test/bats @@ -0,0 +1 @@ +Subproject commit 3d3f63d9772b98c88586ec0a66bd358a85d9b4a6 From 97485734901e57462c2f03254cce51137121f449 Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Fri, 5 Jan 2024 07:07:48 +0000 Subject: [PATCH 04/11] Get test suite working with bats --- .gitmodules | 6 +++ test/test.bats | 80 ++++++++++++++++++++++++++++++ test/test.sh | 91 ----------------------------------- test/test_helper/bats-assert | 1 + test/test_helper/bats-support | 1 + 5 files changed, 88 insertions(+), 91 deletions(-) create mode 100755 test/test.bats delete mode 100755 test/test.sh create mode 160000 test/test_helper/bats-assert create mode 160000 test/test_helper/bats-support diff --git a/.gitmodules b/.gitmodules index 91716b4..b7efcb4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,9 @@ [submodule "test/bats"] path = test/bats url = https://github.com/bats-core/bats-core.git +[submodule "test/test_helper/bats-support"] + path = test/test_helper/bats-support + url = https://github.com/bats-core/bats-support.git +[submodule "test/test_helper/bats-assert"] + path = test/test_helper/bats-assert + url = https://github.com/bats-core/bats-assert.git diff --git a/test/test.bats b/test/test.bats new file mode 100755 index 0000000..8b5f101 --- /dev/null +++ b/test/test.bats @@ -0,0 +1,80 @@ +#!/usr/bin/env bats + +setup() { + load "test_helper/bats-support/load" + load "test_helper/bats-assert/load" + + DIR=$(dirname "${BATS_TEST_FILENAME}") + TEST_DIR=${TEST_DIR:-$DIR} + VIMS=${VIMS:-$DIR/../vims} +} + +teardown() { + rm -f .tmp +} + +@test "Identity" { + run cat $TEST_DIR/test_files/python.py | run $VIMS '' > .tmp + run diff -b .tmp $TEST_DIR/test_files/python.py + assert_output "" +} + +@test "Move init to bottom" { + run cat $TEST_DIR/test_files/python.py | run $VIMS -e '^\s\+def __init__' 'V/^\\s\\+def\kdGp' | run cat > .tmp + run diff -b .tmp $TEST_DIR/test_files/python_init_at_bottom.py + assert_output "" +} + +@test "Print last 4 lines" { + run cat $TEST_DIR/test_files/python.py | run $VIMS -n '$-3,$p' | run cat > .tmp + run diff -b .tmp $TEST_DIR/test_files/python_last_4_lines.py + assert_output "" +} + +@test "Do one long 'simple' command" { + run cat $TEST_DIR/test_files/python.py | run $VIMS -s '/^class\O# This class is for Bifrost\Go\# This file does not run!' | run cat > .tmp + run diff -b .tmp $TEST_DIR/test_files/python_with_extra_comments.py + assert_output "" +} + +@test "Do one short 'simple' command" { + run cat $TEST_DIR/test_files/python.py | run $VIMS -s 'x' | run cat > .tmp + run diff -b .tmp $TEST_DIR/test_files/python_minus_one_char.py + assert_output "" +} + +@test "Reverse a file with exe" { + run cat $TEST_DIR/test_files/python.py | run $VIMS -e '.*' ':m0\' | run cat > .tmp + run diff -b .tmp $TEST_DIR/test_files/python_reversed.py + assert_output "" +} + +@test "Reverse a file in normal mode" { + run cat $TEST_DIR/test_files/python.py | run $VIMS '%g/.*/m0' | run cat > .tmp + run diff -b .tmp $TEST_DIR/test_files/python_reversed.py + assert_output "" +} + +@test "Turn back off exe mode" { + run cat $TEST_DIR/test_files/numbers.txt | run $VIMS -e '^5$' 'dd' -t '%g/^3$/t$' | run cat > .tmp + run diff -b .tmp $TEST_DIR/test_files/numbers_5_gone_3_bottom.txt + assert_output "" +} + +@test "Run multi-mode commands" { + run cat $TEST_DIR/test_files/numbers.txt | run $VIMS -e '^5$' 'dd' -s ':%g/^3$/t$\' | run cat > .tmp + run diff -b .tmp $TEST_DIR/test_files/numbers_5_gone_3_bottom.txt + assert_output "" +} + +@test "Execute command on every line" { + run cat $TEST_DIR/test_files/numbers.txt | run $VIMS -l '10\' > .tmp + run diff -b .tmp $TEST_DIR/test_files/numbers_all_decreased.txt + assert_output "" +} + +@test "Delete all numbers not 1" { + run cat $TEST_DIR/test_files/numbers.txt | run $VIMS -r '^1$' 'dd' > .tmp + run diff -b .tmp $TEST_DIR/test_files/numbers_delete_all_not_1.txt + assert_output "" +} diff --git a/test/test.sh b/test/test.sh deleted file mode 100755 index db1c828..0000000 --- a/test/test.sh +++ /dev/null @@ -1,91 +0,0 @@ -#!/bin/sh -# From http://tldp.org/LDP/abs/html/debugging.html -VIMS=./vims - -assert () -{ - E_PARAM_ERR=98 - E_ASSERT_FAILED=99 - if [ -z "$2" ] - then - return $E_PARAM_ERR - fi - POINTED_LINE_NO=$2 - if [ ! -z "$1" ] - then - echo -n "- test assertion failed!" - echo -n " test $3, line $POINTED_LINE_NO, " - echo "diff between output and expected:" - echo "$1" - exit $E_ASSERT_FAILED - fi -} - -cat $TEST_DIR/test_files/python.py | $VIMS '' > .tmp -DIFF=$(diff -b .tmp $TEST_DIR/test_files/python.py) -TEST_NUM=0 -assert "$DIFF" $LINENO $TEST_NUM -echo "+ test $TEST_NUM to do a non-edit passed" - -cat $TEST_DIR/test_files/python.py | $VIMS -e '^\s\+def __init__' 'V/^\\s\\+def\kdGp' | cat > .tmp -DIFF=$(diff -b .tmp $TEST_DIR/test_files/python_init_at_bottom.py) -TEST_NUM=1 -assert "$DIFF" $LINENO $TEST_NUM -echo "+ test $TEST_NUM to move init to bottom passed" - -cat $TEST_DIR/test_files/python.py | $VIMS -n '$-3,$p' | cat > .tmp -DIFF=$(diff -b .tmp $TEST_DIR/test_files/python_last_4_lines.py) -TEST_NUM=2 -assert "$DIFF" $LINENO $TEST_NUM -echo "+ test $TEST_NUM to print last 4 lines passed" - -cat $TEST_DIR/test_files/python.py | $VIMS -s '/^class\O# This class is for Bifrost\Go\# This file does not run!' | cat > .tmp -DIFF=$(diff -b .tmp $TEST_DIR/test_files/python_with_extra_comments.py) -TEST_NUM=3 -assert "$DIFF" $LINENO $TEST_NUM -echo "+ test $TEST_NUM to do one long 'simple' command passed" - -cat $TEST_DIR/test_files/python.py | $VIMS -s 'x' | cat > .tmp -DIFF=$(diff -b .tmp $TEST_DIR/test_files/python_minus_one_char.py) -TEST_NUM=4 -assert "$DIFF" $LINENO $TEST_NUM -echo "+ test $TEST_NUM to do one short 'simple' command passed" - -cat $TEST_DIR/test_files/python.py | $VIMS -e '.*' ':m0\' | cat > .tmp -DIFF=$(diff -b .tmp $TEST_DIR/test_files/python_reversed.py) -TEST_NUM=5 -assert "$DIFF" $LINENO $TEST_NUM -echo "+ test $TEST_NUM to reverse a file with exe passed" - -cat $TEST_DIR/test_files/python.py | $VIMS '%g/.*/m0' | cat > .tmp -DIFF=$(diff -b .tmp $TEST_DIR/test_files/python_reversed.py) -TEST_NUM=6 -assert "$DIFF" $LINENO $TEST_NUM -echo "+ test $TEST_NUM to reverse a file in normal mode passed" - -cat $TEST_DIR/test_files/numbers.txt | $VIMS -e '^5$' 'dd' -t '%g/^3$/t$' | cat > .tmp -DIFF=$(diff -b .tmp $TEST_DIR/test_files/numbers_5_gone_3_bottom.txt) -TEST_NUM=7 -assert "$DIFF" $LINENO $TEST_NUM -echo "+ test $TEST_NUM to turn back off exe mode passed" - -cat $TEST_DIR/test_files/numbers.txt | $VIMS -e '^5$' 'dd' -s ':%g/^3$/t$\' | cat > .tmp -DIFF=$(diff -b .tmp $TEST_DIR/test_files/numbers_5_gone_3_bottom.txt) -TEST_NUM=8 -assert "$DIFF" $LINENO $TEST_NUM -echo "+ test $TEST_NUM to run multi-mode commands passed" - -cat $TEST_DIR/test_files/numbers.txt | $VIMS -l '10\' > .tmp -DIFF=$(diff -b .tmp $TEST_DIR/test_files/numbers_all_decreased.txt) -TEST_NUM=9 -assert "$DIFF" $LINENO $TEST_NUM -echo "+ test $TEST_NUM to execute command on every line passed" - -cat $TEST_DIR/test_files/numbers.txt | $VIMS -r '^1$' 'dd' > .tmp -DIFF=$(diff -b .tmp $TEST_DIR/test_files/numbers_delete_all_not_1.txt) -TEST_NUM=10 -assert "$DIFF" $LINENO $TEST_NUM -echo "+ test $TEST_NUM to delete all numbers not 1 passed" - -echo "+ tests all passed" -rm .tmp diff --git a/test/test_helper/bats-assert b/test/test_helper/bats-assert new file mode 160000 index 0000000..e2d855b --- /dev/null +++ b/test/test_helper/bats-assert @@ -0,0 +1 @@ +Subproject commit e2d855bc78619ee15b0c702b5c30fb074101159f diff --git a/test/test_helper/bats-support b/test/test_helper/bats-support new file mode 160000 index 0000000..9bf10e8 --- /dev/null +++ b/test/test_helper/bats-support @@ -0,0 +1 @@ +Subproject commit 9bf10e876dd6b624fe44423f0b35e064225f7556 From 6b7a01b038b2260c586384a716b85f3fa60b6388 Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Fri, 5 Jan 2024 07:52:32 +0000 Subject: [PATCH 05/11] Coverage broken so removing --- .github/workflows/CI.yml | 14 ++------------ README.md | 2 +- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index d19c189..567d6ac 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -34,15 +34,5 @@ jobs: - uses: rhysd/action-setup-vim@v1 with: version: ${{ matrix.vim }} - - name: Run tests without coverage - if: ${{ matrix.os != 'ubuntu-latest' }} - run: | - TEST_DIR=$(pwd)/test VIMS=./vims ./test/test.sh - - name: Run tests with coverage - if: ${{ matrix.os == 'ubuntu-latest' }} - run: | - mkdir -p coverage - TEST_DIR=$(pwd)/test VIMS=./vims kcov coverage ./test/test.sh - - name: Upload coverage - if: ${{ matrix.os == 'ubuntu-latest' }} - run: bash <(curl -s https://codecov.io/bash) -s coverage + - name: Run tests + run: ./test/bats/bin/bats ./test/test.bats diff --git a/README.md b/README.md index 594e733..14f80b0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # vims -[![CI](https://github.com/MilesCranmer/vim-stream/actions/workflows/CI.yml/badge.svg)](https://github.com/MilesCranmer/vim-stream/actions/workflows/CI.yml) [![Codecov branch](https://img.shields.io/codecov/c/github/MilesCranmer/vim-stream/master.svg)](https://codecov.io/gh/MilesCranmer/vim-stream) +[![CI](https://github.com/MilesCranmer/vim-stream/actions/workflows/CI.yml/badge.svg)](https://github.com/MilesCranmer/vim-stream/actions/workflows/CI.yml) ![Demo](https://i.imgur.com/dntK3MP.gif) From 7ff07458344ba4daa73ef7da81054b2523ebe21e Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Fri, 5 Jan 2024 07:53:47 +0000 Subject: [PATCH 06/11] Make checkout action check out submodules --- .github/workflows/CI.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 567d6ac..7c43fc1 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -26,6 +26,8 @@ jobs: steps: - uses: actions/checkout@v4 + with: + submodules: true - name: Install coverage dependencies if: ${{ matrix.os == 'ubuntu-latest' }} run: | From c7424fde91b51f7de1e21a7824cb771a099c414e Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Fri, 5 Jan 2024 07:55:44 +0000 Subject: [PATCH 07/11] Disable fail fast --- .github/workflows/CI.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 7c43fc1..dccc4d4 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -15,6 +15,7 @@ jobs: run: shell: bash strategy: + fail-fast: false matrix: os: - ubuntu-latest From 64bb1daa1216c2675a0db9b6073aa6b28fcc0fc0 Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Fri, 5 Jan 2024 07:59:21 +0000 Subject: [PATCH 08/11] Try fixing correct vim --- .github/workflows/CI.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index dccc4d4..05a2c2e 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -38,4 +38,4 @@ jobs: with: version: ${{ matrix.vim }} - name: Run tests - run: ./test/bats/bin/bats ./test/test.bats + run: VIMS=$PWD/vims ./test/bats/bin/bats ./test/test.bats From 109520f05ae4d793dc47821a7be103995712c77b Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Fri, 5 Jan 2024 08:01:53 +0000 Subject: [PATCH 09/11] Use vim action with caching --- .github/workflows/CI.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 05a2c2e..fbaa6e4 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -34,8 +34,10 @@ jobs: run: | sudo apt-get update sudo apt-get install -y libcurl4-openssl-dev libelf-dev libdw-dev cmake kcov - - uses: rhysd/action-setup-vim@v1 + - uses: thinca/action-setup-vim@v1 with: - version: ${{ matrix.vim }} + vim_version: ${{ matrix.vim }} + - name: Ensure vim installed + run: vim --version - name: Run tests run: VIMS=$PWD/vims ./test/bats/bin/bats ./test/test.bats From 6ab1333b8eb4a568fb93046602b4dfe8ec3beb49 Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Fri, 5 Jan 2024 08:07:46 +0000 Subject: [PATCH 10/11] Add smoketest --- .github/workflows/CI.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index fbaa6e4..2ea9104 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -39,5 +39,7 @@ jobs: vim_version: ${{ matrix.vim }} - name: Ensure vim installed run: vim --version + - name: Smoke test of vims + run: echo "Hello" | ./vims '' - name: Run tests run: VIMS=$PWD/vims ./test/bats/bin/bats ./test/test.bats From 8c2742e6778c61120435e8e65c74d5560d5a89c5 Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Fri, 5 Jan 2024 08:13:24 +0000 Subject: [PATCH 11/11] Try changing shell --- .github/workflows/CI.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 2ea9104..f176817 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -13,7 +13,7 @@ jobs: runs-on: ${{ matrix.os }} defaults: run: - shell: bash + shell: bash -l {0} strategy: fail-fast: false matrix: