~dricottone/my-utils

ref: 618b5e7801dd9bdc6100b6ed88f04d9dcd75a3ab my-utils/tests/ctdir_test.sh -rwxr-xr-x 868 bytes
618b5e78Dominic Ricottone Slight refactor of a usage message 3 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
35
36
#!/bin/sh

# ctdir

# exit codes
if ! ctdir -v >/dev/null 2>&1; then
  printf "Wrong exit code on 'ctdir -v' - should be 0\n"
  exit 1
elif ! ctdir -h >/dev/null 2>&1; then
  printf "Wrong exit code on 'ctdir -h' - should be 0\n"
  exit 1
elif ctdir >/dev/null 2>&1; then
  printf "Wrong exit code on 'ctdir' - should be 1\n"
  exit 1
elif ctdir non-existant >/dev/null 2>&1; then
  printf "Wrong exit code on 'ctdir non-existant' should be 1\n"
  exit 1
elif ! ctdir . >/dev/null 2>&1; then
  printf "Wrong exit code on 'ctdir .' should be 0\n"
  exit 1
fi

# output
num=$(ctdir .)
if [ ! "$num" -eq "$num" ] 2>/dev/null; then
  printf "Did not return a number on 'ctdir .'\n"
  exit 1
fi

# behavior on multiple inputs
lines=$(ctdir . . | wc -l)
if [ "$lines" -ne 2 ] 2>/dev/null; then
  printf "Did not return a number for each input on 'ctdir . .'\n"
  exit 1
fi