Fix test script to report error code automatically