From 84b7598b100ba8ff3e91c6aa019232363bfdffaf Mon Sep 17 00:00:00 2001 From: Postmodern Date: Fri, 4 Jun 2021 22:47:01 -0700 Subject: [PATCH] Better compartmentalize test fixture files and rm -rf them. * tearDown actually runs an additional time after all test_* functions have been called. https://github.com/kward/shunit2/issues/112 --- test/cli-tests/no_reinstall_test.sh | 4 ++-- test/functions-tests/apply_patches_test.sh | 4 ++-- test/functions-tests/download_patches_test.sh | 7 ++++++- .../download_ruby_versions_file_test.sh | 5 ++++- test/util-tests/fetch_test.sh | 4 ++-- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/test/cli-tests/no_reinstall_test.sh b/test/cli-tests/no_reinstall_test.sh index 8dfd1142..124ce1cc 100755 --- a/test/cli-tests/no_reinstall_test.sh +++ b/test/cli-tests/no_reinstall_test.sh @@ -2,7 +2,7 @@ . ./test/helper.sh -test_install_dir="$test_fixtures_dir/install_dir" +test_install_dir="$test_fixtures_dir/no_reinstall_test" function setUp() { @@ -22,7 +22,7 @@ function test_no_reinstall_when_ruby_executable_exists() function tearDown() { - rm -r "$test_install_dir" + rm -rf "$test_install_dir" } SHUNIT_PARENT=$0 . $SHUNIT2 diff --git a/test/functions-tests/apply_patches_test.sh b/test/functions-tests/apply_patches_test.sh index bda0c617..17139d07 100755 --- a/test/functions-tests/apply_patches_test.sh +++ b/test/functions-tests/apply_patches_test.sh @@ -3,7 +3,7 @@ . ./test/helper.sh . ./share/ruby-install/functions.sh -src_dir="$test_fixtures_dir/src" +src_dir="$test_fixtures_dir/apply_patches_test" ruby_dir_name="ruby-1.9.3-p448" patches=("$src_dir/$ruby_dir_name/falcon-gc.diff") @@ -30,7 +30,7 @@ function test_apply_patches() function tearDown() { - rm -r "$src_dir/$ruby_dir_name" + rm -rf "$src_dir" } SHUNIT_PARENT=$0 . $SHUNIT2 diff --git a/test/functions-tests/download_patches_test.sh b/test/functions-tests/download_patches_test.sh index fd804239..3b273adb 100755 --- a/test/functions-tests/download_patches_test.sh +++ b/test/functions-tests/download_patches_test.sh @@ -3,6 +3,8 @@ . ./test/helper.sh . ./share/ruby-install/functions.sh +src_dir="$test_fixtures_dir/download_patches_test" + patches=("https://gist.github.com/funny-falcon/2981959/raw/ary-queue.diff" "local.patch") ruby_dir_name="ruby-1.9.3-p448" @@ -17,13 +19,16 @@ function test_download_patches() assertTrue "did not download patches to \$src_dir/\$ruby_dir_name" \ '[[ -f "$src_dir/$ruby_dir_name/ary-queue.diff" ]]' + assertEquals "did not update \$patches" \ "${patches[0]}" "$src_dir/$ruby_dir_name/ary-queue.diff" + + ls "$src_dir/$ruby_dir_name" } function tearDown() { - rm -r "$src_dir/$ruby_dir_name" + rm -rf "$src_dir" } SHUNIT_PARENT=$0 . $SHUNIT2 diff --git a/test/ruby-versions-tests/download_ruby_versions_file_test.sh b/test/ruby-versions-tests/download_ruby_versions_file_test.sh index b5cca309..d3fde5c2 100755 --- a/test/ruby-versions-tests/download_ruby_versions_file_test.sh +++ b/test/ruby-versions-tests/download_ruby_versions_file_test.sh @@ -3,8 +3,11 @@ . ./test/helper.sh . ./share/ruby-install/ruby-versions.sh +ruby_install_cache_dir="$test_fixtures_dir/download_ruby_versions_file_test" + ruby="ruby" file="stable.txt" + expected_path="$ruby_install_cache_dir/$ruby/$file" function test_download_ruby_versions_file_with_no_parent_dir() @@ -42,7 +45,7 @@ function test_download_ruby_versions_file_with_existing_file() function tearDown() { - rm -rf "$ruby_install_cache_dir/$ruby" + rm -rf "$ruby_install_cache_dir" } SHUNIT_PARENT=$0 . $SHUNIT2 diff --git a/test/util-tests/fetch_test.sh b/test/util-tests/fetch_test.sh index 1d6daf00..d778db20 100755 --- a/test/util-tests/fetch_test.sh +++ b/test/util-tests/fetch_test.sh @@ -2,7 +2,7 @@ . ./test/helper.sh -ruby_install_dir="$test_fixtures_dir/fetch" +ruby_install_dir="$test_fixtures_dir/fetch_test" test_file="$ruby_install_dir/db.txt" @@ -61,7 +61,7 @@ function test_fetch_with_unknown_key() function tearDown() { - rm -r "$ruby_install_dir" + rm -rf "$ruby_install_dir" } SHUNIT_PARENT=$0 . $SHUNIT2