From d9a1088a3c1c6131fbd1bd5ea2a2dc10e2427eb2 Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Fri, 22 May 2020 18:07:37 -0700 Subject: [PATCH] tests: Depend upon /bin/sh supporting traps --- tests/alias.sh | 2 -- tests/core.sh | 2 -- tests/lib/test-setup.sh | 7 +++++-- tests/multi-update.sh | 1 - tests/pin-twice.sh | 2 -- tests/reject-duplicates.sh | 8 +------- tests/reject-nonancestor.sh | 2 -- 7 files changed, 6 insertions(+), 18 deletions(-) diff --git a/tests/alias.sh b/tests/alias.sh index 5083999..368fc1e 100755 --- a/tests/alias.sh +++ b/tests/alias.sh @@ -13,8 +13,6 @@ python3 ./pinch.py pin "$conf" actual_env_command=`python3 ./pinch.py update --dry-run "$conf"` -foo_cleanup - expected_env_command_RE='^nix-env --profile /nix/var/nix/profiles/per-user/[^/]+/channels --show-trace --file '\'''\'' --install --from-expression '\''f: f \{ name = "(repo-[0-9]{10}-[0-9a-f]{11})"; channelName = "bar"; src = builtins.storePath "/nix/store/.{32}-\1.tar.xz"; \}'\'' '\''f: f \{ name = "\1"; channelName = "foo"; src = builtins.storePath "/nix/store/.{32}-\1.tar.xz"; \}'\''$' if echo "$actual_env_command" | egrep "$expected_env_command_RE" > /dev/null;then diff --git a/tests/core.sh b/tests/core.sh index da0d991..5ef652e 100755 --- a/tests/core.sh +++ b/tests/core.sh @@ -8,8 +8,6 @@ python3 ./pinch.py pin "$conf" actual_env_command=`python3 ./pinch.py update --dry-run "$conf"` -foo_cleanup - expected_env_command_RE='^nix-env --profile /nix/var/nix/profiles/per-user/[^/]+/channels --show-trace --file '\'''\'' --install --from-expression '\''f: f \{ name = "(repo-[0-9]{10}-[0-9a-f]{11})"; channelName = "foo"; src = builtins.storePath "/nix/store/.{32}-\1.tar.xz"; \}'\''$' if echo "$actual_env_command" | egrep "$expected_env_command_RE" > /dev/null;then diff --git a/tests/lib/test-setup.sh b/tests/lib/test-setup.sh index 12cf525..4ccc8d9 100644 --- a/tests/lib/test-setup.sh +++ b/tests/lib/test-setup.sh @@ -21,6 +21,9 @@ EOF } -foo_cleanup() { - rm -rf "$repo_dir" "$conf" +test_cleanup() { + if [ "$repo_dir" ];then rm -rf "$repo_dir"; fi + if [ "$conf" ];then rm "$conf"; fi } + +trap test_cleanup EXIT INT TERM diff --git a/tests/multi-update.sh b/tests/multi-update.sh index d6a6d54..74899ff 100755 --- a/tests/multi-update.sh +++ b/tests/multi-update.sh @@ -15,7 +15,6 @@ python3 ./pinch.py pin "$conf2" actual_env_command=`python3 ./pinch.py update --dry-run "$conf" "$conf2"` -foo_cleanup rm -rf "$conf2" expected_env_command_RE='^nix-env --profile /nix/var/nix/profiles/per-user/[^/]+/channels --show-trace --file '\'''\'' --install --from-expression '\''f: f \{ name = "(repo-[0-9]{10}-[0-9a-f]{11})"; channelName = "bar"; src = builtins.storePath "/nix/store/.{32}-\1.tar.xz"; \}'\'' '\''f: f \{ name = "\1"; channelName = "foo"; src = builtins.storePath "/nix/store/.{32}-\1.tar.xz"; \}'\''$' diff --git a/tests/pin-twice.sh b/tests/pin-twice.sh index 5f51cc0..dec02f0 100755 --- a/tests/pin-twice.sh +++ b/tests/pin-twice.sh @@ -17,8 +17,6 @@ python3 ./pinch.py pin "$conf" actual_env_command=`python3 ./pinch.py update --dry-run "$conf"` -foo_cleanup - expected_env_command_RE='^nix-env --profile /nix/var/nix/profiles/per-user/[^/]+/channels --show-trace --file '\'''\'' --install --from-expression '\''f: f \{ name = "(repo-[0-9]{10}-[0-9a-f]{11})"; channelName = "foo"; src = builtins.storePath "/nix/store/.{32}-\1.tar.xz"; \}'\''$' if echo "$actual_env_command" | egrep "$expected_env_command_RE" > /dev/null;then diff --git a/tests/reject-duplicates.sh b/tests/reject-duplicates.sh index 8a630b0..a6978f8 100755 --- a/tests/reject-duplicates.sh +++ b/tests/reject-duplicates.sh @@ -20,10 +20,4 @@ else echo PASS fi -foo_cleanup - -repo_dir=$repo_dir1 -repo=$repo1 -conf=$conf1 - -foo_cleanup +rm -rf "$repo_dir1" "$repo1" "$conf1" diff --git a/tests/reject-nonancestor.sh b/tests/reject-nonancestor.sh index 5608761..f8cc2e9 100755 --- a/tests/reject-nonancestor.sh +++ b/tests/reject-nonancestor.sh @@ -19,5 +19,3 @@ if python3 ./pinch.py pin "$conf";then else echo PASS fi - -foo_cleanup -- 2.44.1