Skip to content

Commit

Permalink
Merge pull request #5 from egurapha/unittests
Browse files Browse the repository at this point in the history
Setting up Automated Unit Testing
  • Loading branch information
egurapha authored Jan 26, 2025
2 parents 69fe979 + c4d9a9e commit 55a734b
Show file tree
Hide file tree
Showing 13 changed files with 1,487 additions and 22 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/code_formatting.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Code Formatting

on:
push:
branches:
- main
pull_request:
branches:
- main
Expand All @@ -10,7 +13,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout code
- name: Checkout.
uses: actions/checkout@v4

- name: Install shfmt.
Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/unit_testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Unit Testing

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
unit-testing:
runs-on: ubuntu-latest

steps:
- name: Checkout.
uses: actions/checkout@v4

- name: Set TERM environment variable
run: echo "TERM=xterm-256color" >> $GITHUB_ENV

- name: Install BATS.
run: sudo apt update && sudo apt install -y bats

- name: Run Unit Tests.
run: script -q -c "bats tests/"

- name: Success.
if: success()
run: echo "Unit Testing Passed."

- name: Failure.
if: failure()
run: echo "Unit Testing Failed."
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
Shunpo is a minimalist bash tool that tries to make directory navigation in terminal just a little bit faster by providing a simple system to manage bookmarks and jump to directories with only a few keystrokes.
If you frequently need to use commands like `cd`, `pushd`, or `popd`, Shunpo is for you.

![Powered by 🍵](https://img.shields.io/badge/Powered%20by-%F0%9F%8D%B5-green) [![Ko-fi](https://img.shields.io/badge/Ko--fi-Buy%20me%20Tea-ff5f5f?logo=kofi&style=flat-square)](https://ko-fi.com/egurapha)
![shfmt](https://github.com/egurapha/Shunpo/actions/workflows/code_formatting.yml/badge.svg)
![Powered by 🍵](https://img.shields.io/badge/Powered%20by-%F0%9F%8D%B5-blue?style=flat-square)
[![Ko-fi](https://img.shields.io/badge/Ko--fi-Buy%20me%20Tea-ff5f5f?logo=kofi&style=flat-square)](https://ko-fi.com/egurapha)
![Code Formatting](https://img.shields.io/badge/Code%20Formatting-Passing-green?style=flat-square)
![Unit Tests](https://img.shields.io/badge/Unit%20Tests-Passing-green?style=flat-square)

Requirements
----
Expand Down
35 changes: 17 additions & 18 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,22 @@ setup() {
touch $SHUNPORC
}

add_aliases() {
aliases=(
"sj:source $(realpath $INSTALL_DIR/jump_to_parent.sh)"
"sd:source $(realpath $INSTALL_DIR/jump_to_child.sh)"
"sb:$(realpath $INSTALL_DIR/add_bookmark.sh)"
"sr:$(realpath $INSTALL_DIR/remove_bookmark.sh)"
"sg:source $(realpath $INSTALL_DIR/go_to_bookmark.sh)"
"sl:$(realpath $INSTALL_DIR/list_bookmarks.sh)"
"sc:$(realpath $INSTALL_DIR/clear_bookmarks.sh)"
add_commands() {
INSTALL_DIR="$(realpath "$INSTALL_DIR")"

functions=(
"sj() { source \"$INSTALL_DIR/jump_to_parent.sh\"; }"
"sd() { source \"$INSTALL_DIR/jump_to_child.sh\"; }"
"sb() { \"$INSTALL_DIR/add_bookmark.sh\" \"\$@\"; }"
"sr() { \"$INSTALL_DIR/remove_bookmark.sh\" \"\$@\"; }"
"sg() { source \"$INSTALL_DIR/go_to_bookmark.sh\"; }"
"sl() { \"$INSTALL_DIR/list_bookmarks.sh\"; }"
"sc() { \"$INSTALL_DIR/clear_bookmarks.sh\"; }"
)
for alias_pair in "${aliases[@]}"; do
alias_name="${alias_pair%%:*}"
alias_command="${alias_pair#*:}"
alias_line="alias $alias_name='$alias_command'"

echo "$alias_line" >>"$SHUNPORC"
echo "Added: $alias_line"
for func_definition in "${functions[@]}"; do
echo "$func_definition" >>"$SHUNPORC"
echo "Created Command: ${func_definition%%()*}"
done
}

Expand All @@ -42,17 +41,17 @@ install() {
sed '/^source.*\.shunporc/d' "$BASHRC" >"$temp_file"
mv "$temp_file" "$BASHRC"
echo "$source_rc_line" >>"$BASHRC"
echo "Added: $source_rc_line"
echo "Added to BASHRC: $source_rc_line"

# record SHUNPO_DIR for uninstallation.
install_dir_line="export SHUNPO_DIR=$INSTALL_DIR" >>"$BASHRC$"
temp_file=$(mktemp)
grep -v '^export SHUNPO_DIR=' "$BASHRC" >"$temp_file"
mv "$temp_file" "$BASHRC"
echo "$install_dir_line" >>"$BASHRC"
echo "Added: $install_dir_line"
echo "Added to BASHRC: $install_dir_line"

add_aliases
add_commands
}

# Install.
Expand Down
8 changes: 7 additions & 1 deletion src/jump_to_parent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ trap 'handle_kill; return 1' SIGINT
jump_to_parent_dir $1

# Handle case where bookmark is not set.
if [ $? -eq 2 ]; then
if [ $? -eq 1 ]; then

if declare -f cleanup >/dev/null; then
cleanup
fi
return 1
elif [ $? -eq 2 ]; then
if declare -f cleanup >/dev/null; then
cleanup
fi
Expand Down
3 changes: 3 additions & 0 deletions tests/bats/Notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Files in this folder were copied from:
https://github.com/ztombol/bats-assert
https://github.com/ztombol/bats-support
Loading

0 comments on commit 55a734b

Please sign in to comment.