1
1
mirror of https://github.com/mgree/ffs.git synced 2024-10-05 15:18:20 +03:00
ffs/tests/pretty_json.sh
Michael Greenberg 7249ae95df
Pretty printing (#35)
Add --pretty flag, tests, docs.

Resolves #33.
2021-07-03 16:40:01 -07:00

32 lines
530 B
Bash
Executable File

#!/bin/sh
fail() {
echo FAILED: $1
if [ "$MNT" ]
then
umount "$MNT"
rmdir "$MNT"
rm "$OUT"
fi
exit 1
}
MNT=$(mktemp -d)
OUT=$(mktemp)
ffs -m "$MNT" --target json -o "$OUT" --pretty ../json/object.json &
PID=$!
sleep 2
echo mgree >"$MNT"/handle
umount "$MNT" || fail unmount
sleep 1
kill -0 $PID >/dev/null 2>&1 && fail process
[ "$(cat $OUT | wc -l)" -eq 6 ] || fail lines
grep '^\s*"handle": "mgree",$' "$OUT" >/dev/null 2>&1 || fail handle
rmdir "$MNT" || fail mount
rm "$OUT"