toybox/tests/chown.test
<<
>>
Prefs
   1#!/bin/bash
   2
   3[ -f testing.sh ] && . testing.sh
   4
   5if [ "$(id -u)" -ne 0 ]
   6then
   7  echo "$SHOWSKIP: chown (not root)"
   8  continue 2>/dev/null
   9  exit
  10fi
  11
  12# We chown between user "root" and the last user in /etc/passwd,
  13# and group "root" and the last group in /etc/group.
  14
  15USR="$(sed -n '$s/:.*//p' /etc/passwd)"
  16GRP="$(sed -n '$s/:.*//p' /etc/group)"
  17
  18# Set up a little testing hierarchy
  19
  20rm -rf testdir &&
  21mkdir testdir &&
  22touch testdir/file
  23F=testdir/file
  24
  25# Wrapper to reset groups and return results
  26
  27OUT="&& echo \$(ls -l testdir/file | awk '{print \$3,\$4}')"
  28
  29#testing "name" "command" "result" "infile" "stdin"
  30
  31# Basic smoketest
  32testing "initial" "chown root:root $F $OUT" "root root\n" "" ""
  33testing "usr:grp" "chown $USR:$GRP $F $OUT" "$USR $GRP\n" "" ""
  34testing "root"    "chown root $F $OUT" "root $GRP\n" "" ""
  35# TODO: can we test "owner:"?
  36testing ":grp"    "chown root:root $F && chown :$GRP $F $OUT" \
  37    "root $GRP\n" "" ""
  38testing ":"       "chown $USR:$GRP $F && chown : $F $OUT" \
  39    "$USR $GRP\n" "" ""
  40
  41rm -rf testdir
  42