Make test.sh more robust