aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2019-11-02 22:58:42 -0700
committerRob Landley <rob@landley.net>2019-11-03 19:20:31 -0600
commit126c317d5ceee7802d52fc6be1b695f759aa6725 (patch)
tree6e7e0e35dcf9171b5eb34aa2c9e6fa3e6c9c772b /tests
parent3ead70e503b2809a250a70d161d525213f5328d8 (diff)
downloadtoybox-126c317d5ceee7802d52fc6be1b695f759aa6725.tar.gz
id: support numeric lookup.
Fall back to converting the "name" to an integer and calling getpwuid(). We need to update `username` for the later call to getgrouplist(). Also fix the separator printing logic to avoid a trailing ',' on `id 0`. Switch to FLAG() and move some declarations down to where they can be initialized, both for clarity. Also add simple tests. Sadly, there's no always-present user that is in multiple groups.
Diffstat (limited to 'tests')
-rwxr-xr-xtests/id.test10
1 files changed, 10 insertions, 0 deletions
diff --git a/tests/id.test b/tests/id.test
new file mode 100755
index 00000000..6d0f63a8
--- /dev/null
+++ b/tests/id.test
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+[ -f testing.sh ] && . testing.sh
+
+#testing "name" "command" "result" "infile" "stdin"
+
+testing "id 0" "id 0" "uid=0(root) gid=0(root) groups=0(root)\n" "" ""
+testing "id root" "id root" "uid=0(root) gid=0(root) groups=0(root)\n" "" ""
+testing "id no-such-user" "id no-such-user 2>/dev/null ; echo \$?" "1\n" "" ""
+testing "id 9999999" "id 9999999 2>/dev/null ; echo \$?" "1\n" "" ""