1
1
mirror of https://github.com/mgree/ffs.git synced 2024-09-11 19:17:40 +03:00
ffs/tests/newline_cleanup.sh
Michael Greenberg 4aff907523
Better mount control (issue #12; pr #24)
Mountpoints are typically inferred/generated from filenames with a -m/--mount flag for when reading from STDIN or to manually specify a mountpoint.
2021-06-24 07:06:38 -07:00

54 lines
1.1 KiB
Bash
Executable File

#!/bin/sh
fail() {
echo FAILED: $1
if [ "$MNT" ]
then
cd
umount "$MNT"
rmdir "$MNT"
rm -r "$EXP"
rm "$JSON"
fi
exit 1
}
MNT=$(mktemp -d)
EXP=$(mktemp -d)
JSON=$(mktemp)
# generate files w/newlines
printf "Michael Greenberg" >"${EXP}/name"
printf "2" >"${EXP}/eyes"
printf "10" >"${EXP}/fingernails"
printf "true" >"${EXP}/human"
printf "hi" >"${EXP}/greeting"
printf "bye" >"${EXP}/farewell"
ffs --newline -o "$JSON" -m "$MNT" ../json/object.json &
PID=$!
sleep 2
echo hi >"$MNT"/greeting
printf "bye" >"$MNT"/farewell
umount "$MNT" || fail unmount
sleep 1
kill -0 $PID >/dev/null 2>&1 && fail process
# remount w/o --newline, confirm that they're not there
ffs -m "$MNT" "$JSON" &
sleep 2
case $(ls "$MNT") in
(eyes*farewell*fingernails*greeting*human*name) ;;
(*) fail ls;;
esac
for x in "$EXP"/*
do
diff "$x" "$MNT/$(basename $x)" || fail "$(basename $x)"
done
umount "$MNT" || fail unmount
sleep 1
kill -0 $PID >/dev/null 2>&1 && fail process
rmdir "$MNT" || fail mount
rm -r "$EXP"