Skip to content

Commit

Permalink
tests: directly test for presence of command
Browse files Browse the repository at this point in the history
Test directly for presence of command instead of indirectly testing
the return code.

Additionally:

* uses a shell builtin `command -v` instead of external `which`
* `command -v` is the standardized version of `which`
  • Loading branch information
a1346054 committed Sep 13, 2022
1 parent 4157640 commit e04d6b7
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 71 deletions.
2 changes: 1 addition & 1 deletion contrib/gdb-firejail.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if [ -z "${1##*/firejail}" ]; then
else
# First argument is not named firejail, then add default unless environment
# variable already set.
set -- ${FIREJAIL:=$(which firejail)} "$@"
set -- ${FIREJAIL:=$(command -v firejail)} "$@"
fi

bash -c "kill -STOP \$\$; exec \"\$0\" \"\$@\"" "$@" &
Expand Down
12 changes: 4 additions & 8 deletions test/apps-x11-xorg/apps-x11-xorg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,31 @@ export MALLOC_CHECK_=3
export MALLOC_PERTURB_=$(($RANDOM % 255 + 1))
export LC_ALL=C

which firefox 2>/dev/null
if [ "$?" -eq 0 ];
if command -v firefox
then
echo "TESTING: firefox x11 xorg"
./firefox.exp
else
echo "TESTING SKIP: firefox not found"
fi

which transmission-gtk 2>/dev/null
if [ "$?" -eq 0 ];
if command -v transmission-gtk
then
echo "TESTING: transmission-gtk x11 xorg"
./transmission-gtk.exp
else
echo "TESTING SKIP: transmission-gtk not found"
fi

which transmission-qt 2>/dev/null
if [ "$?" -eq 0 ];
if command -v transmission-qt
then
echo "TESTING: transmission-qt x11 xorg"
./transmission-qt.exp
else
echo "TESTING SKIP: transmission-qt not found"
fi

which thunderbird 2>/dev/null
if [ "$?" -eq 0 ];
if command -v thunderbird
then
echo "TESTING: thunderbird x11 xorg"
./thunderbird.exp
Expand Down
27 changes: 9 additions & 18 deletions test/apps-x11/apps-x11.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,18 @@ echo "TESTING: no x11 (test/apps-x11/x11-none.exp)"
./x11-none.exp


which xterm 2>/dev/null
if [ "$?" -eq 0 ];
if command -v xterm
then
echo "TESTING: xterm x11 xorg"
./xterm-xorg.exp

which xpra 2>/dev/null
if [ "$?" -eq 0 ];
if command -v xpra
then
echo "TESTING: xterm x11 xpra"
./xterm-xpra.exp
fi

which Xephyr 2>/dev/null
if [ "$?" -eq 0 ];
if command -v Xephyr
then
echo "TESTING: xterm x11 xephyr"
./xterm-xephyr.exp
Expand All @@ -35,14 +32,12 @@ else
fi

# check xpra/xephyr
which xpra 2>/dev/null
if [ "$?" -eq 0 ];
if command -v xpra
then
echo "xpra found"
else
echo "xpra not found"
which Xephyr 2>/dev/null
if [ "$?" -eq 0 ];
if command -v Xephyr
then
echo "Xephyr found"
else
Expand All @@ -51,35 +46,31 @@ else
fi
fi

which firefox 2>/dev/null
if [ "$?" -eq 0 ];
if command -v firefox
then
echo "TESTING: firefox x11"
./firefox.exp
else
echo "TESTING SKIP: firefox not found"
fi

which chromium 2>/dev/null
if [ "$?" -eq 0 ];
if command -v chromium
then
echo "TESTING: chromium x11"
./chromium.exp
else
echo "TESTING SKIP: chromium not found"
fi

which transmission-gtk 2>/dev/null
if [ "$?" -eq 0 ];
if command -v transmission-gtk
then
echo "TESTING: transmission-gtk x11"
./transmission-gtk.exp
else
echo "TESTING SKIP: transmission-gtk not found"
fi

which thunderbird 2>/dev/null
if [ "$?" -eq 0 ];
if command -v thunderbird
then
echo "TESTING: thunderbird x11"
./thunderbird.exp
Expand Down
3 changes: 1 addition & 2 deletions test/apps/apps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ LIST="firefox midori chromium opera transmission-qt qbittorrent uget-gtk filezil
LIST+="vlc fbreader deluge gnome-mplayer xchat wine kcalc ktorrent hexchat"

for app in $LIST; do
which $app 2>/dev/null
if [ "$?" -eq 0 ];
if command -v "$app"
then
echo "TESTING: $app"
./$app.exp
Expand Down
9 changes: 3 additions & 6 deletions test/environment/environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ echo "TESTING: environment variables (test/environment/env.exp)"
echo "TESTING: firejail in firejail - single sandbox (test/environment/firejail-in-firejail.exp)"
./firejail-in-firejail.exp

which aplay 2>/dev/null
if [ "$?" -eq 0 ] && [ "$(aplay -l | grep -c "List of PLAYBACK")" -gt 0 ];
if command -v aplay && [ "$(aplay -l | grep -c "List of PLAYBACK")" -gt 0 ];
then
echo "TESTING: sound (test/environment/sound.exp)"
./sound.exp
Expand All @@ -54,8 +53,7 @@ echo "TESTING: nice (test/environment/nice.exp)"
echo "TESTING: quiet (test/environment/quiet.exp)"
./quiet.exp

