# http://redsymbol.net/articles/unofficial-bash-strict-mode/ #set -e ;# exit if any command has a non-zero exit status set -u ;# a reference to any variable you haven't previously defined - with the exceptions of $* and $@ - is an error, and causes the program to immediately exit #set -o pipefail ;# If any command in a pipeline fails, that return code will be used as the return code of the whole pipeline #IFS=$'\n\t' # If this file has already been sourced, just return test $(COMMON_SH+true)TODO && return declare -g COMMON_SH = 'true' # echo "Defining common commands" proc stderr { echo $(@) !2 > !1 } proc functionExistsTODO { declare functionName = $(1)TODO declare type = $[type -t $(functionName)] if [[ $? != 0 ]] { # not found at all return 1 } elif [[ $type == "function" ]] { return 0 } else { return 1 }TODO } declare -g -A ASSERT_RESULTS = '('[total]=0 [passed]=0 [failed]=0) proc assert::equalsTODO { declare expect = $1TODO declare actual = $2TODO declare message = $(@:3) sh-expr ' ASSERT_RESULTS[total]+=1 ' if test $expect != $actual { echo "FAILED ('$expect' != '$actual') $message" log "FAILED ('$expect' != '$actual') $message" sh-expr ' ASSERT_RESULTS[failed]+=1 ' return 1 } echo "PASSED $message" sh-expr ' ASSERT_RESULTS[passed]+=1 ' return 0 } proc assert::report { echo "TESTS [total=$(ASSERT_RESULTS[total])] [passed=$(ASSERT_RESULTS[passed])] [failed=$(ASSERT_RESULTS[failed])]" }