Meta: Add bashunit tests to CI workflow and implement a first test case (#464)

This commit is contained in:
carlfriedrich 2025-09-01 21:31:18 +02:00
parent 5d4d6121b1
commit 94e52ed942
4 changed files with 54 additions and 0 deletions

View file

@ -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

View file

@ -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

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
._zinit/
*.zwc
lib/

45
tests/fzf.test.sh Normal file
View file

@ -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"
}