diff --git a/.ci/lib/testlib.sh b/.ci/lib/testlib.sh index a9c0bcf0f..700c28595 100755 --- a/.ci/lib/testlib.sh +++ b/.ci/lib/testlib.sh @@ -23,6 +23,8 @@ _test_passedn=0 _test_failedn=0 _test_current_test="" _test_statefile="$(mktemp)" +_test_original_pwd="" +_test_temp_root="" # Set by each test results_dir="${results_dir:-}" @@ -42,6 +44,23 @@ test_debug() { echo -e "${YELLOW}$*${RESET}" >&2 } +create_test_root() { + _test_original_pwd="$(pwd)" + _test_temp_root="$(mktemp -d)" + cd "$_test_temp_root" +} + +cleanup_test_root() { + if [ -n "$_test_original_pwd" ]; then + cd "$_test_original_pwd" + fi + if [ -n "$_test_temp_root" ] && [ -d "$_test_temp_root" ]; then + rm -rf "$_test_temp_root" + fi + _test_original_pwd="" + _test_temp_root="" +} + assert_strequal() { # $1: first string # $2: second string