view tests/chown.test @ 1656:88e6a100490e draft

i found a few problems while manually smoke testing toybox chown versus toolbox (NetBSD) chown... new test: and here's the patch to fix "owner:" ":group" and the ":" special case:
author Elliott Hughes <>
date Wed, 14 Jan 2015 03:43:49 -0600
line wrap: on
line source


[ -f ] && .

if [ "$(id -u)" -ne 0 ]
  echo "SKIPPED: chown (not root)"
  continue 2>/dev/null

# We chown between user "root" and the last user in /etc/passwd,
# and group "root" and the last group in /etc/group.

USR="$(sed -n '$s/:.*//p' /etc/passwd)"
GRP="$(sed -n '$s/:.*//p' /etc/group)"

# Set up a little testing hierarchy

rm -rf testdir &&
mkdir testdir &&
touch testdir/file

# Wrapper to reset groups and return results

OUT="&& echo \$(ls -l testdir/file | awk '{print \$3,\$4}')"

#testing "name" "command" "result" "infile" "stdin"

# Basic smoketest
testing "chown initial" "chown root:root $F $OUT" "root root\n" "" ""
testing "chown usr:grp" "chown $USR:$GRP $F $OUT" "$USR $GRP\n" "" ""
testing "chown root"    "chown root $F $OUT" "root $GRP\n" "" ""
# TODO: can we test "owner:"?
testing "chown :grp"    "chown root:root $F && chown :$GRP $F $OUT" \
    "root $GRP\n" "" ""
testing "chown :"       "chown $USR:$GRP $F && chown : $F $OUT" \
    "$USR $GRP\n" "" ""

rm -rf testdir