Skip to content

Commit

Permalink
fix shellcheck in test cases
Browse files Browse the repository at this point in the history
enable shellcheck tests for these files in do_shellcheck.sh

Signed-off-by: Robert Marklund <[email protected]>
  • Loading branch information
trollkarlen authored and pauldreik committed Jan 24, 2025
1 parent 46bc68f commit 6ac64fa
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 122 deletions.
3 changes: 1 addition & 2 deletions do_shellcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ echo "$me: run shellcheck on shellscripts"

echo "$me: run shellcheck on testcases"
(
# use this when all issues are fixed
# cd testcases && git ls-files | grep -E ".sh$" | xargs shellcheck -x
cd testcases && git ls-files | grep -E ".sh$" | xargs shellcheck -x
)

6 changes: 3 additions & 3 deletions testcases/checksum_options.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ for checksumtype in $allchecksumtypes; do
dbgecho "trying checksum $checksumtype with small files"
echo checksumtest >a
echo checksumtest >b
$rdfind -checksum $checksumtype -deleteduplicates true a b
$rdfind -checksum "$checksumtype" -deleteduplicates true a b
[ -e a ]
[ ! -e b ]
done
Expand All @@ -25,7 +25,7 @@ for checksumtype in $allchecksumtypes; do
dbgecho "trying checksum $checksumtype with large files"
head -c 1000000 /dev/zero >a
head -c 1000000 /dev/zero >b
$rdfind -checksum $checksumtype -deleteduplicates true a b
$rdfind -checksum "$checksumtype" -deleteduplicates true a b
[ -e a ]
[ ! -e b ]
done
Expand All @@ -35,7 +35,7 @@ for checksumtype in $allchecksumtypes; do
dbgecho "trying checksum $checksumtype with large files that differ only in the middle"
( head -c 1000000 /dev/zero; echo =====a=====; head -c 1000000 /dev/zero) >a
( head -c 1000000 /dev/zero; echo =====b=====; head -c 1000000 /dev/zero) >b
$rdfind -checksum $checksumtype -deleteduplicates true a b
$rdfind -checksum "$checksumtype" -deleteduplicates true a b
[ -e a ]
[ -e b ]
done
Expand Down
36 changes: 19 additions & 17 deletions testcases/common_funcs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
#bail out on the first error
set -e

me=$(basename $0)
me="$(basename "$0")"


# shellcheck disable=SC3037
/bin/echo -n "$me: checking for rdfind ..."
rdfind=$PWD/rdfind
if [ ! -x "$rdfind" ]; then
Expand All @@ -17,8 +18,8 @@ if [ ! -x "$rdfind" ]; then
fi
echo " OK."

/bin/echo -n "checking for valgrind ..."
if [ -z $VALGRIND ] ; then
printf "checking for valgrind ..."
if [ -z "$VALGRIND" ] ; then
echo "not used."
else
echo "active! here is the command: $VALGRIND"
Expand All @@ -27,15 +28,15 @@ fi
rdfind="$VALGRIND $rdfind"

#where is the test scripts dir?
testscriptsdir=$(dirname $(readlink -f $0))

testscriptsdir="$(dirname "$(readlink -f "$0")")"
export testscriptsdir

dbgecho() {
echo "$0 debug: " "$@"
}


echo -n "checking for mktemp ..."
printf "checking for mktemp ..."
which mktemp >/dev/null
echo " OK."

Expand All @@ -52,39 +53,40 @@ cleanup () {
rm -rf "$datadir"
}

if [ -z $KEEPTEMPDIR ] ; then
if [ -z "$KEEPTEMPDIR" ] ; then
trap cleanup INT QUIT EXIT
fi

[ -d $datadir ]
cd $datadir
[ -d "$datadir" ]
cd "$datadir"

reset_teststate() {
cd /
rm -rf "$datadir"
mkdir -p $datadir
mkdir -p "$datadir"
cd "$datadir"
}


verify() {
if ! $@ ; then
echo "failed asserting $@"
if ! "$@" ; then
echo "failed asserting $*"
exit 1
fi
}

# where to mount disorderfs for the determinism tests
DISORDERED_MNT=$datadir/disordered_mnt
DISORDERED_ROOT=$datadir/disordered_root
DISORDERED_MNT="$datadir/disordered_mnt"
DISORDERED_ROOT="$datadir/disordered_root"

