summaryrefslogtreecommitdiffstats
path: root/debian/tests/fuser
blob: bf18235316da638510bf9982252409752390982a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/sh

exec 2>&1

test_no_arguments() {
    ( fuser >"${stdoutF}" 2>"${stderrF}" )
    rtrn=$?

    assertEquals "fuser exit value" "1" "${rtrn}"
    grep -E '^No process specification given$' "${stderrF}" > /dev/null
    assertTrue 'error message' $?
}

test_no_process() {
    ( fuser "${testF}" >"${stdoutF}" 2>"${stderrF}" )
    rtrn=$?

    assertEquals "fuser exit value" "1" "${rtrn}"
    assertFalse "unexpected output to stderr" "[ -s '${stderrF}' ]"
}

test_a_no_process() {
    ( fuser -a "${testF}" >"${stdoutF}" 2>"${stderrF}" )
    rtrn=$?

    assertEquals "fuser exit value" "1" "${rtrn}"
    grep -qE "^${testF}:$" "${stderrF}"
    assertTrue 'File matches no process' $?
}

test_my_cwd() {
    myCWD=$(readlink "/proc/${myPID}/cwd" )
    ( fuser "${myCWD}" >"${stdoutF}" 2>"${stderrF}" )
    rtrn=$?

    assertEquals "fuser exit value" "0" "${rtrn}"
    grep -qE "${myPID}" "${stdoutF}"
    assertTrue 'STDOUT has my PID' $?
    grep -qE "^${myCWD}:.*c" "${stderrF}"
    assertTrue 'STDERR has my path and c' $?
}

test_my_exe() {
    myEXE=$(readlink "/proc/${myPID}/exe" )
    ( fuser "${myEXE}" >"${stdoutF}" 2>"${stderrF}" )
    rtrn=$?

    assertEquals "fuser exit value" "0" "${rtrn}"
    grep -qE "${myPID}" "${stdoutF}"
    assertTrue 'STDOUT has my PID' $?
    grep -qE "^${myEXE}:.*e" "${stderrF}"
    assertTrue 'STDERR has my path and e' $?
}
oneTimeSetUp() {
  # Define global variables for command output.
  stdoutF="${AUTOPKGTEST_TMP}/stdout"
  stderrF="${AUTOPKGTEST_TMP}/stderr"
  testF="${AUTOPKGTEST_TMP}/test-file"
  touch "${testF}"
  myPID=$$
}

setUp() {
  # Truncate the output files.
  cp /dev/null "${stdoutF}"
  cp /dev/null "${stderrF}"
}


# shellcheck disable=SC1091
. shunit2