2 # Copyright (c) 2015 Marcus Rohrmoser http://mro.name/me. All rights reserved.
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # insipired by https://github.com/lehmannro/assert.sh but much more primitive.
20 # terminal colors (require bash)
21 # http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html
22 # http://wiki.bash-hackers.org/scripting/terminalcodes
26 FGC_GREEN
="\033[1;32m"
27 FGC_YELLOW
="\033[1;33m"
29 FGC_PURPLE
="\033[1;35m"
31 FGC_WHITE
="\033[1;37m"
34 BGC_GREEN
="\033[7;32m"
35 BGC_YELLOW
="\033[7;33m"
37 BGC_PURPLE
="\033[7;35m"
39 BGC_WHITE
="\033[7;37m"
42 local CODE
="${1}" MESSAGE
="${2}"
43 echo -e "${BGC_RED}assert_fail (${CODE}): ${MESSAGE}${FGC_NONE}"
48 local EXPECTED
="${1}" ACTUAL="${2}" CODE="${3}" MESSAGE="${4}"
49 if [ ! "${EXPECTED}" = "${ACTUAL}" ] ; then
50 echo -e "${BGC_RED}assert_equal${FGC_NONE} (${CODE}): ${MESSAGE} expected: \"${FGC_GREEN}${EXPECTED}${FGC_NONE}\" != actual: \"${FGC_RED}${ACTUAL}${FGC_NONE}\""
56 local PATTERN
="${1}" ACTUAL="${2}" CODE="${3}" MESSAGE="${4}"
57 echo "${ACTUAL}" | fgrep
"${PATTERN}" 1> /dev
/null
2>&1 ||
{ \
58 echo -e "${BGC_RED}assert_equal${FGC_NONE} (${CODE}): ${MESSAGE} pattern: \"${FGC_GREEN}${PATTERN}${FGC_NONE}\" != actual: \"${FGC_RED}${ACTUAL}${FGC_NONE}\"" \