Skip to content

Commit

Permalink
make more resilient, remove tmp files
Browse files Browse the repository at this point in the history
  • Loading branch information
mcblum committed Sep 14, 2024
1 parent c4708e8 commit 3ab011a
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tests/.storage
Empty file removed .tests/3455.ini
Empty file.
12 changes: 6 additions & 6 deletions tests/_common.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Include our script
source ./flex_ini.sh
source ./tests/_assertions.sh
source $test_parent_dir/../flex_ini.sh
source $test_parent_dir/_assertions.sh

fail() {
local msg="$1"
Expand All @@ -9,19 +9,19 @@ fail() {
}

init() {
mkdir -p "$testing_storage_dir"
mkdir -p "$test_storage_dir"
}

create_ini() {
filepath_one="${testing_storage_dir}/$$.ini"
filepath_one="${test_storage_dir}/$$.ini"
touch "$filepath_one"

echo "$filepath_one"
}

clean() {
if [ -z "$testing_storage_dir" ]; then
if [ -z "$test_storage_dir" ]; then
fail "Testing dir variable undefined!!! Extremely unsafe operation prevented"
fi
rm -rf "${testing_storage_dir}"
rm -rf "${test_storage_dir}"
}
9 changes: 5 additions & 4 deletions tests/_run.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
echo "Running tests for FlexIni..."

testing_storage_dir="$PWD/.tests"
test_parent_dir="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
test_storage_dir="$test_parent_dir/.tests"
echo ""

test_suites=()
cd ./tests/src
cd $test_parent_dir/src
for f in *; do
fn_name="${f/.sh/''}"
test_suites+=("$fn_name")
done
cd ../..

source ./tests/_common.sh
source $test_parent_dir/_common.sh

for t in "${test_suites[@]}"; do
init
source ./tests/src/$t.sh
source $test_parent_dir/src/$t.sh
echo ""
echo "[ $t ] running..."
${t}_before >/dev/null 2>&1 && echo "[ $t ] before method found + executed" || true
Expand Down
3 changes: 2 additions & 1 deletion tests/_run_local.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/opt/homebrew/bin/bash
./_run.sh
test_dir="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
$test_dir/_run.sh
2 changes: 1 addition & 1 deletion tests/src/test_flex_ini_has_unsaved.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test_flex_ini_has_unsaved() {
expect_return_code 1 "flex_ini_has_unsaved"

flex_ini_update "unsaved" "changed_again"
local save_as_path="${testing_storage_dir}/$$"
local save_as_path="${test_storage_dir}/$$"
flex_ini_save_as "$save_as_path" || fail "Could not save as"
expect_success "flex_ini_has_unsaved"
expect_return_code 0 "flex_ini_has_unsaved"
Expand Down
2 changes: 1 addition & 1 deletion tests/src/test_flex_ini_load.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ test_flex_ini_load() {
# Test auto-create
auto_create_ini_on_load=true

local autocreate_filepath="${testing_storage_dir}/auto_create.ini"
local autocreate_filepath="${test_storage_dir}/auto_create.ini"

flex_ini_load "$autocreate_filepath" "autocreate" || fail "There was a failure in auto-creation"
expect_file_exists "$autocreate_filepath"
Expand Down
2 changes: 1 addition & 1 deletion tests/src/test_flex_ini_save.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test_flex_ini_save() {
# Update the value of 'save_as' in the ini array
# but only save it as, leaving the original untouched.
flex_ini_update "save_as" "test"
local save_as_loc="${testing_storage_dir}/$$"
local save_as_loc="${test_storage_dir}/$$"
flex_ini_save_as "$save_as_loc"

flex_ini_reset
Expand Down

0 comments on commit 3ab011a

Please sign in to comment.