# do we have a working disorder fs?
hasdisorderfs=false
if which disorderfs fusermount >/dev/null 2>&1; then
mkdir -p $DISORDERED_MNT $DISORDERED_ROOT
if disorderfs $DISORDERED_ROOT $DISORDERED_MNT >/dev/null 2>&1 ; then
mkdir -p "$DISORDERED_MNT" "$DISORDERED_ROOT"
if disorderfs "$DISORDERED_ROOT" "$DISORDERED_MNT" >/dev/null 2>&1 ; then
# "Sälj inte skinnet förrän björnen är skjuten - Don't count your chickens until they're hatched"
fusermount -z -u $DISORDERED_MNT
fusermount -z -u "$DISORDERED_MNT"
hasdisorderfs=true
fi
fi
export hasdisorderfs
24 changes: 12 additions & 12 deletions testcases/hardlink_fails.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ reset_teststate
files="a subdir/b c some/deeply/nested/subdir/d"
nfiles=4
for n in $files ; do
mkdir -p $(dirname $datadir/$n)
echo "hello hardlink" > $datadir/$n
mkdir -p "$(dirname "$datadir/$n")"
echo "hello hardlink" > "$datadir/$n"
done

#eliminate them.
$rdfind -makehardlinks true $datadir/
$rdfind -makehardlinks true "$datadir/"

#make sure one is a hard link to the other.
for n in $files ; do
nhardlinks=$(stat -c %h $datadir/$n)
if [ $nhardlinks -ne $nfiles ] ; then
nhardlinks=$(stat -c %h "$datadir/$n")
if [ "$nhardlinks" -ne "$nfiles" ] ; then
dbgecho "expected $nfiles hardlinks, got $nhardlinks"
exit 1
fi
Expand All @@ -33,10 +33,10 @@ dbgecho passed the happy path
# try to make a hardlink to somewhere that fails.

reset_teststate
mkdir -p $datadir/readonly.d/
echo xxx > $datadir/readonly.d/a
echo xxx > $datadir/readonly.d/b
chmod 500 $datadir/readonly.d/
mkdir -p "$datadir/readonly.d/"
echo xxx > "$datadir/readonly.d/a"
echo xxx > "$datadir/readonly.d/b"
chmod 500 "$datadir/readonly.d/"

if [ "$(id -u)" -eq 0 ]; then
# if running as root, directory rights are not respected. drop the capability
Expand All @@ -53,13 +53,13 @@ fi

#make sure that our own copy is still there
for f in a b ; do
if [ ! -e $datadir/readonly.d/$f ] ; then
dbgecho file $f is missing, rdfind should not have removed it!
if [ ! -e "$datadir/readonly.d/$f" ] ; then
dbgecho "file $f is missing, rdfind should not have removed it!"
exit 1
fi
done

# make sure it can be cleaned up
chmod 700 $datadir/readonly.d/
chmod 700 "$datadir/readonly.d/"

dbgecho "all is good in this test!"
2 changes: 1 addition & 1 deletion testcases/largefilesupport.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ reset_teststate

#create a large file, sparse.
filesizem1=2147483647 #size, in bytes. This is no problem.
filesize=$(($filesizem1+1)) #size, in bytes. This is a problematic value.
filesize=$((filesizem1+1)) #size, in bytes. This is a problematic value.

#below, dd is used and the file is later appended to, to avoid problems
#on Hurd which currently (20130619) can not take $filesize as argument to
Expand Down
2 changes: 1 addition & 1 deletion testcases/md5collisions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ reset_teststate