which strace 2>/dev/null
if [ "$?" -eq 0 ];
if command -v strace
then
echo "TESTING: --allow-debuggers (test/environment/allow-debuggers.exp)"
./allow-debuggers.exp
Expand All @@ -67,8 +65,7 @@ fi
# $ sudo apt-get install ibus-table-array30
# $ ibus-setup

find ~/.config/ibus/bus | grep unix-0
if [ "$?" -eq 0 ];
if find ~/.config/ibus/bus | grep unix-0
then
echo "TESTING: ibus (test/environment/ibus.exp)"
./ibus.exp
Expand Down
3 changes: 1 addition & 2 deletions test/filters/filters.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ echo "TESTING: seccomp errno (test/filters/seccomp-errno.exp)"
echo "TESTING: seccomp su (test/filters/seccomp-su.exp)"
./seccomp-su.exp

which strace 2>/dev/null
if [ $? -eq 0 ]; then
if command -v strace; then
echo "TESTING: seccomp ptrace (test/filters/seccomp-ptrace.exp)"
./seccomp-ptrace.exp
else
Expand Down
15 changes: 5 additions & 10 deletions test/overlay/overlay.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,15 @@ rm -fr ~/_firejail_test_*
./fs-tmpfs.exp
rm -fr ~/_firejail_test_*

which firefox 2>/dev/null
if [ "$?" -eq 0 ];
if command -v firefox
then
echo "TESTING: overlay firefox"
./firefox.exp
else
echo "TESTING SKIP: firefox not found"
fi

which firefox 2>/dev/null
if [ "$?" -eq 0 ];
if command -v firefox
then
echo "TESTING: overlay firefox x11 xorg"
./firefox.exp
Expand All @@ -42,14 +40,12 @@ fi


# check xpra/xephyr
which xpra 2>/dev/null
if [ "$?" -eq 0 ];
if command -v xpra
then
echo "xpra found"
else
echo "xpra not found"
which Xephyr 2>/dev/null
if [ "$?" -eq 0 ];
if command -v Xephyr
then
echo "Xephyr found"
else
Expand All @@ -58,8 +54,7 @@ else
fi
fi

which firefox 2>/dev/null
if [ "$?" -eq 0 ];
if command -v firefox
then
echo "TESTING: overlay firefox x11"
./firefox-x11.exp
Expand Down
3 changes: 1 addition & 2 deletions test/private-lib/private-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ LIST="gnome-logs gnome-system-log gnome-nettool pavucontrol dig evince whois gal


for app in $LIST; do
which $app 2>/dev/null
if [ "$?" -eq 0 ];
if command -v "$app"
then
echo "TESTING: private-lib $app"
./$app.exp
Expand Down
3 changes: 1 addition & 2 deletions test/root/root.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ export LC_ALL=C
#********************************
# firecfg
#********************************
which less 2>/dev/null
if [ "$?" -eq 0 ];
if command -v less
then
echo "TESTING: firecfg (test/root/firecfg.exp)"
mv /home/netblue/.local/share/applications /home/netblue/.local/share/applications-store
Expand Down
27 changes: 9 additions & 18 deletions test/sysutils/sysutils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,80 +7,71 @@ export MALLOC_CHECK_=3
export MALLOC_PERTURB_=$(($RANDOM % 255 + 1))
export LC_ALL=C

which cpio 2>/dev/null
if [ "$?" -eq 0 ];
if command -v cpio
then
echo "TESTING: cpio"
./cpio.exp
else
echo "TESTING SKIP: cpio not found"
fi

#which strings
#if [ "$?" -eq 0 ];
#if command -v strings
#then
# echo "TESTING: strings"
# ./strings.exp
#else
# echo "TESTING SKIP: strings not found"
#fi

which gzip 2>/dev/null
if [ "$?" -eq 0 ];
if command -v gzip
then
echo "TESTING: gzip"
./gzip.exp
else
echo "TESTING SKIP: gzip not found"
fi

which xzdec 2>/dev/null
if [ "$?" -eq 0 ];
if command -v xzdec
then
echo "TESTING: xzdec"
./xzdec.exp
else
echo "TESTING SKIP: xzdec not found"
fi

which xz 2>/dev/null
if [ "$?" -eq 0 ];
if command -v xz
then
echo "TESTING: xz"
./xz.exp
else
echo "TESTING SKIP: xz not found"
fi

which less 2>/dev/null
if [ "$?" -eq 0 ];
if command -v less
then
echo "TESTING: less"
./less.exp
else
echo "TESTING SKIP: less not found"
fi

which file 2>/dev/null
if [ "$?" -eq 0 ];
if command -v file
then
echo "TESTING: file"
./file.exp
else
echo "TESTING SKIP: file not found"
fi

which tar 2>/dev/null
if [ "$?" -eq 0 ];
if command -v tar
then
echo "TESTING: tar"
./tar.exp
else
echo "TESTING SKIP: tar not found"
fi

which ping 2>/dev/null
if [ "$?" -eq 0 ];
if command -v ping
then
echo "TESTING: ping"
./ping.exp
Expand Down
3 changes: 1 addition & 2 deletions test/utils/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ echo "TESTING: version (test/utils/version.exp)"
echo "TESTING: help (test/utils/help.exp)"
./help.exp

which man 2>/dev/null
if [ "$?" -eq 0 ];
if command -v man
then
echo "TESTING: man (test/utils/man.exp)"
./man.exp
Expand Down

0 comments on commit e04d6b7

Please sign in to comment.