Add mechanisms to programmatically check for test failures

Add a test util method `hasFailed()` to the test util, and use it to exit with non-zero exit code from `bin/test` on failure.