pentest-distro-builder/filesystem/root/.tmux/plugins/tmux-net-speed/tests/test_utils.sh
Kaj Forney 4fdc60b6a2 Add autologin and custom tmux config.
Former-commit-id: 9f5a64d372
Former-commit-id: 89d8a1302bd2a72239fbe9ad9820be4ecda76cab
2018-09-27 17:40:01 -06:00

91 lines
1.5 KiB
Bash

#!/bin/bash -
###############################################################################
# Author: Travis Goldie
# Purpose: Util funcs for unit tests
###############################################################################
##
# Description:
# Asserts if `$1` equals `$2`
##
assertEqual()
{
local input=$1
local expected=$2
local msg=$3
if [[ "$4" == "-v" ]] ; then
echo $@
fi
if [[ -z msg ]] ; then
msg="Failed test"
fi
test "$1" == "$2"
err=$?
if [[ $err == 0 ]] ; then
echo "[PASSED]: ${msg}"
echo
return $err
fi
if [[ $err != 0 ]] ; then
echo "[FAILED]: ${msg}"
echo
return $err
fi
}
##
# Description:
# Asserts if `$1` not equals `$2`
##
assertNotEqual()
{
local input=$1
local expected=$2
local msg=$3
if [[ -z msg ]] ; then
msg="Failed test"
fi
test "$1" != "$2"
err=$?
if [[ $err == 0 ]] ; then
echo "[PASSED]: ${msg}"
echo
return $err
fi
if [[ $err != 0 ]] ; then
echo "[FAILED]: ${msg}"
echo
return $err
fi
}
##
# @description
# Checks to see if error code is non-zero. If so, echo message and exit
# with the given error code.
#
# ``` bash
# $ someCmd blah blah2
# $ err=$?
# $ die $err "If err is non-zero this script will exit"
# ```
##
die()
{
local err=$1
local msg=$2
local name=$( basename $0 )
if [[ $err != 0 ]] ; then
echo "[ERROR]:${name}:code $err:${msg}"
exit $err
fi
}