added general test function that records stdout and stderr