Skip to content

Commit

Permalink
refactor: improve test
Browse files Browse the repository at this point in the history
  • Loading branch information
egel committed Sep 22, 2024
1 parent 495112f commit 0d8e96e
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 44 deletions.
13 changes: 0 additions & 13 deletions src/tmux_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,3 @@ tmux_set_window_option_now() {
_value="$2"
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"
}
6 changes: 3 additions & 3 deletions tests/linux/test_check_gruvbox_dark256_enabled.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# shellcheck disable=SC1091
source "${CURRENT_DIR}/../tmux_helpers.sh"
source "${CURRENT_DIR}/../test_helpers.sh"

main() {
helper_tearup_linux
Expand Down Expand Up @@ -33,15 +33,15 @@ EOF

# check if left side match
_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
helper_print_fail "status-left did not match" "$_status_left_current" "$_status_left_expected"
helper_teardown
exit 1
fi
# check if status is not transparent
_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
helper_print_fail "status-style did not match" "$_status_style_current" "$_status_style_expected"
helper_teardown
Expand Down
6 changes: 3 additions & 3 deletions tests/linux/test_check_gruvbox_dark256_transparent_enabled.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# shellcheck disable=SC1091
source "${CURRENT_DIR}/../tmux_helpers.sh"
source "${CURRENT_DIR}/../test_helpers.sh"

main() {
helper_tearup_linux
Expand Down Expand Up @@ -34,15 +34,15 @@ EOF

# check if left side match
_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
helper_print_fail "status-left did not match" "$_status_left_current" "$_status_left_expected"
helper_teardown
exit 1
fi
# check if status is not transparent
_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
helper_print_fail "status-style did not match" "$_status_style_current" "$_status_style_expected"
helper_teardown
Expand Down
6 changes: 3 additions & 3 deletions tests/linux/test_check_gruvbox_dark_enabled.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# shellcheck disable=SC1091
source "${CURRENT_DIR}/../tmux_helpers.sh"
source "${CURRENT_DIR}/../test_helpers.sh"

main() {
helper_tearup_linux
Expand Down Expand Up @@ -33,15 +33,15 @@ EOF

# check if left side match
_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
helper_print_fail "status-left did not match" "$_status_left_current" "$_status_left_expected"
helper_teardown
exit 1
fi
# check if status is not transparent
_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
helper_print_fail "status-style did not match" "$_status_style_current" "$_status_style_expected"
helper_teardown
Expand Down
6 changes: 3 additions & 3 deletions tests/linux/test_check_gruvbox_dark_transparent_enabled.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# shellcheck disable=SC1091
source "${CURRENT_DIR}/../tmux_helpers.sh"
source "${CURRENT_DIR}/../test_helpers.sh"

main() {
helper_tearup_linux
Expand Down Expand Up @@ -34,15 +34,15 @@ EOF

# check if left side match
_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
helper_print_fail "status-left did not match" "$_status_left_current" "$_status_left_expected"
helper_teardown
exit 1
fi
# check if status is not transparent
_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
helper_print_fail "status-style did not match" "$_status_style_current" "$_status_style_expected"
helper_teardown
Expand Down
6 changes: 3 additions & 3 deletions tests/linux/test_check_gruvbox_light256_enabled.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# shellcheck disable=SC1091
source "${CURRENT_DIR}/../tmux_helpers.sh"
source "${CURRENT_DIR}/../test_helpers.sh"

main() {
helper_tearup_linux
Expand Down Expand Up @@ -33,15 +33,15 @@ EOF

# check if left side match
_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
helper_print_fail "status-left did not match" "$_status_left_current" "$_status_left_expected"
helper_teardown
exit 1
fi
# check if status is not transparent
_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
helper_print_fail "status-style did not match" "$_status_style_current" "$_status_style_expected"
helper_teardown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# 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() {
helper_tearup_linux
Expand Down Expand Up @@ -34,15 +36,15 @@ EOF

# check if left side match
_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
helper_print_fail "status-left did not match" "$_status_left_current" "$_status_left_expected"
helper_teardown
exit 1
fi
# check if status is not transparent
_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
helper_print_fail "status-style did not match" "$_status_style_current" "$_status_style_expected"
helper_teardown
Expand Down
6 changes: 3 additions & 3 deletions tests/linux/test_check_gruvbox_light_enabled.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# shellcheck disable=SC1091
source "${CURRENT_DIR}/../tmux_helpers.sh"
source "${CURRENT_DIR}/../test_helpers.sh"

main() {
helper_tearup_linux
Expand Down Expand Up @@ -33,15 +33,15 @@ EOF

# check if left side match
_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
helper_print_fail "status-left did not match" "$_status_left_current" "$_status_left_expected"
helper_teardown
exit 1
fi
# check if status is not transparent
_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
helper_print_fail "status-style did not match" "$_status_style_current" "$_status_style_expected"
helper_teardown
Expand Down
6 changes: 3 additions & 3 deletions tests/linux/test_check_gruvbox_light_transparent_enabled.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# shellcheck disable=SC1091
source "${CURRENT_DIR}/../tmux_helpers.sh"
source "${CURRENT_DIR}/../test_helpers.sh"

main() {
helper_tearup_linux
Expand Down Expand Up @@ -34,15 +34,15 @@ EOF

# check if left side match
_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
helper_print_fail "status-left did not match" "$_status_left_current" "$_status_left_expected"
helper_teardown
exit 1
fi
# check if status is not transparent
_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
helper_print_fail "status-style did not match" "$_status_style_current" "$_status_style_expected"
helper_teardown
Expand Down
6 changes: 3 additions & 3 deletions tests/linux/test_without_theme_fallback_to_gruvbox_dark256.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# 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'
Expand Down Expand Up @@ -36,15 +36,15 @@ EOF

# check if left side match
_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
helper_print_fail "status-left did not match" "$_status_left_current" "$_status_left_expected"
helper_teardown
exit 1
fi
# check if status is not transparent
_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
helper_print_fail "status-style did not match" "$_status_style_current" "$_status_style_expected"
helper_teardown
Expand Down
17 changes: 13 additions & 4 deletions tests/tmux_helpers.sh → tests/test_helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ helper_print_fail() {
}

helper_print_success() {
local _msg="${1:-}"
local _msg="${1}"
printf "SUCCESS. %s\n" "${_msg}"
}

Expand All @@ -52,7 +52,16 @@ helper_install_tpm_plugins() {
bash -c "${HOME}/.tmux/plugins/tpm/scripts/install_plugins.sh install_plugins"
}

helper_get_project_root_dir() {
_current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo "${_current_dir}/../"
# return the value of tmux status-style
helper_tmux_get_statusstyle() {
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"
}

0 comments on commit 0d8e96e

Please sign in to comment.