Zero length keys test improvements
The zero length keys could use some small improvements, such as;
- Remove the temporary directories that are generated. It prevents the main temporary directory from growing over time after each script execution. The solution would be a trap that removes them when the script exits.
diff --git a/src/test/zero_length_keys.sh b/src/test/zero_length_keys.sh
index 3a99ca1..2545734 100755
--- a/src/test/zero_length_keys.sh
+++ b/src/test/zero_length_keys.sh
@@ -26,6 +26,8 @@ if [ $# -lt 1 ]; then
fi
export DATA_DIR=`mktemp -d -t tor_zero_length_keys.XXXXXX`
+trap "rm -rf "$DATA_DIR"" 0
+
# DisableNetwork means that the ORPort won't actually be opened.
# 'ExitRelay 0' suppresses a warning.
TOR="./src/or/tor --hush --DisableNetwork 1 --ShutdownWaitLength 0 --ORPort 12345 --ExitRelay 0"
- Do not export the variable
DATA_DIR
because it is useless and stop using the old style command substitution because it has cases of undefined results [0]. Also Bash mentions a preference towards the newer$()
style [1].
diff --git a/src/test/zero_length_keys.sh b/src/test/zero_length_keys.sh
index 3a99ca1..ede7df5 100755
--- a/src/test/zero_length_keys.sh
+++ b/src/test/zero_length_keys.sh
@@ -25,7 +25,8 @@ if [ $# -lt 1 ]; then
exit $?
fi
-export DATA_DIR=`mktemp -d -t tor_zero_length_keys.XXXXXX`
+DATA_DIR="$(mktemp -d -t tor_zero_length_keys.XXXXXX)"
+
# DisableNetwork means that the ORPort won't actually be opened.
# 'ExitRelay 0' suppresses a warning.
TOR="./src/or/tor --hush --DisableNetwork 1 --ShutdownWaitLength 0 --ORPort 12345 --ExitRelay 0"
- Because i am unsure which platforms/shells need to be supported, this improvement may be more work than the satisfaction of correctness it gives. In GNU Coreutils the
mktemp
program marks the-t
option as deprecated [2]. On other platforms the option is not deprecated. A list of options of the severalmktemp
implementations is available on StackOverflow. The question is whether the script needs to be platform-aware so it can avoid deprecated options or not.
[0] http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_03
[1] https://www.gnu.org/software/bash/manual/bashref.html#Major-Differences-From-The-Bourne-Shell (search for $()
)
[2] https://www.gnu.org/software/coreutils/manual/html_node/mktemp-invocation.html#mktemp-invocation
PS: The patches are just suggestions, if others agree i can merge them together into one patch and upload a patch file for easier merging.