refactor: improve test

This commit is contained in:
Maciej Sypien 2024-09-22 22:42:11 +02:00
parent dd1c215631
commit e631a41278
No known key found for this signature in database
GPG key ID: 10BC01EDA6827DC8
11 changed files with 42 additions and 44 deletions

View file

@ -61,16 +61,3 @@ tmux_set_window_option_now() {
_value="$2" _value="$2"
tmux set-window-option -gq "$_option_name" "$_value" tmux set-window-option -gq "$_option_name" "$_value"
} }
# return the value of status style
tmux_get_statusstyle() {
local _val
_val=$(tmux show-option -gqv status-style)
echo "$_val"
}
tmux_get_statusleft() {
local _val
_val=$(tmux show-option -gqv status-left)
echo "$_val"
}

View file

@ -3,7 +3,7 @@
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck disable=SC1091 # shellcheck disable=SC1091
source "${CURRENT_DIR}/../tmux_helpers.sh" source "${CURRENT_DIR}/../test_helpers.sh"
main() { main() {
helper_tearup_linux helper_tearup_linux
@ -33,7 +33,7 @@ EOF
# check if left side match # check if left side match
_status_left_expected="#[bg=colour241,fg=colour248] #S #[bg=colour237,fg=colour241,nobold,noitalics,nounderscore]" _status_left_expected="#[bg=colour241,fg=colour248] #S #[bg=colour237,fg=colour241,nobold,noitalics,nounderscore]"
_status_left_current=$(tmux_get_statusleft) _status_left_current=$(helper_tmux_get_statusleft)
if [[ "$_status_left_current" != "$_status_left_expected" ]]; then if [[ "$_status_left_current" != "$_status_left_expected" ]]; then
helper_print_fail "status-left did not match" "$_status_left_current" "$_status_left_expected" helper_print_fail "status-left did not match" "$_status_left_current" "$_status_left_expected"
helper_teardown helper_teardown
@ -41,7 +41,7 @@ EOF
fi fi
# check if status is not transparent # check if status is not transparent
_status_style_expected="bg=colour237,fg=colour223" _status_style_expected="bg=colour237,fg=colour223"
_status_style_current=$(tmux_get_statusstyle) _status_style_current=$(helper_tmux_get_statusstyle)
if [[ "$_status_style_current" != "$_status_style_expected" ]]; then if [[ "$_status_style_current" != "$_status_style_expected" ]]; then
helper_print_fail "status-style did not match" "$_status_style_current" "$_status_style_expected" helper_print_fail "status-style did not match" "$_status_style_current" "$_status_style_expected"
helper_teardown helper_teardown

View file

@ -3,7 +3,7 @@
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck disable=SC1091 # shellcheck disable=SC1091
source "${CURRENT_DIR}/../tmux_helpers.sh" source "${CURRENT_DIR}/../test_helpers.sh"
main() { main() {
helper_tearup_linux helper_tearup_linux
@ -34,7 +34,7 @@ EOF
# check if left side match # check if left side match
_status_left_expected="#[bg=colour241,fg=colour248] #S #[bg=colour237,fg=colour241,nobold,noitalics,nounderscore]" _status_left_expected="#[bg=colour241,fg=colour248] #S #[bg=colour237,fg=colour241,nobold,noitalics,nounderscore]"
_status_left_current=$(tmux_get_statusleft) _status_left_current=$(helper_tmux_get_statusleft)
if [[ "$_status_left_current" != "$_status_left_expected" ]]; then if [[ "$_status_left_current" != "$_status_left_expected" ]]; then
helper_print_fail "status-left did not match" "$_status_left_current" "$_status_left_expected" helper_print_fail "status-left did not match" "$_status_left_current" "$_status_left_expected"
helper_teardown helper_teardown
@ -42,7 +42,7 @@ EOF
fi fi
# check if status is not transparent # check if status is not transparent
_status_style_expected="bg=default,fg=colour223" _status_style_expected="bg=default,fg=colour223"
_status_style_current=$(tmux_get_statusstyle) _status_style_current=$(helper_tmux_get_statusstyle)
if [[ "$_status_style_current" != "$_status_style_expected" ]]; then if [[ "$_status_style_current" != "$_status_style_expected" ]]; then
helper_print_fail "status-style did not match" "$_status_style_current" "$_status_style_expected" helper_print_fail "status-style did not match" "$_status_style_current" "$_status_style_expected"
helper_teardown helper_teardown

View file

@ -3,7 +3,7 @@
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck disable=SC1091 # shellcheck disable=SC1091
source "${CURRENT_DIR}/../tmux_helpers.sh" source "${CURRENT_DIR}/../test_helpers.sh"
main() { main() {
helper_tearup_linux helper_tearup_linux
@ -33,7 +33,7 @@ EOF
# check if left side match # check if left side match
_status_left_expected="#[bg=#665c54,fg=#bdae93] #S #[bg=#3c3836,fg=#665c54,nobold,noitalics,nounderscore]" _status_left_expected="#[bg=#665c54,fg=#bdae93] #S #[bg=#3c3836,fg=#665c54,nobold,noitalics,nounderscore]"
_status_left_current=$(tmux_get_statusleft) _status_left_current=$(helper_tmux_get_statusleft)
if [[ "$_status_left_current" != "$_status_left_expected" ]]; then if [[ "$_status_left_current" != "$_status_left_expected" ]]; then
helper_print_fail "status-left did not match" "$_status_left_current" "$_status_left_expected" helper_print_fail "status-left did not match" "$_status_left_current" "$_status_left_expected"
helper_teardown helper_teardown
@ -41,7 +41,7 @@ EOF
fi fi
# check if status is not transparent # check if status is not transparent
_status_style_expected="bg=#3c3836,fg=#ebdbb2" _status_style_expected="bg=#3c3836,fg=#ebdbb2"
_status_style_current=$(tmux_get_statusstyle) _status_style_current=$(helper_tmux_get_statusstyle)
if [[ "$_status_style_current" != "$_status_style_expected" ]]; then if [[ "$_status_style_current" != "$_status_style_expected" ]]; then
helper_print_fail "status-style did not match" "$_status_style_current" "$_status_style_expected" helper_print_fail "status-style did not match" "$_status_style_current" "$_status_style_expected"
helper_teardown helper_teardown

View file

@ -3,7 +3,7 @@
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck disable=SC1091 # shellcheck disable=SC1091
source "${CURRENT_DIR}/../tmux_helpers.sh" source "${CURRENT_DIR}/../test_helpers.sh"
main() { main() {
helper_tearup_linux helper_tearup_linux
@ -34,7 +34,7 @@ EOF
# check if left side match # check if left side match
_status_left_expected="#[bg=#665c54,fg=#bdae93] #S #[bg=#3c3836,fg=#665c54,nobold,noitalics,nounderscore]" _status_left_expected="#[bg=#665c54,fg=#bdae93] #S #[bg=#3c3836,fg=#665c54,nobold,noitalics,nounderscore]"
_status_left_current=$(tmux_get_statusleft) _status_left_current=$(helper_tmux_get_statusleft)
if [[ "$_status_left_current" != "$_status_left_expected" ]]; then if [[ "$_status_left_current" != "$_status_left_expected" ]]; then
helper_print_fail "status-left did not match" "$_status_left_current" "$_status_left_expected" helper_print_fail "status-left did not match" "$_status_left_current" "$_status_left_expected"
helper_teardown helper_teardown
@ -42,7 +42,7 @@ EOF
fi fi
# check if status is not transparent # check if status is not transparent
_status_style_expected="bg=default,fg=#ebdbb2" _status_style_expected="bg=default,fg=#ebdbb2"
_status_style_current=$(tmux_get_statusstyle) _status_style_current=$(helper_tmux_get_statusstyle)
if [[ "$_status_style_current" != "$_status_style_expected" ]]; then if [[ "$_status_style_current" != "$_status_style_expected" ]]; then
helper_print_fail "status-style did not match" "$_status_style_current" "$_status_style_expected" helper_print_fail "status-style did not match" "$_status_style_current" "$_status_style_expected"
helper_teardown helper_teardown

View file

@ -3,7 +3,7 @@
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck disable=SC1091 # shellcheck disable=SC1091
source "${CURRENT_DIR}/../tmux_helpers.sh" source "${CURRENT_DIR}/../test_helpers.sh"
main() { main() {
helper_tearup_linux helper_tearup_linux
@ -33,7 +33,7 @@ EOF
# check if left side match # check if left side match
_status_left_expected="#[bg=colour239,fg=colour223] #S #[bg=colour250,fg=colour239,nobold,noitalics,nounderscore]" _status_left_expected="#[bg=colour239,fg=colour223] #S #[bg=colour250,fg=colour239,nobold,noitalics,nounderscore]"
_status_left_current=$(tmux_get_statusleft) _status_left_current=$(helper_tmux_get_statusleft)
if [[ "$_status_left_current" != "$_status_left_expected" ]]; then if [[ "$_status_left_current" != "$_status_left_expected" ]]; then
helper_print_fail "status-left did not match" "$_status_left_current" "$_status_left_expected" helper_print_fail "status-left did not match" "$_status_left_current" "$_status_left_expected"
helper_teardown helper_teardown
@ -41,7 +41,7 @@ EOF
fi fi
# check if status is not transparent # check if status is not transparent
_status_style_expected="bg=colour250,fg=colour237" _status_style_expected="bg=colour250,fg=colour237"
_status_style_current=$(tmux_get_statusstyle) _status_style_current=$(helper_tmux_get_statusstyle)
if [[ "$_status_style_current" != "$_status_style_expected" ]]; then if [[ "$_status_style_current" != "$_status_style_expected" ]]; then
helper_print_fail "status-style did not match" "$_status_style_current" "$_status_style_expected" helper_print_fail "status-style did not match" "$_status_style_current" "$_status_style_expected"
helper_teardown helper_teardown

View file

@ -3,7 +3,9 @@
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck disable=SC1091 # shellcheck disable=SC1091
source "${CURRENT_DIR}/../tmux_helpers.sh" source "${CURRENT_DIR}/../test_helpers.sh"
# shellcheck disable=SC1091
source "${CURRENT_DIR}/../tmux_utils.sh"
main() { main() {
helper_tearup_linux helper_tearup_linux
@ -34,7 +36,7 @@ EOF
# check if left side match # check if left side match
_status_left_expected="#[bg=colour239,fg=colour223] #S #[bg=colour250,fg=colour239,nobold,noitalics,nounderscore]" _status_left_expected="#[bg=colour239,fg=colour223] #S #[bg=colour250,fg=colour239,nobold,noitalics,nounderscore]"
_status_left_current=$(tmux_get_statusleft) _status_left_current=$(helper_tmux_get_statusleft)
if [[ "$_status_left_current" != "$_status_left_expected" ]]; then if [[ "$_status_left_current" != "$_status_left_expected" ]]; then
helper_print_fail "status-left did not match" "$_status_left_current" "$_status_left_expected" helper_print_fail "status-left did not match" "$_status_left_current" "$_status_left_expected"
helper_teardown helper_teardown
@ -42,7 +44,7 @@ EOF
fi fi
# check if status is not transparent # check if status is not transparent
_status_style_expected="bg=default,fg=colour237" _status_style_expected="bg=default,fg=colour237"
_status_style_current=$(tmux_get_statusstyle) _status_style_current=$(helper_tmux_get_statusstyle)
if [[ "$_status_style_current" != "$_status_style_expected" ]]; then if [[ "$_status_style_current" != "$_status_style_expected" ]]; then
helper_print_fail "status-style did not match" "$_status_style_current" "$_status_style_expected" helper_print_fail "status-style did not match" "$_status_style_current" "$_status_style_expected"
helper_teardown helper_teardown

View file

@ -3,7 +3,7 @@
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck disable=SC1091 # shellcheck disable=SC1091
source "${CURRENT_DIR}/../tmux_helpers.sh" source "${CURRENT_DIR}/../test_helpers.sh"
main() { main() {
helper_tearup_linux helper_tearup_linux
@ -33,7 +33,7 @@ EOF
# check if left side match # check if left side match
_status_left_expected="#[bg=#bdae93,fg=#665c54] #S #[bg=#ebdbb2,fg=#bdae93,nobold,noitalics,nounderscore]" _status_left_expected="#[bg=#bdae93,fg=#665c54] #S #[bg=#ebdbb2,fg=#bdae93,nobold,noitalics,nounderscore]"
_status_left_current=$(tmux_get_statusleft) _status_left_current=$(helper_tmux_get_statusleft)
if [[ "$_status_left_current" != "$_status_left_expected" ]]; then if [[ "$_status_left_current" != "$_status_left_expected" ]]; then
helper_print_fail "status-left did not match" "$_status_left_current" "$_status_left_expected" helper_print_fail "status-left did not match" "$_status_left_current" "$_status_left_expected"
helper_teardown helper_teardown
@ -41,7 +41,7 @@ EOF
fi fi
# check if status is not transparent # check if status is not transparent
_status_style_expected="bg=#ebdbb2,fg=#3c3836" _status_style_expected="bg=#ebdbb2,fg=#3c3836"
_status_style_current=$(tmux_get_statusstyle) _status_style_current=$(helper_tmux_get_statusstyle)
if [[ "$_status_style_current" != "$_status_style_expected" ]]; then if [[ "$_status_style_current" != "$_status_style_expected" ]]; then
helper_print_fail "status-style did not match" "$_status_style_current" "$_status_style_expected" helper_print_fail "status-style did not match" "$_status_style_current" "$_status_style_expected"
helper_teardown helper_teardown

View file

@ -3,7 +3,7 @@
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck disable=SC1091 # shellcheck disable=SC1091
source "${CURRENT_DIR}/../tmux_helpers.sh" source "${CURRENT_DIR}/../test_helpers.sh"
main() { main() {
helper_tearup_linux helper_tearup_linux
@ -34,7 +34,7 @@ EOF
# check if left side match # check if left side match
_status_left_expected="#[bg=#bdae93,fg=#665c54] #S #[bg=#ebdbb2,fg=#bdae93,nobold,noitalics,nounderscore]" _status_left_expected="#[bg=#bdae93,fg=#665c54] #S #[bg=#ebdbb2,fg=#bdae93,nobold,noitalics,nounderscore]"
_status_left_current=$(tmux_get_statusleft) _status_left_current=$(helper_tmux_get_statusleft)
if [[ "$_status_left_current" != "$_status_left_expected" ]]; then if [[ "$_status_left_current" != "$_status_left_expected" ]]; then
helper_print_fail "status-left did not match" "$_status_left_current" "$_status_left_expected" helper_print_fail "status-left did not match" "$_status_left_current" "$_status_left_expected"
helper_teardown helper_teardown
@ -42,7 +42,7 @@ EOF
fi fi
# check if status is not transparent # check if status is not transparent
_status_style_expected="bg=default,fg=#3c3836" _status_style_expected="bg=default,fg=#3c3836"
_status_style_current=$(tmux_get_statusstyle) _status_style_current=$(helper_tmux_get_statusstyle)
if [[ "$_status_style_current" != "$_status_style_expected" ]]; then if [[ "$_status_style_current" != "$_status_style_expected" ]]; then
helper_print_fail "status-style did not match" "$_status_style_current" "$_status_style_expected" helper_print_fail "status-style did not match" "$_status_style_current" "$_status_style_expected"
helper_teardown helper_teardown

View file

@ -3,7 +3,7 @@
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck disable=SC1091 # shellcheck disable=SC1091
source "${CURRENT_DIR}/../tmux_helpers.sh" source "${CURRENT_DIR}/../test_helpers.sh"
#### ####
# Test: when the theme is not defined in config it should fallback to 'dark256' # Test: when the theme is not defined in config it should fallback to 'dark256'
@ -36,7 +36,7 @@ EOF
# check if left side match # check if left side match
_status_left_expected="#[bg=colour241,fg=colour248] #S #[bg=colour237,fg=colour241,nobold,noitalics,nounderscore]" _status_left_expected="#[bg=colour241,fg=colour248] #S #[bg=colour237,fg=colour241,nobold,noitalics,nounderscore]"
_status_left_current=$(tmux_get_statusleft) _status_left_current=$(helper_tmux_get_statusleft)
if [[ "$_status_left_current" != "$_status_left_expected" ]]; then if [[ "$_status_left_current" != "$_status_left_expected" ]]; then
helper_print_fail "status-left did not match" "$_status_left_current" "$_status_left_expected" helper_print_fail "status-left did not match" "$_status_left_current" "$_status_left_expected"
helper_teardown helper_teardown
@ -44,7 +44,7 @@ EOF
fi fi
# check if status is not transparent # check if status is not transparent
_status_style_expected="bg=colour237,fg=colour223" _status_style_expected="bg=colour237,fg=colour223"
_status_style_current=$(tmux_get_statusstyle) _status_style_current=$(helper_tmux_get_statusstyle)
if [[ "$_status_style_current" != "$_status_style_expected" ]]; then if [[ "$_status_style_current" != "$_status_style_expected" ]]; then
helper_print_fail "status-style did not match" "$_status_style_current" "$_status_style_expected" helper_print_fail "status-style did not match" "$_status_style_current" "$_status_style_expected"
helper_teardown helper_teardown

View file

@ -33,7 +33,7 @@ helper_print_fail() {
} }
helper_print_success() { helper_print_success() {
local _msg="${1:-}" local _msg="${1}"
printf "SUCCESS. %s\n" "${_msg}" printf "SUCCESS. %s\n" "${_msg}"
} }
@ -52,7 +52,16 @@ helper_install_tpm_plugins() {
bash -c "${HOME}/.tmux/plugins/tpm/scripts/install_plugins.sh install_plugins" bash -c "${HOME}/.tmux/plugins/tpm/scripts/install_plugins.sh install_plugins"
} }
helper_get_project_root_dir() { # return the value of tmux status-style
_current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" helper_tmux_get_statusstyle() {
echo "${_current_dir}/../" local _val
_val=$(tmux show-option -gqv status-style)
echo "$_val"
}
# return the value of tmux status-left
helper_tmux_get_statusleft() {
local _val
_val=$(tmux show-option -gqv status-left)
echo "$_val"
} }