#
# recursion options test - recursion options should only apply to files that
#                          follow it
# ref: http://www.gnu.org/software/tar/manual/tar.html#SEC110
#

# setup

if ( ! test -d tree ); then mkdir tree; fi
if ( ! test -d tree/a ); then mkdir tree/a; fi
if ( ! test -d tree/b ); then mkdir tree/b; fi
touch tree/a/r{1,2,3} tree/b/p{1,2}

# test 01 - default recursion allowed, later disabled by --no-recursion

echo 'a/' > expected.tmp
echo 'a/r1' >> expected.tmp
echo 'a/r2' >> expected.tmp
echo 'a/r3' >> expected.tmp
echo 'b/' >> expected.tmp
cat expected.tmp | sort > expected
rm expected.tmp

tar --verbose --create --file tree.tar --directory tree \
  a --no-recursion b | sort > actual

if ( ! cmp expected actual > /dev/null ); then
  echo "01 FAILED"; else echo "01 OK"; fi

# test 02 - recursion disabled by default, later allowed by --recursion

echo 'a/' > expected.tmp
echo 'b/' >> expected.tmp
echo 'b/p1' >> expected.tmp
echo 'b/p2' >> expected.tmp
cat expected.tmp | sort > expected
rm expected.tmp

tar --verbose --create --file tree.tar --directory tree \
  --no-recursion a --recursion b | sort > actual

if ( ! cmp expected actual > /dev/null ); then
  echo "02 FAILED"; else echo "02 OK"; fi

