-
Notifications
You must be signed in to change notification settings - Fork 0
/
test
executable file
·100 lines (73 loc) · 2.8 KB
/
test
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
set -e
not ()
{
! "$@"
}
cd "$(dirname -- "$0")"
if [[ ! -e /.dockerenv ]] #not running in docker
then
./lint
fi
T=$(mktemp -d -- "${TMPDIR:-/tmp/}$(basename -- "$0").XXXXXX")
trap 'rm -rf -- "${T:?}"' EXIT
trap 'echo "Error on line $LINENO." >&2' ERR
echo 'Testing with a missing DEST' >&2
mkdir -- "${T:?}/src"
cat >"${T:?}/.backup_include" <<EOD
${T:?}/src
${T:?}/missing
EOD
not ./lnbackup "${T:?}/.backup_include" "${T:?}/dest"
echo >&2
echo 'Testing with an existing backup' >&2
mkdir -- "${T:?}/dest"
./lnbackup "${T:?}/.backup_include" "${T:?}/dest"
not ./lnbackup "${T:?}/.backup_include" "${T:?}/dest"
echo >&2
echo 'Testing with various file names, duplicate files, a symbolic link, a directory, and a fifo' >&2
CRAZY_FILENAME='~`!@#$%^&*()-_=+[{]}'\\'|;:'"'"'",<.>? '
echo '' >"${T:?}/src/${CRAZY_FILENAME:?}"
echo '' >"${T:?}/src/-hyphen"
echo '' >"${T:?}/src/.hidden"
echo '' >"${T:?}/src/ "
echo 'identical' >"${T:?}/src/identical1"
cp -p -- "${T:?}/src/identical1" \
"${T:?}/src/identical2"
echo 'different' >"${T:?}/src/different"
ln -s missing "${T:?}/src/symboliclink"
mkdir -- "${T:?}/src/dir"
mkfifo -- "${T:?}/src/fifo"
sleep 1 #prevent backup from running twice in the same second
./lnbackup "${T:?}/.backup_include" "${T:?}/dest"
[[ -d "${T:?}/dest/Latest/${T:?}/src" ]]
[[ -f "${T:?}/dest/Latest/${T:?}/src/${CRAZY_FILENAME:?}" ]]
[[ -f "${T:?}/dest/Latest/${T:?}/src/-hyphen" ]]
[[ -f "${T:?}/dest/Latest/${T:?}/src/.hidden" ]]
[[ -f "${T:?}/dest/Latest/${T:?}/src/ " ]]
[[ "${T:?}/dest/Latest/${T:?}/src/identical1" -ef "${T:?}/dest/Latest/${T:?}/src/identical2" ]]
[[ ! ( "${T:?}/dest/Latest/${T:?}/src/identical1" -ef "${T:?}/src/identical1" ) ]]
[[ ! ( "${T:?}/dest/Latest/${T:?}/src/different" -ef "${T:?}/dest/Latest/${T:?}/src/identical1" ) ]]
[[ -h "${T:?}/dest/Latest/${T:?}/src/symboliclink" ]]
[[ -d "${T:?}/dest/Latest/${T:?}/src/dir" ]]
[[ ! -e "${T:?}/dest/Latest/${T:?}/src/fifo" ]]
echo >&2
echo 'Testing with a duplicate file, and without perl' >&2
cp -pPR -- "${T:?}/dest/Latest" \
"${T:?}/dest/Previous"
cp -p -- "${T:?}/src/identical1" \
"${T:?}/src/identical3"
perl () { ! :; } #disable perl
export -f perl
sleep 1 #prevent backup from running twice in the same second
./lnbackup "${T:?}/.backup_include" "${T:?}/dest"
[[ "${T:?}/dest/Latest/${T:?}/src/identical1" -ef "${T:?}/dest/Previous/${T:?}/src/identical1" ]]
[[ "${T:?}/dest/Latest/${T:?}/src/identical3" -ef "${T:?}/dest/Previous/${T:?}/src/identical1" ]]
echo >&2
find -- "${T:?}"
trap - ERR
if command -v docker >/dev/null && [[ ! -e /.dockerenv ]] #not running in docker
then
echo >&2
docker run --rm -v "${PWD:?}":/wd -w /wd debian ./"$(basename -- "$0")" #run in docker
fi