|
Iain Douglas |
05452a |
#!/bin/bash
|
|
Iain Douglas |
05452a |
# Author: Iain Douglas <centos@1n6.org.uk>
|
|
Iain Douglas |
05452a |
|
|
|
2b3708 |
uname_arch=$(uname -m)
|
|
|
2b3708 |
|
|
|
2b3708 |
if [ "$uname_arch" == "armv7l" ]; then
|
|
|
2b3708 |
t_Log "*** Not testing on Arch: $uname_arch ***"
|
|
|
2b3708 |
exit 0
|
|
|
2b3708 |
fi
|
|
|
2b3708 |
|
|
|
2b3708 |
|
|
Iain Douglas |
05452a |
# Tests for cmp
|
|
Iain Douglas |
05452a |
|
|
Iain Douglas |
05452a |
function ExitFail {
|
|
Iain Douglas |
05452a |
t_Log "FAIL"
|
|
Iain Douglas |
05452a |
exit $FAIL
|
|
Iain Douglas |
05452a |
}
|
|
Iain Douglas |
05452a |
# Basic Tests
|
|
Iain Douglas |
05452a |
|
|
Iain Douglas |
05452a |
t_Log "Running $0 - cmp tests"
|
|
Iain Douglas |
05452a |
|
|
Iain Douglas |
05452a |
t_Log "Basic Check"
|
|
Iain Douglas |
05452a |
cmp -v &>/dev/null || ExitFail
|
|
Iain Douglas |
05452a |
|
|
Iain Douglas |
05452a |
FILE=/var/tmp/diffutils
|
|
Iain Douglas |
82d069 |
# Cleanup just in case we exited without doing so earlier.
|
|
Iain Douglas |
82d069 |
rm ${FILE}a ${FILE}b &>/dev/null
|
|
Iain Douglas |
05452a |
|
|
Iain Douglas |
82d069 |
# Create some files to work with
|
|
Iain Douglas |
05452a |
cat << EOF >${FILE}a
|
|
Iain Douglas |
05452a |
This is some text to play with
|
|
Iain Douglas |
05452a |
EOF
|
|
Iain Douglas |
05452a |
|
|
Iain Douglas |
05452a |
cat << EOF >${FILE}b
|
|
Iain Douglas |
05452a |
This is some test to play with
|
|
Iain Douglas |
05452a |
EOF
|
|
Iain Douglas |
05452a |
|
|
Iain Douglas |
05452a |
# Basic check of 2 files
|
|
Iain Douglas |
05452a |
t_Log "Compare 2 files"
|
|
Iain Douglas |
05452a |
cmp ${FILE}a ${FILE}b | grep -q "byte 16, line 1" || ExitFail
|
|
Iain Douglas |
05452a |
|
|
Iain Douglas |
05452a |
t_Log "Compare 2 files -b"
|
|
Iain Douglas |
05452a |
cmp -b ${FILE}a ${FILE}b | grep -q " line 1 is 170 x 163 s" || ExitFail
|
|
Iain Douglas |
05452a |
t_Log "Check -i - skip bytes "
|
|
Iain Douglas |
05452a |
|
|
Iain Douglas |
05452a |
# Expect this to pass as the difference is at byte 16
|
|
Iain Douglas |
05452a |
cmp -b -i 16 ${FILE}a ${FILE}b || ExitFail
|
|
Iain Douglas |
05452a |
|
|
Iain Douglas |
05452a |
t_Log "check -i skip1:skip2"
|
|
Iain Douglas |
05452a |
|
|
Iain Douglas |
3451d5 |
# Expect this to have a different output to earlier
|
|
Iain Douglas |
05452a |
cmp -i 15:16 ${FILE}a ${FILE}b | grep -q "byte 1, line 1"|| ExitFail
|
|
Iain Douglas |
05452a |
|
|
Iain Douglas |
05452a |
# Chek that -n works
|
|
Iain Douglas |
05452a |
t_Log "Check -n limit bytes"
|
|
Iain Douglas |
05452a |
cmp -n 15 ${FILE}a ${FILE}b || ExitFail
|
|
Iain Douglas |
05452a |
|
|
Iain Douglas |
05452a |
# Verbose output
|
|
Iain Douglas |
05452a |
t_Log "Check -l - verbose output"
|
|
Iain Douglas |
05452a |
cmp -l ${FILE}a ${FILE}b | grep -q "16 170 163" || ExitFail
|
|
Iain Douglas |
05452a |
|
|
Iain Douglas |
05452a |
# Silent - exit status only, first scheck that there is no output
|
|
Iain Douglas |
05452a |
t_Log "Check -s - silent mode"
|
|
Iain Douglas |
05452a |
cmp -s ${FILE}a ${FILE}b | wc -m | grep -q "^0" || ExitFail
|
|
Iain Douglas |
05452a |
cmp -i 16 -s ${FILE}a ${FILE}b
|
|
Iain Douglas |
05452a |
t_CheckExitStatus $?
|
|
Iain Douglas |
05452a |
|
|
Iain Douglas |
82d069 |
rm ${FILE}a ${FILE}b &>/dev/null
|