Skip to content

Instantly share code, notes, and snippets.

@estrattonbailey
Last active April 27, 2022 14:47
Show Gist options
  • Save estrattonbailey/445c378aa25b779e9f3cff1ce581d584 to your computer and use it in GitHub Desktop.
Save estrattonbailey/445c378aa25b779e9f3cff1ce581d584 to your computer and use it in GitHub Desktop.
~/test.sh index.mjs [-w]
red="\e[31m"
green="\e[32m"
reset="\e[0m"
bold="\e[1m"
run()
{
tmperr="$(mktemp -u)"
tmpout="$(mktemp -u)"
node $1 2> tmperr > tmpout
err="$(cat tmperr && rm tmperr)"
out="$(cat tmpout && rm tmpout)"
echo "${out}"
if [[ $err != '' ]]; then
gecho -e "${red}${bold}FAIL ${1}${reset}"
gecho "${err}"
else
gecho -e "${green}${bold}PASS ${1}${reset}"
fi
}
watch=0
glob=0
for arg in "$@"
do
if [[ $arg == *\-w ]]; then
watch=1
else
glob=$arg
fi
done
files=$glob
gecho -e "\n${green}${bold}t e s t i n g${reset}"
if [[ $watch == 1 ]]; then
prev=()
for file in $1; do
h=($(md5sum $file))
prev+=("$file;$h")
done
while [[ true ]]; do
next=()
for file in $1; do
h=($(md5sum $file))
next+=("$file;$h")
done
size=${#next[@]}
for ((i = 0; i <= $size; i++)); do
if [[ ${prev[$i]} != ${next[$i]} ]]; then
IFS=";" read -ra file <<< "${next[$i]}"
run ${file[0]}
prev[$i]=${next[i]}
fi
done
sleep 0.01
done
else
for file in $files; do
run $file
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment