aboutsummaryrefslogtreecommitdiff
path: root/tests/lib.sh
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2021-09-01 11:02:20 -0300
committerEuAndreh <eu@euandre.org>2021-09-01 11:02:20 -0300
commit3832d1ee69c415e54e8f7ae92dffcb9a23444407 (patch)
tree0a607259bde37e2a3dd894e3fb93c4cf43fd287b /tests/lib.sh
parentmv src/remembering-c.c src/remembering.c (diff)
downloadremembering-3832d1ee69c415e54e8f7ae92dffcb9a23444407.tar.gz
remembering-3832d1ee69c415e54e8f7ae92dffcb9a23444407.tar.xz
tests/lib.sh: Update
Diffstat (limited to 'tests/lib.sh')
-rwxr-xr-xtests/lib.sh29
1 files changed, 25 insertions, 4 deletions
diff --git a/tests/lib.sh b/tests/lib.sh
index 76f22e3..527e645 100755
--- a/tests/lib.sh
+++ b/tests/lib.sh
@@ -16,7 +16,9 @@ ERROR() {
}
print_debug_info() {
- printf 'LINENO: %s\nOUT: %s\n%s: %s\n' "$N" "$OUT" "$(ERROR)" "$ERR" >&2
+ # shellcheck disable=2016
+ printf 'LINENO: %s\n$OUT: %s\n$ERR: %s\n' \
+ "$N" "$OUT" "$ERR" >&2
}
assert_status() {
@@ -39,7 +41,9 @@ assert_usage() {
assert_empty_stream() {
if [ -s "$2" ]; then
- printf '\n%s: Expected %s (%s) to be empty, but has content:\n%s\n' \
+ FMT='\n%s: Expected %s (%s) to be empty, but has content:\n%s\n'
+ # shellcheck disable=2059
+ printf "$FMT" \
"$(ERROR)" "$1" "$2" "$(cat "$2")" >&2
print_debug_info
exit 1
@@ -117,7 +121,24 @@ test_ok() {
uuid() {
# Taken from:
# https://serverfault.com/a/799198
- od -xN20 /dev/urandom | \
- head -1 | \
+ od -xN20 /dev/urandom |
+ head -1 |
awk '{OFS="-"; print $2$3,$4,$5,$6,$7$8$9}'
}
+
+tmpname() {
+ echo 'mkstemp(template)' | m4 -D template="${TMPDIR:-/tmp}/m4-tmpname."
+}
+
+mkstemp() {
+ name="$(tmpname)"
+ touch "$name"
+ echo "$name"
+}
+
+mkdtemp() {
+ name="$(tmpname)"
+ rm -f "$name"
+ mkdir "$name"
+ echo "$name"
+}