#check md5 collision files
mkdir md5coll
cp $testscriptsdir/md5collisions/*.ps md5coll
cp "$testscriptsdir/md5collisions/"*.ps md5coll
sync

#make sure nothing happens when using sha
Expand Down
2 changes: 1 addition & 1 deletion testcases/sha1collisions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ set -e
reset_teststate

#unpack collisions example from https://shattered.it/static/shattered.pdf
base64 --decode <$testscriptsdir/sha1collisions/coll.tar.bz2.b64 |tar xvfj -
base64 --decode <"$testscriptsdir/sha1collisions/coll.tar.bz2.b64" | tar xvfj -

#make sure nothing happens when using sha256
$rdfind -checksum sha256 -deleteduplicates true . 2>&1 |tee rdfind.out
Expand Down
49 changes: 24 additions & 25 deletions testcases/symlinking_action.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@ reset_teststate

#make identical files.
files="first subdir/b c some/deeply/nested/subdir/d"
nfiles=4
for n in $files ; do
mkdir -p $(dirname $datadir/$n)
echo "hello symlink" > $datadir/$n
mkdir -p "$(dirname "$datadir/$n")"
echo "hello symlink" > "$datadir/$n"
done

#eliminate them.
$rdfind -makesymlinks true $datadir/first $datadir/
$rdfind -makesymlinks true "$datadir/first" "$datadir/"

#make sure the first one is untouched (it has the highest rank), and the rest are symlinks.
export LANG=

for n in $files ; do
if [ $n = "first" ]; then
if [ "$n" = "first" ]; then
inodeforfirst=$(stat -c %i "$datadir/first")
if [ x"$(stat -c %F "$datadir/first")" != x"regular file" ] ; then
dbgecho "expected first to be a regular file"
Expand All @@ -35,7 +34,7 @@ for n in $files ; do
exit 1
fi
inodeforn=$(stat --dereference -c %i "$datadir/$n")
if [ $inodeforfirst != $inodeforn ] ; then
if [ "$inodeforfirst" != "$inodeforn" ] ; then
dbgecho "$n does not refer to first - inode mismatch $inodeforfirst vs $inodeforn"
exit 1
fi
Expand All @@ -47,10 +46,10 @@ dbgecho passed the happy path
# try to make a symlink somewhere where it fails.

reset_teststate
mkdir -p $datadir/readonly.d/
echo xxx > $datadir/readonly.d/a
echo xxx > $datadir/readonly.d/b
chmod 500 $datadir/readonly.d/
mkdir -p "$datadir/readonly.d/"
echo xxx > "$datadir/readonly.d/a"
echo xxx > "$datadir/readonly.d/b"
chmod 500 "$datadir/readonly.d/"

if [ "$(id -u)" -eq 0 ]; then
# if running as root, directory rights are not respected. drop the capability
Expand All @@ -67,16 +66,16 @@ fi

# make sure that our own copy is still there
for f in a b ; do
if [ ! -e $datadir/readonly.d/$f ] ; then
dbgecho file $f is missing, rdfind should not have removed it!
if [ ! -e "$datadir/readonly.d/$f" ] ; then
dbgecho "file $f is missing, rdfind should not have removed it!"
exit 1
fi
done

# make sure it can be cleaned up
chmod 700 $datadir/readonly.d/
chmod 700 "$datadir/readonly.d/"

dbgecho passed the test with trying to write to a readonly directory
dbgecho "passed the test with trying to write to a readonly directory"



Expand All @@ -85,13 +84,13 @@ dbgecho passed the test with trying to write to a readonly directory
# argument 1 is path to file 1. argument 2 is path to file 2.
pathsimplification() {
reset_teststate
mkdir -p $(dirname $1) && echo "simplification test" >$1
mkdir -p $(dirname $2) && echo "simplification test" >$2
mkdir -p "$(dirname "$1")" && echo "simplification test" >"$1"
mkdir -p "$(dirname "$2")" && echo "simplification test" >"$2"

#dbgecho "state before (args $1 $2)"
#tree

$rdfind -makesymlinks true $1 $2 2>&1 |tee rdfind.out
$rdfind -makesymlinks true "$1" "$2" 2>&1 |tee rdfind.out
# $2 should be a symlink to $1
if [ x"$(stat -c %F "$1")" != x"regular file" ] ; then
dbgecho "expected file $1 to be a regular file"
Expand All @@ -103,14 +102,14 @@ pathsimplification() {
fi
inodefor1=$(stat -c %i "$1")
inodefor2=$(stat --dereference -c %i "$2")
if [ $inodefor1 != $inodefor2 ] ; then
if [ "$inodefor1" != "$inodefor2" ] ; then
dbgecho "inode mismatch $inodefor1 vs $inodefor2"
exit 1
fi
#switching directory should still give the correct answer
cd $(dirname $2)
inodefor2=$(stat --dereference -c %i $(basename "$2"))
if [ $inodefor1 != $inodefor2 ] ; then
cd "$(dirname "$2")"
inodefor2="$(stat --dereference -c %i "$(basename "$2")")"
if [ "$inodefor1" != "$inodefor2" ] ; then
dbgecho "inode mismatch $inodefor1 vs $inodefor2"
exit 1
fi
Expand All @@ -128,10 +127,10 @@ pathsimplification subdir1/../a subdir2/b
pathsimplification subdir1/../a subdir2/./././b
pathsimplification subdir2/./././b subdir1/../a
pathsimplification a subdir2/./././b
pathsimplification $(pwd)/a b
pathsimplification a $(pwd)/b
pathsimplification $(pwd)/a $(pwd)/b
pathsimplification $(pwd)/subdir/../a $(pwd)/b
pathsimplification "$(pwd)/a" b
pathsimplification a "$(pwd)/b"
pathsimplification "$(pwd)/a" "$(pwd)/b"
pathsimplification "$(pwd)/subdir/../a" "$(pwd)/b"
pathsimplification ./a b
pathsimplification ./a ./b
pathsimplification a ./b
Expand Down
Loading

0 comments on commit 6ac64fa

Please sign in to comment.