Skip to content

Commit

Permalink
feat: install bashunit using bashdep
Browse files Browse the repository at this point in the history
  • Loading branch information
Chemaclass committed Nov 12, 2024
1 parent 8412a6f commit 58bf024
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Here you can find developer tools to improve your DX.
Install testing library with:
```bash
cd tools
curl -s https://bashunit.typeddevs.com/install.sh | bash -s lib 0.10.1
./install-dependencies.sh
```

Run bash tests:
Expand Down
20 changes: 20 additions & 0 deletions tools/install-dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

# Ensure bashdep is installed
[ ! -f lib/bashdep ] && {
mkdir -p lib
curl -sLo lib/bashdep \
https://github.com/Chemaclass/bashdep/releases/download/0.1/bashdep
chmod +x lib/bashdep
}

# Add latest bashunit release to your dependencies
DEPENDENCIES=(
"https://github.com/TypedDevs/bashunit/releases/download/0.18.0/bashunit"
"https://github.com/Chemaclass/bash-dumper/releases/download/0.1/dumper.sh@dev"
)

# Load, configure and run bashdep
source lib/bashdep
bashdep::setup dir="lib" dev-dir="src/dev" silent=false
bashdep::install "${DEPENDENCIES[@]}"
58 changes: 58 additions & 0 deletions tools/src/dev/dumper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash

# Pass in any number of ANSI SGR codes.
#
# Code reference:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters
# Credit:
# https://superuser.com/a/1119396
sgr() {
local codes=${1:-0}
shift

for c in "$@"; do
codes="$codes;$c"
done

echo $'\e'"[${codes}m"
}

_COLOR_BOLD="$(sgr 1)"
_COLOR_FAINT="$(sgr 2)"
_COLOR_RED="$(sgr 31)"
_COLOR_YELLOW="$(sgr 33)"
_COLOR_BLACK="$(sgr 30)"
_COLOR_GREEN="$(sgr 32)"
_COLOR_DEFAULT="$(sgr 0)"

function trace() {
set -x
}

function untrace() {
set +x
}

# An alternative to echo when debugging.
function dump() {
printf "[%s] %s: %s\n" "${_COLOR_YELLOW}DUMP${_COLOR_DEFAULT}" \
"${_COLOR_GREEN}${BASH_SOURCE[1]}:${BASH_LINENO[0]}" \
"${_COLOR_DEFAULT}$*"
}

# Dump and Die.
function dd() {
printf "[%s] %s: %s\n" "${_COLOR_RED}DUMP${_COLOR_DEFAULT}" \
"${_COLOR_GREEN}${BASH_SOURCE[1]}:${BASH_LINENO[0]}" \
"${_COLOR_DEFAULT}$*"

kill -9 $$
}

function debug_var() {
local var_name=$1
local var_value=${!var_name}
printf "[%s] %s: %s=%s\n" "${_COLOR_FAINT}DEBUG${_COLOR_DEFAULT}" \
"${_COLOR_GREEN}${BASH_SOURCE[1]}:${BASH_LINENO[0]}" \
"$var_name" "$var_value"
}

0 comments on commit 58bf024

Please sign in to comment.