Skip to content

Commit

Permalink
func: add more traps
Browse files Browse the repository at this point in the history
  • Loading branch information
nazunalika committed Nov 21, 2023
1 parent 94cb574 commit 47c64bb
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 19 deletions.
3 changes: 1 addition & 2 deletions func/core/pkg_coreutils/12-cat.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/bin/bash
r_log "coreutils" "Testing cat"
trap "/bin/rm /var/tmp/cattest" EXIT

cat > /var/tmp/cattest <<EOF
Green Obsidian
EOF

grep -q "Green Obsidian" /var/tmp/cattest
r_checkExitStatus $?

/bin/rm /var/tmp/cattest
2 changes: 1 addition & 1 deletion func/core/pkg_coreutils/17-readlink.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
r_log "coreutils" "Testing readlink"
trap "/bin/rm /var/tmp/listen" EXIT
ln -s /var/tmp/talk /var/tmp/listen
readlink /var/tmp/listen | grep -q "/var/tmp/talk"
r_checkExitStatus $?
/bin/rm /var/tmp/listen
3 changes: 1 addition & 2 deletions func/core/pkg_coreutils/20-hash.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
r_log "coreutils" "Test hash sum tools"
trap '/bin/rm ${HASHFILE}' EXIT

HASHFILE=/var/tmp/obsidian
echo "Green Obsidian is our release name" > ${HASHFILE}
Expand All @@ -22,5 +23,3 @@ r_checkExitStatus $?
r_log "coreutils" "Test sha512sum"
/usr/bin/sha512sum ${HASHFILE} | grep -q e50554c29a5cb7bd04279d3c0918e486024c79c4b305a2e360a97d4021dacf56ce0d17fa6e6a0e81ad03d5fb74fbe2d50cce6081c2c277f22b958cdae978a2f5
r_checkExitStatus $?

/bin/rm ${HASHFILE}
3 changes: 1 addition & 2 deletions func/core/pkg_coreutils/21-touch-ls.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
r_log "coreutils" "Testing touch and ls"
trap '/bin/rm /tmp/touch-?' EXIT

r_log "coreutils" "Touch files with specific dates"
touch -t 199104230420 /tmp/touch-1
Expand All @@ -10,5 +11,3 @@ r_log "coreutils" "Verify that the oldest file is last"
ls -lt /tmp/touch-? | tail -n 1 | grep -q 'touch-1'

r_checkExitStatus $?

/bin/rm /tmp/touch-?
2 changes: 1 addition & 1 deletion func/core/pkg_coreutils/22-uniq.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
r_log "coreutils" "Ensure uniq works as expected"
trap '/bin/rm /var/tmp/uniq' EXIT

cat > /var/tmp/uniq <<EOF
Rocky
Expand All @@ -14,4 +15,3 @@ EOF

uniq -d /var/tmp/uniq | wc -l | grep -q 2 && uniq -u /var/tmp/uniq | wc -l | grep -q 4
r_checkExitStatus $?
/bin/rm /var/tmp/uniq
3 changes: 1 addition & 2 deletions func/core/pkg_coreutils/23-wc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
r_log "coreutils" "Ensure wc works as expected"
r_log "coreutils" "This should have already been done with uniq"
# Context: we should probably test some switches...
trap "/bin/rm /var/tmp/wc" EXIT

cat > /var/tmp/wc <<EOF
Rocky
Expand All @@ -21,5 +22,3 @@ wc -L /var/tmp/wc | grep -q 8 && \
wc -w /var/tmp/wc | grep -q 8

r_checkExitStatus $?

/bin/rm /var/tmp/wc
2 changes: 2 additions & 0 deletions func/core/pkg_cpio/10-cpio.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ OUTTER=/var/tmp/cpio/out
INNER=/var/tmp/cpio/in
PASSER=/var/tmp/cpio/pass

trap '/bin/rm -rf /var/tmp/cpio' EXIT

# Nothing should be here. Clean up first.
[ -d /var/tmp/cpio ] && /bin/rm -rf /var/tmp/cpio

Expand Down
1 change: 1 addition & 0 deletions func/core/pkg_cracklib/10-test-passwords.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ r_checkExitStatus $?

r_log "cracklib" "Testing a complicated password"
echo -e "2948_Obaym-" | cracklib-check | grep -q "OK"
r_checkExitStatus $?
4 changes: 2 additions & 2 deletions func/core/pkg_cron/10-dot-cron.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
r_log "cron" "Testing hourly cron jobs"

trap '/bin/rm /etc/cron.{weekly,daily,hourly}/rocky.sh' EXIT

cat > /etc/cron.hourly/rocky.sh <<EOF
#!/bin/bash
echo "obsidian"
Expand Down Expand Up @@ -34,5 +36,3 @@ chmod +x /etc/cron.weekly/rocky.sh

run-parts /etc/cron.weekly | grep -q "obsidian"
r_checkExitStatus $?

/bin/rm /etc/cron.{weekly,daily,hourly}/rocky.sh
3 changes: 1 addition & 2 deletions func/core/pkg_file/30-mime-symlink.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/bin/bash
r_log "file" "Check that we can see a symlink"
FILE_PATH=/var/tmp/linktest
trap '/bin/rm ${FILE_PATH}' EXIT
MIME="inode/symlink"
ln -s /etc/issue $FILE_PATH
file -i $FILE_PATH | grep -q "${MIME}"
r_checkExitStatus $?

/bin/rm /var/tmp/linktest
7 changes: 2 additions & 5 deletions func/core/pkg_findutils/10-find.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
r_log "findutils" "Testing basic find stuff"

TMPDIR=/var/tmp/find
trap '/bin/rm -rf $TMPDIR' EXIT

[ -e $TMPDIR ] && rm -rf "$TMPDIR"

Expand Down Expand Up @@ -37,8 +38,4 @@ r_log "findutils" "Perform for xargs test: fails with spaces in the name"
# shellcheck disable=SC2038
find "$TMPDIR" -type f | xargs ls &> /dev/null && { r_log "findutils" "Why did this get a 0 exit?"; exit "$FAIL"; }
ret_val=$?
if [ "$ret_val" -ne 0 ]; then
r_checkExitStatus $?
fi

rm -rf "$TMPDIR"
r_checkExitStatus $ret_val

0 comments on commit 47c64bb

Please sign in to comment.