test-sysusers: fix how paths are calculated

We were looking at ${f%.*}, i.e. the $f with any suffix starting with a dot removed.
This worked fine for paths like /some/path/test-11.input. It also worked
for paths like /some/path/inline (there were no dots, so we got $f back unscathed).
But in the ubuntu CI the package is built in a temporary directory like
/tmp/autopkgtest-lxc.nnnfqb26/downtmp/build.UfW/ (yes, it has a dot, even two.).
That still worked for the first case, but in the second case we truncated things
after the first dot, and we would try to get
/tmp/autopkgtest-lxc.nnnfqb26/downtmp/build and try to load
/tmp/autopkgtest-lxc.nnnfqb26/downtmp/build.expected-password, which obviously
didn't work as expected. To avoid this issue, do the suffix removal only when
we know that there really is a suffix.

A second minor issue was that we would try to copy $1.expected-*, and sometimes
$1 would be given, and sometimes not. Effectively we were relying on there
not being any files matching .expected-*. There weren't any such files, but let's
avoid this ugliness and always pass $1.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2020-10-01 14:16:46 +02:00
parent 69a7c5fb1f
commit 044df624aa

View file

@ -27,12 +27,12 @@ preprocess() {
} }
compare() { compare() {
if ! diff -u $TESTDIR/etc/passwd <(preprocess ${1%.*}.expected-passwd); then if ! diff -u $TESTDIR/etc/passwd <(preprocess $1.expected-passwd); then
echo "**** Unexpected output for $f" echo "**** Unexpected output for $f $2"
exit 1 exit 1
fi fi
if ! diff -u $TESTDIR/etc/group <(preprocess ${1%.*}.expected-group); then if ! diff -u $TESTDIR/etc/group <(preprocess $1.expected-group); then
echo "**** Unexpected output for $f $2" echo "**** Unexpected output for $f $2"
exit 1 exit 1
fi fi
@ -47,7 +47,7 @@ for f in $(ls -1 $SOURCE/test-*.input | sort -V); do
cp $f $TESTDIR/usr/lib/sysusers.d/test.conf cp $f $TESTDIR/usr/lib/sysusers.d/test.conf
$SYSUSERS --root=$TESTDIR $SYSUSERS --root=$TESTDIR
compare $f "" compare ${f%.*} ""
done done
for f in $(ls -1 $SOURCE/test-*.input | sort -V); do for f in $(ls -1 $SOURCE/test-*.input | sort -V); do
@ -56,7 +56,7 @@ for f in $(ls -1 $SOURCE/test-*.input | sort -V); do
touch $TESTDIR/etc/sysusers.d/test.conf touch $TESTDIR/etc/sysusers.d/test.conf
cat $f | $SYSUSERS --root=$TESTDIR - cat $f | $SYSUSERS --root=$TESTDIR -
compare $f "on stdin" compare ${f%.*} "on stdin"
done done
for f in $(ls -1 $SOURCE/test-*.input | sort -V); do for f in $(ls -1 $SOURCE/test-*.input | sort -V); do
@ -68,12 +68,12 @@ for f in $(ls -1 $SOURCE/test-*.input | sort -V); do
# this should be ignored # this should be ignored
cat $SOURCE/test-1.input | $SYSUSERS --root=$TESTDIR --replace=/usr/lib/sysusers.d/test.conf - cat $SOURCE/test-1.input | $SYSUSERS --root=$TESTDIR --replace=/usr/lib/sysusers.d/test.conf -
compare $f "on stdin with --replace" compare ${f%.*} "on stdin with --replace"
done done
# test --inline # test --inline
echo "*** Testing --inline" echo "*** Testing --inline"
prepare_testdir prepare_testdir $SOURCE/inline
# copy a random file to make sure it is ignored # copy a random file to make sure it is ignored
cp $f $TESTDIR/etc/sysusers.d/confuse.conf cp $f $TESTDIR/etc/sysusers.d/confuse.conf
$SYSUSERS --root=$TESTDIR --inline \ $SYSUSERS --root=$TESTDIR --inline \
@ -84,7 +84,7 @@ compare $SOURCE/inline "(--inline)"
# test --replace # test --replace
echo "*** Testing --inline with --replace" echo "*** Testing --inline with --replace"
prepare_testdir prepare_testdir $SOURCE/inline
# copy a random file to make sure it is ignored # copy a random file to make sure it is ignored
cp $f $TESTDIR/etc/sysusers.d/confuse.conf cp $f $TESTDIR/etc/sysusers.d/confuse.conf
$SYSUSERS --root=$TESTDIR \ $SYSUSERS --root=$TESTDIR \