~dricottone/my-utils

ref: 9c7265d72675317569a2e502a20a67f9bf763ecd my-utils/core/test_debom_rebom.sh -rwxr-xr-x 950 bytes
9c7265d7Dominic Ricottone Standardization of docs, [[ usage, local variables. 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
35
36
#!/bin/sh
# tests demon and rebom

# move to temp directory
cd test

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

# try de-BOM-ing a file
../debom -d debom_target.txt > debom_result.txt
if ! cmp rebom_target.txt debom_result.txt >/dev/null 2>&1; then
  printf "Failure in BOM tests: de-BOM-ed file is corrupt\n"
  exit 1
fi

# try re-BOM-ing a file
../rebom rebom_target.txt > rebom_result.txt
if ! cmp debom_target.txt rebom_result.txt >/dev/null 2>&1; then
  printf "Failure in BOM tests: re-BOM-ed file is corrupt\n"
  exit 1
fi