Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve testing #314

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion tests/application_module.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@ source "${script_dir}/helpers.sh"
tmux source "${script_dir}/../catppuccin_options_tmux.conf"
tmux source "${script_dir}/../catppuccin_tmux.conf"

print_option @catppuccin_status_application | sed -E 's/\b(bash|fish|zsh)\b/<application>/'
application_text=$(get_option @catppuccin_application_text)

print_option @catppuccin_status_application | grep -q "$application_text" ||
echo "@catppuccin_status_application expanded @catppuccin_application_text more than once"

print_option @catppuccin_status_application | grep -q "@thm_" &&
echo "@catppuccin_status_application did not expand all colors"
Comment on lines +13 to +17
Copy link
Contributor Author

@vdbe vdbe Sep 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add a die function in helpers that takes a msg and exit's with 1?

currently it fails on diff with expected


print_option E:@catppuccin_status_application | sed -E 's/\b(bash|fish|zsh)\b/<application>/'
2 changes: 1 addition & 1 deletion tests/application_module_expected.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
@catppuccin_status_application #[fg=#f5c2e7,bg=default,nobold,nounderscore,noitalics] #[fg=#11111b,bg=#f5c2e7] #[fg=#cdd6f4,bg=#45475a,nobold] <application>#[fg=#45475a,bg=default]█
E:@catppuccin_status_application #[fg=#f5c2e7,bg=default,nobold,nounderscore,noitalics] #[fg=#11111b,bg=#f5c2e7] #[fg=#cdd6f4,bg=#45475a,nobold] <application>#[fg=#45475a,bg=default]█
6 changes: 3 additions & 3 deletions tests/default_options.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ source "${script_dir}/helpers.sh"
tmux source "${script_dir}/../catppuccin_options_tmux.conf"
tmux source "${script_dir}/../catppuccin_tmux.conf"

print_option @catppuccin_flavor
print_option @catppuccin_menu_selected_style
print_option @catppuccin_pane_active_border_style
print_option E:@catppuccin_flavor
print_option E:@catppuccin_menu_selected_style
print_option E:@catppuccin_pane_active_border_style
6 changes: 3 additions & 3 deletions tests/default_options_expected.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@catppuccin_flavor mocha
@catppuccin_menu_selected_style fg=#313244,bg=#f9e2af
@catppuccin_pane_active_border_style fg=#b4befe
E:@catppuccin_flavor mocha
E:@catppuccin_menu_selected_style fg=#313244,bg=#f9e2af
E:@catppuccin_pane_active_border_style fg=#b4befe
5 changes: 5 additions & 0 deletions tests/harness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ run_test() {
local output
# shellcheck disable=SC1090
output=$(source "${test_script}")
test_exit_code="$?"

if test $test_exit_code -ne 0; then
die "\n${RED}Test ${script_name} exited with code $test_exit_code ${NOFORMAT}"
fi

echo -e "${output}" | diff -aB --color=${DIFFCOLORS} "${expected_output}" -

Expand Down
20 changes: 17 additions & 3 deletions tests/helpers.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
#!/usr/bin/env bash

# Returns the value of given tmux option.
# First argument is the option name, e.g. @catppuccin_flavor.
#
# Usage: `get_option @catppuccin_flavor`
# Would return: `mocha`
#
# The option is given as a format string.
get_option() {
local option
option=$1

tmux display-message -p "#{${option}}"
}

# Prints the given tmux option to stdout.
# First argument is the option name, e.g. @catppuccin_flavor.
#
# Usage: `print-option @catppuccin_flavor`
# Usage: `print_option @catppuccin_flavor`
# Would print: `@catppuccin_flavor mocha`
#
# The variable given is expanded as a format string.
# The option is given as a format string.
print_option() {
local option
option=$1

printf "\n%s " "${option}"
tmux display-message -p "#{E:${option}}"
get_option "$option"
}