toybox/tests/id.test
<<
>>
Prefs
   1#!/bin/bash
   2
   3[ -f testing.sh ] && . testing.sh
   4
   5#testing "name" "command" "result" "infile" "stdin"
   6
   7# Systems with SELinux will have security context cruft,
   8# BSDs call the root group "wheel" instead,
   9# and Raspberry Pi OS has root also in the 117(lpadmin) group.
  10CLEAN="sed 's/ context=.*//g' | sed 's/wheel/root/g' | \
  11sed 's/117//g' | sed -E 's/\(?lpadmin\)?//g' | sed 's/[ ,]$//'"
  12
  13testing "0" "id 0 | $CLEAN" "uid=0(root) gid=0(root) groups=0(root)\n" "" ""
  14testing "root" "id root | $CLEAN" \
  15  "uid=0(root) gid=0(root) groups=0(root)\n" "" ""
  16testing "-G root" "id -G root | $CLEAN" "0\n" "" ""
  17testing "-nG root" "id -nG root | $CLEAN" "root\n" "" ""
  18testing "-g root" "id -g root" "0\n" "" ""
  19testing "-ng root" "id -ng root | $CLEAN" "root\n" "" ""
  20testing "-u root" "id -u root" "0\n" "" ""
  21testing "-nu root" "id -nu root" "root\n" "" ""
  22testing "no-such-user" "id no-such-user 2>/dev/null ; echo \$?" "1\n" "" ""
  23testing "2147483647" "id 2147483647 2>/dev/null ; echo \$?" "1\n" "" ""
  24