blob: 293136109dd7d4dc7ebb8cc5767fc085814ba264 (
plain)
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
|
Step implementations
====================
This chapter contains implementations of each step. See the [yarn]
manual for details and examples.
Running distix
--------------
We need a way for the steps to run distix with various command line
arguments. Instead of having a different IMPLEMENTS step for each
command that needs to be run, we'll have one fairly generic one. It'll
allow the step to provide the command line arguments, but then also
adds in options and things to make distix be isolated from, say,
global configuration etc.
User needs to change directory. Since each step is run in a new shell,
we do this by keeping track ourselves of where the scenario wants to
be, and changing there when running various commands.
IMPLEMENTS WHEN user changes working directory to (\S+)
printf "%s" "$MATCH_1" > "$DATADIR/cwd"
IMPLEMENTS WHEN user attempts to run distix ([^$]*)
# Yarn sets $HOME to point at an empty temporary directory.
# Set up a simple git config so tests can use git.
git config --global user.email 'Tomjon <tomjon@example.com>'
git config --global user.name 'Tomjon Tester'
cd "$DATADIR"
rm -f attempt.exit attempt.stdout attempt.stderr
cd "$(cat cwd || echo .)"
if "$SRCDIR/distix" --no-default-config --quiet \
--log "$DATADIR/distix.log" \
$MATCH_1 \
> "$DATADIR/attempt.stdout" 2> "$DATADIR/attempt.stderr"
then
echo 0 > "$DATADIR/attempt.exit"
else
echo "$?" > "$DATADIR/attempt.exit"
fi
IMPLEMENTS WHEN user attempts to run distix show \$PREFIX
# Yarn sets $HOME to point at an empty temporary directory.
# Set up a simple git config so tests can use git.
git config --global user.email 'Tomjon <tomjon@example.com>'
git config --global user.name 'Tomjon Tester'
cd "$DATADIR"
rm -f attempt.exit attempt.stdout attempt.stderr
cd "$(cat cwd || echo .)"
if "$SRCDIR/distix" --no-default-config --quiet \
--log "$DATADIR/distix.log" \
show "$(cat "$DATADIR/tid-prefix")"\
> "$DATADIR/attempt.stdout" 2> "$DATADIR/attempt.stderr"
then
echo 0 > "$DATADIR/attempt.exit"
else
echo "$?" > "$DATADIR/attempt.exit"
fi
IMPLEMENTS WHEN user sets all tickets in (\S+) to (\S+)
cd "$DATADIR/$MATCH_1"
"$SRCDIR/distix" --no-default-config --quiet \
--log "$DATADIR/distix.log" list |
awk '/^ / { print $2 }' > "$DATADIR/tickets.list"
cat "$DATADIR/tickets.list" |
while read ticket
do
"$SRCDIR/distix" --no-default-config --quiet \
--log "$DATADIR/distix.log" \
set "$MATCH_2" "$ticket"
done
We also need steps for inspecting the results of attempting to run
distix.
IMPLEMENTS THEN attempt succeeded
cat "$DATADIR/attempt.exit"
cat "$DATADIR/attempt.stderr"
if ! grep -Fx 0 "$DATADIR/attempt.exit"
then
echo "Attempt should have succeeded, but didn't" 1>&2
exit 1
fi
IMPLEMENTS THEN output is "(.*)"
cat "$DATADIR/attempt.stdout"
printf "$MATCH_1" > "$DATADIR/temp-stdout"
diff -u "$DATADIR/temp-stdout" "$DATADIR/attempt.stdout"
IMPLEMENTS THEN output matches "(.*)"
cat "$DATADIR/attempt.stdout"
grep -P -e "$MATCH_1" "$DATADIR/attempt.stdout"
IMPLEMENTS THEN output doesn't match "(.*)"
cat "$DATADIR/attempt.stdout"
if grep -P -e "$MATCH_1" "$DATADIR/attempt.stdout"
then
echo "$DATADIR/attempt.stdout unexpected matches $MATCH_1" 1>&2
exit 1
fi
IMPLEMENTS THEN first ticket id is captured as \$TID
# We assume previous command run was distix list.
# Each line starts with a full ticket id.
awk 'NR == 2 { print $2; exit }' "$DATADIR/attempt.stdout" \
> "$DATADIR/ticket-id-1"
IMPLEMENTS THEN attempt failed
cat "$DATADIR/attempt.exit" # helps debugging scenarios
if grep -Fx 0 "$DATADIR/attempt.exit"
then
echo "Attempt should have failed, but didn't" 1>&2
exit 1
fi
IMPLEMENTS THEN error message matches (.*)
cat "$DATADIR/attempt.stderr"
grep -e "$MATCH_1" "$DATADIR/attempt.stderr"
File creation
-------------
We need to provide a way for scenarios to create files with known
content.
IMPLEMENTS GIVEN file (\S+) containing "(.*)"
printf "$MATCH_2" > "$DATADIR/$MATCH_1"
Maildir creation
----------------
We need to create a maildir with mails in it.
IMPLEMENTS GIVEN maildir (\S+) containing a mail with subject "(.+)"
dirname="$DATADIR/$MATCH_1"
mkdir -p "$dirname/new" "$dirname/cur" "$dirname/tmp"
cat <<EOF > "$dirname/new/message"
From: user@example.com
Subject: $MATCH_2
Message body goes here.
EOF
File tests
-----------
Does a file or directory exist?
IMPLEMENTS THEN (\S+) exists
test -e "$DATADIR/$MATCH_1"
Repository/ticket tests
-----------------------
How many tickets does a repository have?
IMPLEMENTS THEN repository (\S+) has (\d+) tickets?
n="$(ls "$DATADIR/$MATCH_1/tickets" | wc -l)"
[ "$n" = "$MATCH_2" ]
How many copies of a given message does a repository have? In any
tickets?
IMPLEMENTS THEN repository (\S+) has one copy of message in (\S+)
find "$DATADIR/$MATCH_1/tickets" -type f -exec md5sum '{}' + \
> "$DATADIR/md5sums"
msgsum="$(md5sum < "$DATADIR/$MATCH_2" | awk '{ print $1 }')"
n="$(grep -c -e "$msgsum" "$DATADIR/md5sums" | wc -l)"
[ "$n" = 1 ]
Git operations
--------------
Clone a repository.
IMPLEMENTS WHEN user clones (\S+) to (\S+)
cd "$DATADIR"
git clone "$MATCH_1" "$MATCH_2"
Check that everything is in git.
IMPLEMENTS THEN everything in (\S+) is committed to git
cd "$DATADIR/$MATCH_1"
if git status --short | grep .
then
echo "Not everything is in git" 1>&2
exit 1
fi
Ticket id manipulation
----------------------
IMPLEMENTS THEN ticket id \$TID 7-nybble prefix is \$PREFIX
cut -c1-7 "$DATADIR/ticket-id-1" > "$DATADIR/tid-prefix"
IMPLEMENTS THEN output contains ticket id \$TID
grep -f "$DATADIR/ticket-id-1" "$DATADIR/attempt.stdout"
|