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

feat: add tests for linux #39

Merged
merged 12 commits into from
Sep 22, 2024
34 changes: 34 additions & 0 deletions .github/workflows/dev-push-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: dev-push-check
run-name: ${{ github.actor }} pushed new code 💻
on: [push] #, pull_request]
jobs:
lint_shellcheck:
runs-on: ubuntu-latest
steps:
- name: Install shellcheck
run: sudo apt-get install -y shellcheck
- name: Checkout repo
uses: actions/checkout@main
- name: Lint files against shellcheck
run: make lint_shellcheck
lint_shfmt:
runs-on: ubuntu-latest
steps:
- name: Install shfmt
run: sudo apt-get install -y shfmt
- name: Checkout repository
uses: actions/checkout@main
- name: Lint files against shfmt
run: make lint_shfmt
test_setup_linux:
runs-on: ubuntu-latest
needs:
- lint_shfmt
- lint_shellcheck
steps:
- name: Install required software
run: sudo apt install -y tmux git
- name: Checkout repository
uses: actions/checkout@main
- name: Execute all linux tests and check results
run: ./tests/run_all_linux_tests.sh
22 changes: 0 additions & 22 deletions .github/workflows/github-actions.yml

This file was deleted.

21 changes: 18 additions & 3 deletions src/gruvbox-main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,24 @@ get_theme() {
}

main() {
local theme
theme=$(get_theme "$THEME_OPTION" "$DEFAULT_THEME")
tmux source-file "$CURRENT_DIR/tmux-gruvbox-${theme}.conf"
local _theme _path
_theme=$(get_theme "$THEME_OPTION" "$DEFAULT_THEME")
case "$_theme" in
light-transparent)
_theme="light-transparent"
;;
dark-transparent)
_theme="dark-transparent"
;;
light | light256)
_theme="light"
;;
dark | dark256 | *)
_theme="dark"
;;
esac

tmux source-file "${CURRENT_DIR}/tmux-gruvbox-${_theme}.conf"
}

main "$@"
6 changes: 6 additions & 0 deletions tests/linux/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Linux tests

Those test is meant to run on linux

- ubuntu 20.04 LTS
- bash
51 changes: 51 additions & 0 deletions tests/linux/test_default_start_set_gruvbox_dark256.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

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

main() {
helper_tearup_linux

cat <<EOF >~/.tmux.conf
# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'

# Other plugins
set -g @plugin 'egel/tmux-gruvbox'
set -g @tmux-gruvbox 'dark'
egel marked this conversation as resolved.
Show resolved Hide resolved

# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'
EOF

cat ~/.tmux.conf

# it's essential to link current repo to the plugins' directory
ln -sfv "$CURRENT_DIR/../../../tmux-gruvbox" "${HOME}/.tmux/plugins/tmux-gruvbox"

helper_install_tpm_plugins

# start new detached session
tmux new -d

# default value of status-left section from gruvbox theme
_status_left_expected="#[bg=colour241,fg=colour248] #S #[bg=colour237,fg=colour241,nobold,noitalics,nounderscore]"

# get status of something from theme
_status_left_current=$(tmux show-option -gqv status-left)
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

helper_print_success "status-left match"
helper_teardown
exit 0

}

main "$@"
51 changes: 51 additions & 0 deletions tests/linux/test_gruvbox_light256_theme_enabled.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

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

main() {
helper_tearup_linux

cat <<EOF >~/.tmux.conf
# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'

# Other plugins
set -g @plugin 'egel/tmux-gruvbox'
set -g @tmux-gruvbox 'light256'

# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'
EOF

cat ~/.tmux.conf

# it's essential to link current repo to the plugins' directory
ln -sfv "$CURRENT_DIR/../../../tmux-gruvbox" "${HOME}/.tmux/plugins/tmux-gruvbox"

helper_install_tpm_plugins

# start new detached session
tmux new -d

# default value of status-left section from gruvbox theme
_status_left_expected="#[bg=colour243,fg=colour255] #S #[bg=colour252,fg=colour243,nobold,noitalics,nounderscore]"

# get status of something from theme
_status_left_current=$(tmux show-option -gqv status-left)
if [[ "$_status_left_expected" != "$_status_left_current" ]]; then
helper_print_fail "status-left did not match" "$_status_left_current" "$_status_left_expected"
helper_teardown
exit 1
fi

helper_print_success "status-left match"
helper_teardown
exit 0

}

main "$@"
31 changes: 31 additions & 0 deletions tests/run_all_linux_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

main() {
set -e # exit on error
declare -i _countFailures
local _files
_countFailures=0
_files=$(find "$CURRENT_DIR/linux" -name "test_*" -type f)
for test in $_files; do
printf "\n=============================================="
printf "\n %s" "$test"
printf "\n=============================================="
printf ""
bash -c "$test"

# run all and count failures
retVal=$?
if [ $retVal -eq 1 ]; then
_countFailures+=1
fi
done

# check if anything failed and fail
if [ "$_countFailures" -gt 0 ]; then
exit 1
fi
}

main "$@"
58 changes: 58 additions & 0 deletions tests/tmux_helpers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash

helper_teardown() {
echo "TEARDOWN"
rm -rf ~/.tmux.conf
rm -rf ~/.tmux/
tmux kill-server >/dev/null 2>&1
}

helper_tearup_linux() {
if [[ "$(uname)" != "Linux" ]]; then
echo "NOT LINUX. Failed & exit."
exit 1
fi
echo "TEARUP LINUX"

# install software
sudo apt update -y
sudo apt install -y tmux git

# download TPM
mkdir -p ~/.tmux/plugins/
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
}

helper_print_fail() {
local _msg="${1}"
local _current_val="${2}"
local _expected_val="${3}"
printf "FAIL. %s\n" "${_msg}"
printf "current value:\t%s\n" "$_current_val"
printf "expected value:\t%s\n" "$_expected_val"
}

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

helper_print_fail_and_exit() {
helper_print_fail "$1" "$2" "$3"
exit 1
}

helper_print_success_and_exit() {
helper_print_success "$1" "$2" "$3"
exit 0
}

# install TMP plugins with command
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}/../"
}