From 94e52ed942a3d333155cde931896ecc4eee17afa Mon Sep 17 00:00:00 2001 From: carlfriedrich Date: Mon, 1 Sep 2025 21:31:18 +0200 Subject: [PATCH] Meta: Add bashunit tests to CI workflow and implement a first test case (#464) --- .github/pull_request_template.md | 2 ++ .github/workflows/ci.yaml | 6 +++++ .gitignore | 1 + tests/fzf.test.sh | 45 ++++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 tests/fzf.test.sh diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index a2da841..dd8426a 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -6,6 +6,7 @@ - [ ] I have performed a self-review of my code - [ ] I have commented my code in hard-to-understand areas +- [ ] I have added unit tests for my code - [ ] I have made corresponding changes to the documentation ## Description @@ -18,6 +19,7 @@ - [ ] New feature - [ ] Refactor - [ ] Breaking change +- [ ] Test - [ ] Documentation change ## Test environment diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 14abff5..df9bd5a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -39,16 +39,22 @@ jobs: sudo apt -y update sudo apt -y install zsh fish shellcheck fi + curl -s https://bashunit.typeddevs.com/install.sh | bash -s 0.23.0 - name: Show version run: | bash --version; echo zsh --version; echo fish --version; echo + shellcheck --version; echo + lib/bashunit --version; echo - name: Shellcheck run: shellcheck forgit.plugin.sh bin/git-forgit + - name: Unit tests + run: lib/bashunit . + - name: Test bash run: bash forgit.plugin.sh diff --git a/.gitignore b/.gitignore index eace2b1..814f620 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ ._zinit/ *.zwc +lib/ diff --git a/tests/fzf.test.sh b/tests/fzf.test.sh new file mode 100644 index 0000000..067764f --- /dev/null +++ b/tests/fzf.test.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +function test_exit_when_fzf_is_not_installed() { + # Error code 127 = "command not found" + mock fzf "return 127" + + output=$(bin/git-forgit) + + assert_general_error + assert_contains "fzf is not installed" "$output" +} + +# @data_provider fzf_versions_below_required_version +function test_exit_when_fzf_version_is_below_required_version() { + mock "fzf" "echo '$1'" + + output=$(bin/git-forgit) + + assert_general_error + assert_contains "fzf version 0.49.0 or higher is required" "$output" +} + +function fzf_versions_below_required_version() { + echo "0.0.2" + echo "0.5.0" + echo "0.30.0" + echo "0.48.9" +} + +# @data_provider fzf_versions_satisfying_required_version +function test_pass_when_fzf_version_satisfies_required_version() { + mock "fzf" "echo '$1'" + + output=$(bin/git-forgit) + + assert_general_error + assert_contains "missing command" "$output" +} + +function fzf_versions_satisfying_required_version() { + echo "0.49.0" + echo "0.49.1" + echo "0.80.0" + echo "1.1.0" +}