aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2020-01-31 14:07:31 -0800
committerRob Landley <rob@landley.net>2020-01-31 21:04:15 -0600
commitf9a448aeb871aa17708d3909dfd7ad013e418126 (patch)
treedc129357a9a18060edef41cc8729207034476840
parent2b729ee1e0cb266bf50df0ca80f123f93384ac77 (diff)
downloadtoybox-f9a448aeb871aa17708d3909dfd7ad013e418126.tar.gz
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.
-rw-r--r--tests/lsattr.test45
1 files 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