Skip to content

Instantly share code, notes, and snippets.

@qwertme
Created April 20, 2011 17:06
Show Gist options
  • Save qwertme/931961 to your computer and use it in GitHub Desktop.
Save qwertme/931961 to your computer and use it in GitHub Desktop.
Bash assertions
ASSERT_COUNTER=0
ASSERT_FAIL_COUNTER=0
assert_equal() {
let ASSERT_COUNTER=ASSERT_COUNTER+1
if [ "$1" != "$2" ]; then
let ASSERT_FAIL_COUNTER=ASSERT_FAIL_COUNTER+1
echo "Expecting '$1' got '$2'"
fi
}
assert_file_line() {
assert_equal "$1" "`head -$2 $3 | tail -1`"
}
print_results() {
echo "Ran $ASSERT_COUNTER tests with $ASSERT_FAIL_COUNTER failures"
if [ "$ASSERT_FAIL_COUNTER" -ne "0" ]; then
echo "UNIT TESTS FAILED"
else
echo "UNIT TESTS PASSED"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment