update build and test script to properly handle error codes on return