Add method method hasFailed() on test util.

This allows checking whether any of the tests run so far have failed.
Set non-zero exit code on test failure.

This facilitates programmatically checking if a test run failed. This is
handy for automation, bisecting, etc.