Returning failure exit code for test scripts.

Tests run within scripts were failing silently. I added bash logic after test
runs to check previous exit status and exit the script with a failure code if
the test commands failed.

Fixes #1293
yes, i'm sure (on linux, bash to be precise.) Sorry, it's the `test` (aka `[`) command actually, but anyways. It's interesting to learn that (in OSX) it behaves differently? 
You can test for yourself: ` grep --hi 2>/dev/null; if [ $? -ne 0 ]; then echo $?; fi`
prints 0 for me.