~dricottone/my-utils

ref: 60d3e563aa74dfccab44c7647464d0059a001f24 my-utils/core/test_whichcat_whichhead.sh -rwxr-xr-x 972 bytes
60d3e563Dominic Ricottone whichhead fix 2 years ago
                                                                                
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
#!/bin/sh
# tests whichcat and whichhead

# move to temp directory
cd test

test_exit_code() {
  $1 >/dev/null 2>&1
  if [ $? -ne $2 ]; then
    printf "Failure in whichcat tests: wrong exit code ('$1' returned '$?', should be '$2')\n"
    exit 1
  fi
}
test_exit_code "../whichcat -v" "0"
test_exit_code "../whichcat -h" "0"
test_exit_code "../whichcat" "0"
test_exit_code "../whichcat non-existant-binary" "1"
test_exit_code "../whichhead -v" "0"
test_exit_code "../whichhead -h" "0"
test_exit_code "../whichhead" "0"
test_exit_code "../whichhead non-existant-binary" "1"

should_be="$(wc -l ../whichcat | cut --delimiter=' ' --fields=1)"
if [ "$(cd .. && ./whichcat whichcat | wc -l)" -ne "$should_be" ]; then
  printf "Failure in whichcat tests: wrong file returned\n"
  exit 1
fi

should_be="$((should_be * 2))"
if [ "$(cd .. && ./whichcat whichcat whichcat | wc -l)" -ne "$should_be" ]; then
  printf "Failure in whichcat tests: wrong files returned\n"
  exit 1
fi