From d1ded2e03a2f940ac2df7e56897dfef01735c669 Mon Sep 17 00:00:00 2001 From: barts Date: Wed, 22 Nov 2023 12:23:15 +0100 Subject: [PATCH] improvement: added bats as git submodule --- .github/workflows/test.yml | 9 +++------ README.md | 22 ++++++++++++---------- bats | 5 +++++ test/cli-options.bats | 4 ++-- test/fzf-select-option-preview.bats | 4 ++-- test/fzf-select-option.bats | 4 ++-- test/help-message.bats | 4 ++-- 7 files changed, 28 insertions(+), 24 deletions(-) create mode 100755 bats diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a96dca9..ccf72cb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,15 +20,12 @@ jobs: - name: Install bats run: | - sudo apt-get update -y - sudo apt-get install git -y - git submodule add https://github.com/bats-core/bats-core.git test/bats - git submodule add https://github.com/bats-core/bats-support.git test/test_helper/bats-support - git submodule add https://github.com/bats-core/bats-assert.git test/test_helper/bats-assert + git submodule init + git submodule update - name: Run Bats Test shell: 'script -q -e -c "bash {0}"' # work around tty issues env: TERM: linux # fix tput for tty issue work around run: | - export BATS_LIB_PATH="${PWD}/test":"${PWD}/test/bats":"${PWD}/test/test_helper"; $PWD/test/bats/bin/bats --tap test + $PWD/test/bats/bin/bats --tap test diff --git a/README.md b/README.md index b7b8576..e96b02b 100644 --- a/README.md +++ b/README.md @@ -201,28 +201,30 @@ This is useful when you do not like page wrapping. ## Tests -To run the test make sure the following is installed: +To run the test the following submodules need to be installed as git +sub modules: - Install [bats-core](https://github.com/bats-core/bats-core) - Install [bats-assert](https://github.com/ztombol/bats-assert) - Install [bats-support](https://github.com/ztombol/bats-support) -After this, set the `BATS_LIB_PATH` environment variable to the directories -where the bats libraries are installed. For example: +To install these sub modules, run the following commands: -```bash -export BATS_LIB_PATH=/usr/lib:/usr/lib/bats +``` +git submodule init +git submodule update ``` -For more information, see the [bats-core documentation](https://bats-core.readthedocs.io/en/stable/) - -To run the tests, cd to the root of the repository and run: +After this, you can use the `bats` executable in the root of the repository to +run the tests. To run all tests, run: ```bash -bats test +./bats test ``` -where `bats` is the bats-core executable that should be in your path. +here, `./bats` is a shortcut to `./test/bats/bin/bats`. + +For more information, see the [bats-core documentation](https://bats-core.readthedocs.io/en/stable/) ## Troubleshooting diff --git a/bats b/bats new file mode 100755 index 0000000..4d6ac07 --- /dev/null +++ b/bats @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +# Shortcut to the bats executable at `./test/bats/bin/bats` +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +"$DIR"/test/bats/bin/bats $@ diff --git a/test/cli-options.bats b/test/cli-options.bats index 78c7b96..3ee7112 100644 --- a/test/cli-options.bats +++ b/test/cli-options.bats @@ -1,7 +1,7 @@ #!/usr/bin/env bats # vim: ft=bash -bats_load_library bats-assert -bats_load_library bats-support +load test_helper/bats-assert/load +load test_helper/bats-support/load load helpers.bash @test "Run with -h" { diff --git a/test/fzf-select-option-preview.bats b/test/fzf-select-option-preview.bats index f6dde43..5216f5e 100644 --- a/test/fzf-select-option-preview.bats +++ b/test/fzf-select-option-preview.bats @@ -1,7 +1,7 @@ #!/usr/bin/env bats # vim: ft=bash -bats_load_library bats-assert -bats_load_library bats-support +load test_helper/bats-assert/load +load test_helper/bats-support/load load helpers.bash @test "Run with -h" { diff --git a/test/fzf-select-option.bats b/test/fzf-select-option.bats index 66bdcb5..c4b0471 100644 --- a/test/fzf-select-option.bats +++ b/test/fzf-select-option.bats @@ -1,7 +1,7 @@ #!/usr/bin/env bats # vim: ft=bash -bats_load_library bats-assert -bats_load_library bats-support +load test_helper/bats-assert/load +load test_helper/bats-support/load load helpers.bash @test "Run with -h" { diff --git a/test/help-message.bats b/test/help-message.bats index 790128d..34e611b 100644 --- a/test/help-message.bats +++ b/test/help-message.bats @@ -1,7 +1,7 @@ #!/usr/bin/env bats # vim: ft=bash -bats_load_library bats-assert -bats_load_library bats-support +load test_helper/bats-assert/load +load test_helper/bats-support/load load helpers.bash get_temp() {