~dricottone/my-utils

ref: 633a26b0bbebe61da21f82abef4d3d35351c88c5 my-utils/core/test_debom_rebom.sh -rwxr-xr-x 950 bytes
633a26b0Dominic Ricottone Moving gitstat into public repo 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