From f9a448aeb871aa17708d3909dfd7ad013e418126 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 31 Jan 2020 14:07:31 -0800 Subject: lsattr.test: clean up and fix. My previous attempt to fix this worked for ext-with-extents on the desktop, but not for f2fs-with-encryption on cloud Android devices. This feels quite a bit cleaner, and has the benefit of actually working everywhere I've tried it. I've also added perfunctory testing of -p too, which was missing before. --- tests/lsattr.test | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/tests/lsattr.test b/tests/lsattr.test index 7a7256b7..bbb21dcf 100644 --- a/tests/lsattr.test +++ b/tests/lsattr.test @@ -4,28 +4,37 @@ #testing "name" "command" "result" "infile" "stdin" -# We don't know whether the fs will have extents (e, typically true on the -# desktop) or be encrypted (E, typically true on Android), so ask. -# Unfortunately, this requires that we trust lsattr... mkdir dir && cd dir && touch file -_b=$(lsattr -d . | awk '{print $1}') -_A=$(lsattr file | sed 's/^--------/-------A/' | awk '{print $1}') -attrs="No_Atime" -lsattr -d . | grep -q e && attrs="$attrs, Extents" -lsattr -d . | grep -q E && attrs="$attrs, Encrypted" chattr +A file &>/dev/null +_A='-------A------------' +_d='--------------------' -testing "file" "lsattr file" "$_A file\n" "" "" -testing "-R file" "lsattr -R file" "$_A file\n" "" "" -testing "-a file" "lsattr -a file" "$_A file\n" "" "" -testing "-d ." "lsattr -d ." "$_b .\n" "" "" -testing "-d file" "lsattr -d file" "$_A file\n" "" "" -NOSPACE=1 testing "-l file" "lsattr -l file" "file $attrs\n" "" "" -NOSPACE=1 testing "-v file" "lsattr -v file | sed 's/^[0-9]*/_/'" \ - "_ $_A file\n" "" "" -NOSPACE=1 testing "-lv file" "lsattr -lv file | sed 's/^[0-9]*/_/'" \ - "_ file $attrs\n" "" "" +function clean() +{ + # We don't know whether the fs will have extents (e, typically true on the + # desktop) or be encrypted (E, typically true on Android), so strip out both + # the long and short forms of those. + # We also don't want to rely on chattr(1) to set a known version number or + # project number, so blank out any numbers. + sed 's/, Encrypted//' | \ + sed 's/-E-/---/' | \ + sed 's/, Extents//' | \ + sed 's/-e-/---/' | \ + sed -E 's/[0-9]+/_/g' +} + +testing "file" "lsattr file | clean" "$_A file\n" "" "" +testing "-R file" "lsattr -R file | clean" "$_A file\n" "" "" +testing "-a file" "lsattr -a file | clean" "$_A file\n" "" "" +testing "-d ." "lsattr -d . | clean" "$_d .\n" "" "" +testing "-d file" "lsattr -d file | clean" "$_A file\n" "" "" +NOSPACE=1 testing "-l file" "lsattr -l file | clean" "file No_Atime\n" "" "" +NOSPACE=1 testing "-v file" "lsattr -v file | clean" "_ $_A file\n" "" "" +NOSPACE=1 testing "-lv file" "lsattr -lv file | clean" "_ file No_Atime\n" "" "" +NOSPACE=1 testing "-p file" "lsattr -p file | clean" "_ $_A file\n" "" "" +NOSPACE=1 testing "-lp file" "lsattr -lp file | clean" "_ file No_Atime\n" "" "" +NOSPACE=1 testing "-vp file" "lsattr -vp file | clean" "_ _ $_A file\n" "" "" chattr -AacDdijsStTu file && cd .. rm -rf dir -- cgit v1.2.3