diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 5ac3491..f176817 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -13,22 +13,33 @@ jobs: runs-on: ${{ matrix.os }} defaults: run: - shell: bash + shell: bash -l {0} strategy: + fail-fast: false matrix: - os: [ubuntu-latest] - + os: + - ubuntu-latest + - macos-latest + - windows-latest + vim: + - 'v9.0.2189' + - 'v8.2.4286' + steps: - - uses: actions/checkout@v1.0.0 - - name: Install dependencies + - uses: actions/checkout@v4 + with: + submodules: true + - 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 + sudo apt-get install -y libcurl4-openssl-dev libelf-dev libdw-dev cmake kcov + - uses: thinca/action-setup-vim@v1 + with: + vim_version: ${{ matrix.vim }} + - name: Ensure vim installed + run: vim --version + - name: Smoke test of vims + run: echo "Hello" | ./vims '' - name: Run tests - run: | - mkdir -p coverage - TEST_DIR=$(pwd)/test VIMS=./vims kcov coverage ./test/test.sh - - name: Upload coverage - run: bash <(curl -s https://codecov.io/bash) -s coverage - - + run: VIMS=$PWD/vims ./test/bats/bin/bats ./test/test.bats diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..b7efcb4 --- /dev/null +++ b/.gitmodules @@ -0,0 +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/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) 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 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