ci/testlib: add test root dir support
Allows creating (and cleaning up) a new root dir for tests, for tests that deal with files on disk Part-of: https://gitlab.postmarketos.org/postmarketOS/pmaports/-/merge_requests/6892
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user