summaryrefslogtreecommitdiffstats
path: root/debian/tests/pgrep
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--debian/tests/pgrep56
1 files changed, 56 insertions, 0 deletions
diff --git a/debian/tests/pgrep b/debian/tests/pgrep
new file mode 100644
index 0000000..d39400e
--- /dev/null
+++ b/debian/tests/pgrep
@@ -0,0 +1,56 @@
+#!/bin/sh
+
+exec 2>&1
+
+test_no_arguments() {
+ ( pgrep >"${stdoutF}" 2>"${stderrF}" )
+ rtrn=$?
+
+ assertEquals "pgrep exit value" "2" "${rtrn}"
+ grep -E '^pgrep: no matching criteria specified' "${stderrF}" > /dev/null
+ assertTrue 'no matching line' $?
+}
+
+test_count() {
+ ( pgrep -c "$fakeproc}" >"${stdoutF}" 2>"${stderrF}" )
+ rtrn=$?
+
+ assertEquals "pgrep -c exit value" "1" "${rtrn}"
+ grep '^0$' "${stderrF}" > /dev/null
+ assertFalse 'count 0 of missing process' $?
+}
+
+test_user_procs() {
+ myUID=$(awk '$1 == "Uid:" { print $2}' "/proc/${myPID}/status" 2>/dev/null)
+ if [ -z "${myUID:-}" ];then
+ startSkipping
+ myUID=0
+ fi
+
+ ( pgrep -u "${myUID}" >"${stdoutF}" 2>"${stderrF}" )
+ rtrn=$?
+
+ assertEquals "pgrep exit value" "0" "${rtrn}"
+
+ grep "^${myPID}$" "${stderrF}" > /dev/null
+ assertFalse "User ${myUID} doesn't match PID ${myPID}" $?
+}
+
+oneTimeSetUp() {
+ # Define global variables for command output.
+ stdoutF="${AUTOPKGTEST_TMP}/stdout"
+ stderrF="${AUTOPKGTEST_TMP}/stderr"
+ fakeproc='fakename-test'
+ myPID=$$
+}
+
+setUp() {
+ # Truncate the output files.
+ cp /dev/null "${stdoutF}"
+ cp /dev/null "${stderrF}"
+}
+
+
+# shellcheck disable=SC1091
+. shunit2
+