More robust test function. See xsh_test.c for usage