-
Notifications
You must be signed in to change notification settings - Fork 0
/
test
executable file
·209 lines (179 loc) · 3.7 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/bin/sh
set +e +x
if : Dependencies; then
if test x"$GIT" == x""
then
GIT="$(which git)"
fi
if test x"$PYTHON" == x""
then
PYTHON="$(which python3)"
fi
export GIT PYTHON
fi
if : Test Environment; then
SRC="$(cd "$(dirname "$0")"; pwd)"
SCRIPT="$SRC/$(basename "$0")"
WS="$(mktemp -d)"
export SRC SCRIPT WS
fi
log ()
{
echo >&2 "$@"
}
Fail ()
{
log "-> $TEST: failed" '(' "$@" ')'
exit 1
}
Test ()
{
if test "$@"
then
return 0
else
Fail absurdity test "$@"
exit 1
fi
}
LG ()
{
# Repository initialization.
(set -o pipefail
"$GIT" 2>&1 "$@" | sed 's/^/test-repository: /')
}
GS ()
{
(set -o pipefail
"$PYTHON" 2>&1 "$SRC/git-select.py" "$@" | sed 's/^/git-select: /')
}
gsf ()
{
Fail "non-zero git-select status"
}
seal ()
{
export TEST="$1"
local tmp="$(mktemp -d)"
(cd "$tmp" || exit
if ("$1")
then
log "-> $TEST: passed"
else
:
fi
)
}
test_sole_resource ()
{
# Citing sole data file.
GS "$TR" main data-file || gsf
Test -e data-file -a x"$(cat data-file)" = x"file-content-1"
}
test_resource_set ()
{
# Citing multiple files, maintaining directory structure.
GS "$TR" main data-file dir/data-file || gsf
Test -e data-file -a x"$(cat data-file)" = x"file-content-1"
Test -e dir/data-file -a x"$(cat dir/data-file)" = x"file-content-2"
}
test_resource_tree ()
{
# Citing a directory.
GS "$TR" main dir || gsf
Test ! -e data-file
Test -e dir/data-file -a x"$(cat dir/data-file)" = x"file-content-2"
Test -e dir/sub/data-file -a x"$(cat dir/sub/data-file)" = x"file-content-3"
}
test_remapped_path ()
{
# Remap a sole data file.
GS "$TR" main dir/sub/data-file/./df || gsf
Test -e df -a x"$(cat df)" = x"file-content-3"
}
test_remapped_resource_set ()
{
# Citing multiple files, maintaining directory structure.
GS "$TR" main data-file/./df1 dir/data-file/./df2 || gsf
Test -e df1 -a x"$(cat df1)" = x"file-content-1"
Test -e df2 -a x"$(cat df2)" = x"file-content-2"
}
test_remapped_subdirectory ()
{
# Remap a subdirectory.
GS "$TR" main dir/sub//./d || gsf
# Selected dir/sub; only contains data-file(3)
Test -d d
Test -e d/data-file -a x"$(cat d/data-file)" = x"file-content-3"
}
test_remapped_directory ()
{
# Remap a root directory.
GS "$TR" main dir/./rd || gsf
# Selected dir/sub; only contains data-file(3)
Test -d rd -a -d rd/sub
Test -e rd/data-file -a x"$(cat rd/data-file)" = x"file-content-2"
Test -e rd/sub/data-file -a x"$(cat rd/sub/data-file)" = x"file-content-3"
}
test_remapped_leading_path ()
{
# Remap the leading path of a data-file using a trailing slash.
GS "$TR" main dir/sub/data-file/./local-dir/ || gsf
Test -d local-dir
Test -e local-dir/data-file -a x"$(cat local-dir/data-file)" = x"file-content-3"
}
test_no_such_repository ()
{
GS "$TR/../fs-void" main data-file
r=$?
Test ! -e data-file
Test $r -ne 0
}
test_no_such_snapshot ()
{
GS "$TR" no-such-commit data-file
r=$?
Test ! -e data-file
Test $r -ne 0
}
test_no_such_resource ()
{
GS "$TR" main no-such-data-file
r=$?
Test ! -e no-such-data-file
Test $r -ne 0
}
reveal ()
{
# Check git-select features using $TR.
for tid in $(sed -n 's/^\(test_.*\) ()$/\1/p' < "$SCRIPT")
do
(seal $tid)
done
}
mkfixture ()
{
set -e
LG init -b main "$1"
cd "$1"
mkdir -p dir/sub/empty
echo "file-content-1" >data-file
echo "file-content-2" >dir/data-file
echo "file-content-3" >dir/sub/data-file
LG add dir data-file
LG commit -m "sole" .
}
(cd "$WS"
# Setup test repository.
TR="$(pwd)/repo"
PCACHE="$(pwd)/test-cache"
log "=>" "$SRC/git-select.py" "$GIT" "$PYTHON"
(mkfixture "$TR")
# Check git-select features using $TR.
log '=> [temporary-cache]'
unset GIT_SELECT_CACHE
reveal
export GIT_SELECT_CACHE="$PCACHE"
log "=> [persistent-cache $GIT_SELECT_CACHE]"
reveal
)