~dricottone/my-utils

ref: c168cd406c53bbf956e892e94ea222871e9558b0 my-utils/tests/ctdir_test.sh -rwxr-xr-x 868 bytes
c168cd40Dominic Ricottone Cleaned up README 4 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