Debian Codegraph @

debian/tests/pgrep

raw
1 #!/bin/sh
2
3 exec 2>&1
4
5 test_no_arguments() {
6 ( pgrep >"${stdoutF}" 2>"${stderrF}" )
7 rtrn=$?
8
9 assertEquals "pgrep exit value" "2" "${rtrn}"
10 grep -E '^pgrep: no matching criteria specified' "${stderrF}" > /dev/null
11 assertTrue 'no matching line' $?
12 }
13
14 test_count() {
15 ( pgrep -c "$fakeproc}" >"${stdoutF}" 2>"${stderrF}" )
16 rtrn=$?
17
18 assertEquals "pgrep -c exit value" "1" "${rtrn}"
19 grep '^0$' "${stderrF}" > /dev/null
20 assertFalse 'count 0 of missing process' $?
21 }
22
23 test_user_procs() {
24 myUID=$(awk '$1 == "Uid:" { print $2}' "/proc/${myPID}/status" 2>/dev/null)
25 if [ -z "${myUID:-}" ];then
26 startSkipping
27 myUID=0
28 fi
29
30 ( pgrep -u "${myUID}" >"${stdoutF}" 2>"${stderrF}" )
31 rtrn=$?
32
33 assertEquals "pgrep exit value" "0" "${rtrn}"
34
35 grep "^${myPID}$" "${stderrF}" > /dev/null
36 assertFalse "User ${myUID} doesn't match PID ${myPID}" $?
37 }
38
39 oneTimeSetUp() {
40 # Define global variables for command output.
41 stdoutF="${AUTOPKGTEST_TMP}/stdout"
42 stderrF="${AUTOPKGTEST_TMP}/stderr"
43 fakeproc='fakename-test'
44 myPID=$$
45 }
46
47 setUp() {
48 # Truncate the output files.
49 cp /dev/null "${stdoutF}"
50 cp /dev/null "${stderrF}"
51 }
52
53
54 # shellcheck disable=SC1091
55 . shunit2
56