mirror of
https://github.com/mgree/ffs.git
synced 2024-10-26 20:09:03 +03:00
better handling of newlines, tests
This commit is contained in:
parent
66c6fbeb0b
commit
8345d510f4
@ -181,7 +181,7 @@ pub fn value_from_fs(fs: &FS, inum: u64) -> Value {
|
||||
// TODO 2021-06-16 better newline handling
|
||||
let contents = match String::from_utf8(contents.clone()) {
|
||||
Ok(mut contents) => {
|
||||
if contents.ends_with('\n') {
|
||||
if fs.config.add_newlines && contents.ends_with('\n') {
|
||||
contents.truncate(contents.len() - 1);
|
||||
}
|
||||
contents
|
||||
|
53
tests/exact_cleanup.sh
Executable file
53
tests/exact_cleanup.sh
Executable file
@ -0,0 +1,53 @@
|
||||
#!/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\n" >"${EXP}/greeting"
|
||||
printf "bye" >"${EXP}/farewell"
|
||||
|
||||
ffs -o "$JSON" "$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 (except for greeting)
|
||||
ffs "$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"
|
53
tests/newline_cleanup.sh
Executable file
53
tests/newline_cleanup.sh
Executable file
@ -0,0 +1,53 @@
|
||||
#!/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" "$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 "$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"
|
Loading…
Reference in New Issue
Block a user