Skip to content

Commit 769f571

Browse files
committed
tests: check --include, --exclude, and -nT
1 parent df29760 commit 769f571

12 files changed

+116
-0
lines changed

Makefile.am

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,13 @@ EXTRA_DIST+= \
701701
tests/06-progress-output-vpb-1k.good \
702702
tests/06-progress-output-vpb-20k.good \
703703
tests/06-progress-output.sh \
704+
tests/07-selecting-files-baseline.good \
705+
tests/07-selecting-files-exclude.good \
706+
tests/07-selecting-files-include-exclude.good \
707+
tests/07-selecting-files-include.good \
708+
tests/07-selecting-files-nT-full.good \
709+
tests/07-selecting-files-nT-partial.good \
710+
tests/07-selecting-files.sh \
704711
tests/fake-passphrased.keys \
705712
tests/fake.keys \
706713
tests/shared_test_functions.sh \
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
a .
2+
a ./a
3+
a ./dir1
4+
a ./dir1/b
5+
a ./dir1/c
6+
a ./dir2
7+
a ./dir2/d
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
a .
2+
a ./a
3+
a ./dir2
4+
a ./dir2/d
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
a .
2+
a ./dir1
3+
a ./dir1/c
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
a .
2+
a ./dir1
3+
a ./dir1/b
4+
a ./dir1/c
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
a .
2+
a ./a
3+
a ./dir1
4+
a ./dir1/b
5+
a ./dir1/c
6+
a ./dir2
7+
a ./dir2/d
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
a .
2+
a ./a
3+
a ./dir2
4+
a ./dir2/d

tests/07-selecting-files.sh

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/sh
2+
3+
### Constants
4+
c_valgrind_min=1
5+
sampledir=${scriptdir}/sample-backup
6+
7+
check_ie() {
8+
name=$1
9+
args=$2
10+
11+
# Set up variables.
12+
out_name=${s_basename}-${name}.txt
13+
good_name=${scriptdir}/07-selecting-files-${name}.good
14+
15+
# Run command. We need to `sort` because the OS doesn't necessarily
16+
# process files in alphabetical order. Don't quote the ${args}.
17+
setup_check "check ${name}"
18+
${c_valgrind_cmd} ./tarsnap --no-default-config \
19+
-c --dry-run -v \
20+
-C "${sampledir}" \
21+
${args} \
22+
. 2>&1 | LC_ALL=C sort > "${out_name}"
23+
echo $? > "${c_exitfile}"
24+
25+
# Check against expected output.
26+
setup_check "check ${name} output"
27+
cmp "${good_name}" "${out_name}"
28+
echo $? > "${c_exitfile}"
29+
30+
}
31+
32+
check_nT() {
33+
name=$1
34+
cmd=$2
35+
36+
# Set up variables.
37+
out_name=${s_basename}-nT-${name}.txt
38+
good_name=${scriptdir}/07-selecting-files-nT-${name}.good
39+
filelist=${s_basename}-filelist-${name}.txt
40+
41+
# Create filelist. Don't quote ${cmd}.
42+
(cd "${sampledir}" && eval ${cmd} | sort > "${filelist}")
43+
44+
# Run command. We need to `sort` because the OS doesn't necessarily
45+
# process files in alphabetical order.
46+
setup_check "check ${name}"
47+
(
48+
cd "${sampledir}" &&
49+
${c_valgrind_cmd} \
50+
"${out}"/../tarsnap --no-default-config \
51+
-c --dry-run -v \
52+
-C "${sampledir}" \
53+
-n -T "${filelist}" \
54+
2>&1 | LC_ALL=C sort > "${out_name}"
55+
echo $? > "${c_exitfile}"
56+
)
57+
58+
# Check against expected output.
59+
setup_check "check ${name} output"
60+
cmp "${good_name}" "${out_name}"
61+
echo $? > "${c_exitfile}"
62+
63+
}
64+
65+
scenario_cmd() {
66+
# Run a baseline, then check include, exclude, and both.
67+
# For --include, we need "." otherwise it won't match anything.
68+
check_ie "baseline" ""
69+
check_ie "include" "--include . --include dir1"
70+
check_ie "exclude" "--exclude dir1"
71+
check_ie "include-exclude" "--include . --include dir1 --exclude b"
72+
73+
# Check passing a list of files via -n -T.
74+
check_nT "full" "find ."
75+
check_nT "partial" "find . | grep -v dir1"
76+
}

tests/sample-backup/a

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a

tests/sample-backup/dir1/b

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
b

0 commit comments

Comments
 (0)