-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest
executable file
·101 lines (81 loc) · 2.32 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
101
#!/bin/bash
bh="$PWD/bh"
li="$PWD/list"
lisum="386e39227c6b63be891501bc1700b048170fe52834caede5010fc06f085603d7"
if [[ $(sha256sum "$li" | cut -d " " -f 1) != $lisum ]]; then
echo "Test data checksum doesn't match."
echo "Expect failures."
fi
testdir="/tmp/bh-test-$(date -u +"%F.%T")-$RANDOM"
failcount=0
failtest () {
echo "FAILURE ($?):" $1
failcount=$(($failcount + 1))
}
mkdir "$testdir"
cd "$testdir"
$bh init
if [ ! -f .bibbase ]; then failtest "Initing bibbase failed"; fi
# Non-existant repo tests
"$bh" add junk:junk
if [ -d junk ] ; then failtest "Add junk protocol should fail here" ; fi
"$bh" addprot junk
if [ ! -d junk ] ; then failtest "Adding junk protocol failed"; fi
"$bh" add junk:junk
if [ ! -d junk/junk ] ; then failtest "Junk entry folder added" ; fi
if [ ! -f junk/junk/.entry ] ; then failtest "Junk entry file added" ; fi
# Removals are manual
rm -rf junk
echo "Adding standrd protocols"
protocols=(arxiv doi isbn)
bh addprot "${protocols[@]}"
for i in "${protocols[@]}"; do
if [ ! -d "$i" ]; then failtest "Couldn't add $i protocol"; fi
done
echo "Adding entries:"
time cat $li | xargs $bh add
echo "Return: " $?
tree -a
echo "179 directories expected"
echo "Misplaced entries:"
comm -3 <($bh list | sort) <(cat "$li" | tr "[:upper:]" "[:lower:]" | sort)
# Reflow tests
# Reflowing is currently done _manually_
mkdir doi/10.1103_x2f
mkdir doi/10.1103_x2f/physreva.
echo "Reflowing entries"
time find . -name .entry -printf %h\\0 | xargs -0 $bh reflow
echo "Return: " $?
if [ ! -f "doi/10.1103_x2f/physrevlett.100.030503/.entry" ]; then
failtest "Single nested reflow failed"
fi
if [ ! -f "doi/10.1103_x2f/physreva./41.5139/.entry" ]; then
failtest "Double nested reflow failed"
fi
tree -a
echo "181 directories expected"
echo "Misplaced entries:"
comm -3 <($bh list | sort) <(cat "$li" | tr "[:upper:]" "[:lower:]" | sort)
gettertest="(\
physrevlett\\.100\\.030503|\
physreva\\.41\\.5139|\
science\\.273\\.5278\\.1073\
)"
echo $gettertest
getterfiles=(\
"doi/10.1103_x2f/physreva./41.5139/bib"
"doi/10.1103_x2f/physrevlett.100.030503/bib"
"doi/10.1126_x2fscience.273.5278.1073/bib"
)
xargs -a <(egrep "$gettertest" $li) "$bh" getbib
for f in "${getterfiles[@]}"; do
if [ ! -f "$f" ]; then
failtest "doi getter failed: $f"
else
echo "$f"
cat "$f"
echo
fi
done
rm -rf "$testdir"
echo Failures: $failcount