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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
|
IMPLEMENTS implementations
==========================
Implementation sections for workspaces
--------------------------------------
We'll use `$DATADIR/workspace` as the workspace directory that is used.
IMPLEMENTS GIVEN no workspace
true
IMPLEMENTS GIVEN an empty workspace directory
mkdir "$DATADIR/workspace"
IMPLEMENTS GIVEN a non-empty workspace directory
mkdir "$DATADIR/workspace"
touch "$DATADIR/workspace/random-file"
We run `morph init` in two different ways: either the simple way,
letting yarn catch errors, or in a way that catches the error so
we can test it later in a THEN step.
IMPLEMENTS WHEN morph initialises a workspace
run_morph init "$DATADIR/workspace"
IMPLEMENTS WHEN morph attempts to initialise a workspace
attempt_morph init "$DATADIR/workspace"
IMPLEMENTS THEN morph failed
case $(cat "$DATADIR/morph-exit") in
0) die "Morph should have failed, but didn't. Unexpected success!" ;;
esac
We need to check that a workspace creation worked. This requires the
directory to exist, and its `.morph` subdirectory to exist, and nothing
else.
IMPLEMENTS THEN an empty workspace exists
is_dir "$DATADIR/workspace"
is_dir "$DATADIR/workspace/.morph"
assert_equal $(ls -A "$DATADIR/workspace" | wc -l) 1
Tests for things other than `morph init` just want to have a workspace
created.
IMPLEMENTS GIVEN a workspace
run_morph init "$DATADIR/workspace"
Implementation sections related to a simulated Trove
----------------------------------------------------
Morph needs access to a Trove, i.e., a git server, in order to do certain
kinds of stuff. We simulate this by creating a set of git repositories
locally, which we'll tell Morph to access using `file:` URLs. Specifically,
we'll create a repository to hold system and stratum morphologies, and
another to hold a chunk.
IMPLEMENTS GIVEN a git server
# Create a directory for all the git repositories.
mkdir "$DATADIR/gits"
# Create a repo for the system and stratum morphologies.
mkdir "$DATADIR/gits/morphs"
arch=$(run_morph print-architecture)
cat << EOF > "$DATADIR/gits/morphs/test-system.morph"
name: test-system
kind: system
arch: $arch
strata:
- name: test-stratum
repo: test:morphs
ref: master
morph: test-stratum
EOF
cat << EOF > "$DATADIR/gits/morphs/test-stratum.morph"
name: test-stratum
kind: stratum
chunks:
- name: test-chunk
repo: test:test-chunk
ref: master
morph: test-chunk
build-mode: bootstrap
build-depends: []
EOF
run_in "$DATADIR/gits/morphs" git init .
run_in "$DATADIR/gits/morphs" git add .
run_in "$DATADIR/gits/morphs" git commit -m Initial.
# Create the chunk repository.
mkdir "$DATADIR/gits/test-chunk"
cat << EOF > "$DATADIR/gits/test-chunk/test-chunk.morph"
name: test-chunk
kind: chunk
build-system: dummy
EOF
run_in "$DATADIR/gits/test-chunk" git init .
run_in "$DATADIR/gits/test-chunk" git add .
run_in "$DATADIR/gits/test-chunk" git commit -m Initial.
# Create the Morph configuration file so we can access the repos
# using test:foo URL aliases.
cat << EOF > "$DATADIR/morph.conf"
[config]
repo-alias = test=file://$DATADIR/gits/%s#file://$DATADIR/gits/%s
EOF
Implementation sections for system branch operations
----------------------------------------------------
Checkout out an existing system branch. We parameterise this so the
same phrase can be used to check out any system branch.
IMPLEMENTS WHEN checking out the (\S+) system branch
cd "$DATADIR/workspace"
run_morph checkout test:morphs "$MATCH_1"
Attempt to check out a system branch, and remember if it failed.
IMPLEMENTS WHEN morph attempts to check out system branch (\S+)
cd "$DATADIR/workspace"
attempt_morph checkout test:morphs "$MATCH_1"
Attempt to check out a system branch from a root that has no systems.
IMPLEMENTS WHEN morph attempts to check out a repository with no systems
cd "$DATADIR/workspace"
attempt_morph checkout test:test-chunk master
We also need to verify that a system branch has been checked out.
IMPLEMENTS THEN the system branch (\S+) is checked out
is_dir "$DATADIR/workspace/$MATCH_1/test:morphs"
is_file "$DATADIR/workspace/$MATCH_1/test:morphs/test-system.morph"
is_file "$DATADIR/workspace/$MATCH_1/test:morphs/test-stratum.morph"
We can create a new branch, off master.
IMPLEMENTS WHEN creating system branch (\S+)
cd "$DATADIR/workspace"
run_morph branch test:morphs "$MATCH_1"
We can create a new branch, off another system branch.
IMPLEMENTS WHEN creating system branch (\S+), based on (\S+)
cd "$DATADIR/workspace"
run_morph branch test:morphs "$MATCH_1" "$MATCH_2"
Attempt to branch a system branch from a root that had no systems.
IMPLEMENTS WHEN morph attempts to branch a repository with no systems
cd "$DATADIR/workspace"
attempt_morph branch test:test-chunk foo
Pushing all changes in a system branch checkout to the git server.
IMPLEMENTS WHEN pushing system branch (\S+) to git server
# FIXME: For now, this is just the morphs checkout.
run_in "$DATADIR/workspace/$MATCH_1/test:morphs" git push origin HEAD
Report workspace path.
IMPLEMENTS WHEN morph reports workspace in (\S+)
cd "$DATADIR/workspace/$MATCH_1"
run_morph workspace > "$DATADIR/workspace-reported"
IMPLEMENTS THEN workspace is reported correctly
assert_equal $(cat "$DATADIR/workspace-reported") "$DATADIR/workspace"
IMPLEMENTS WHEN morph attempts to report workspace
cd "$DATADIR"
attempt_morph workspace
Report system branch name:
IMPLEMENTS WHEN reporting system branch in (\S+)
cd "$DATADIR/workspace/$MATCH_1"
run_morph show-system-branch > "$DATADIR/system-branch.reported"
IMPLEMENTS THEN system branch is reported as (.*)
echo "$MATCH_1" > "$DATADIR/system-branch.actual"
diff -u "$DATADIR/system-branch.actual" "$DATADIR/system-branch.reported"
IMPLEMENTS WHEN attempting to report system branch in (.*)
cd "$DATADIR/workspace/$MATCH_1"
attempt_morph show-system-branch
Report system branch root repository.
IMPLEMENTS WHEN reporting system branch root repository in (.*)
cd "$DATADIR/workspace/$MATCH_1"
run_morph show-branch-root > "$DATADIR/branch-root.reported"
IMPLEMENTS THEN root repository is reported as (.*)
echo "$MATCH_1" > "$DATADIR/branch-root.actual"
diff -u "$DATADIR/branch-root.actual" "$DATADIR/branch-root.reported"
IMPLEMENTS WHEN attempting to report system branch root repository in (.*)
cd "$DATADIR/workspace/$MATCH_1"
attempt_morph show-branch-root
Editing morphologies with `morph edit`.
IMPLEMENTS THEN in branch (\S+), system (\S+) refs (\S+) in (\S+)
"$SRCDIR/scripts/yaml-extract" \
"$DATADIR/workspace/$MATCH_1/test:morphs/$MATCH_2.morph" \
strata name="$MATCH_3" ref > "$DATADIR/ref.actual"
echo "$MATCH_4" > "$DATADIR/ref.wanted"
diff -u "$DATADIR/ref.wanted" "$DATADIR/ref.actual"
IMPLEMENTS THEN in branch (\S+), stratum (\S+) refs (\S+) in (\S+)
"$SRCDIR/scripts/yaml-extract" \
"$DATADIR/workspace/$MATCH_1/test:morphs/$MATCH_2.morph" \
chunks name="$MATCH_3" ref > "$DATADIR/ref.actual"
echo "$MATCH_4" > "$DATADIR/ref.wanted"
diff -u "$DATADIR/ref.wanted" "$DATADIR/ref.actual"
IMPLEMENTS WHEN editing stratum (\S+) in system (\S+) in branch (\S+)
cd "$DATADIR/workspace/$MATCH_3/test:morphs"
run_morph edit "$MATCH_2" "$MATCH_1"
IMPLEMENTS WHEN editing chunk (\S+) in (\S+) in (\S+) in branch (\S+)
cd "$DATADIR/workspace/$MATCH_4/test:morphs"
run_morph edit "$MATCH_3" "$MATCH_2" "$MATCH_1"
IMPLEMENTS THEN edited chunk (\S+) has git branch (\S+)
ls -l "$DATADIR/workspace/$MATCH_2"
cd "$DATADIR/workspace/$MATCH_2/$MATCH_1"
git branch | awk '$1 == "*" { print $2 }' > "$DATADIR/git-branch.actual"
echo "$MATCH_2" > "$DATADIR/git-branch.wanted"
diff -u "$DATADIR/git-branch.wanted" "$DATADIR/git-branch.actual"
Reporting status of checked out repositories:
IMPLEMENTS THEN morph reports no outstanding changes in (\S+)
cd "$DATADIR/workspace/$MATCH_1"
run_morph status > "$DATADIR/morph.stdout"
grep '^No repos have outstanding changes.' "$DATADIR/morph.stdout"
IMPLEMENTS THEN morph reports changes in (\S+) in (\S+) only
cd "$DATADIR/workspace/$MATCH_1"
run_morph status > "$DATADIR/morph.stdout"
# morph status is expected to produce records like this:
# On branch GITBRANCH, root baserock:baserock/morphs
# GITREPO: uncommitted changes
# We check thet GITREPO matches $MATCH_2.
awk '/: uncommitted changes$/ { print substr($1,1,length($1)-1) }' \
"$DATADIR/morph.stdout" > "$DATADIR/changed.actual"
echo "$MATCH_2" > "$DATADIR/changed.wanted"
diff -u "$DATADIR/changed.wanted" "$DATADIR/changed.actual"
IMPLEMENTS THEN morph reports changes in (\S+) in (\S+) and (\S+)
cd "$DATADIR/workspace/$MATCH_1"
run_morph status > "$DATADIR/morph.stdout"
echo "status morph.stdout:"
cat "$DATADIR/morph.stdout"
awk '/: uncommitted changes$/ { print substr($1,1,length($1)-1) }' \
"$DATADIR/morph.stdout" | sort > "$DATADIR/changed.actual"
(echo "$MATCH_2"; echo "$MATCH_3") | sort > "$DATADIR/changed.wanted"
diff -u "$DATADIR/changed.wanted" "$DATADIR/changed.actual"
IMPLEMENTS WHEN creating file (\S+) in (\S+) in branch (\S+)
touch "$DATADIR/workspace/$MATCH_3/$MATCH_2/$MATCH_1"
IMPLEMENTS WHEN adding file (\S+) in (\S+) in branch (\S+) to git
cd "$DATADIR/workspace/$MATCH_3/$MATCH_2"
git add "$MATCH_1"
IMPLEMENTS WHEN committing changes in (\S+) in branch (\S+)
cd "$DATADIR/workspace/$MATCH_2/$MATCH_1"
git commit -a -m test-commit
Running shell command in each checked out repository:
IMPLEMENTS WHEN running shell command in each repo in (\S+)
cd "$DATADIR/workspace/$MATCH_1"
run_morph foreach -- pwd > "$DATADIR/morph.stdout"
IMPLEMENTS THEN morph ran command in (\S+) in (\S+)
grep -Fx "$MATCH_1" "$DATADIR/morph.stdout"
grep -Fx "$DATADIR/workspace/$MATCH_2/$MATCH_1" "$DATADIR/morph.stdout"
Petrification and unpetrification:
IMPLEMENTS WHEN remembering all refs in (\S+)
cd "$DATADIR/workspace/$MATCH_1/test:morphs"
list_refs *.morph > "$DATADIR/refs.remembered"
IMPLEMENTS THEN (\S+) refs are as remembered
cd "$DATADIR/workspace/$MATCH_1/test:morphs"
# FIXME: petrify/unpetrify doesn't work quite right at this time:
# petrify can change a ref to a stratum to point at the system
# branch, but does it without adding an unpetrify-ref, and so
# unpetrify doesn't undo the change. We ignore this bug for the
# time being, in order to make the test suite pass. When the
# petrification code has been cleaned up to not be so hairy,
# we'll fix the test and the code.
#
# We would like to verify the result like this:
#
# list_refs *.morph > "$DATADIR/refs.now"
# diff -u "$DATADIR/refs.remembered" "$DATADIR/refs.now"
#
# However, due to the bug, we have to do it in a more complicated
# manner.
list_refs *.morph |
while read filename ref
do
orig=$(awk -v "f=$filename" '$1 == f { print $2 }' \
"$DATADIR/refs.remembered")
if [ "$orig" != "$ref" ] && [ "$ref" != "$MATCH_1" ]
then
die "Un-petrified ref: $filename $ref (should be $orig)"
fi
done
IMPLEMENTS WHEN petrifying (\S+)
cd "$DATADIR/workspace/$MATCH_1/test:morphs"
run_morph petrify
IMPLEMENTS WHEN unpetrifying (\S+)
cd "$DATADIR/workspace/$MATCH_1/test:morphs"
run_morph unpetrify
IMPLEMENTS THEN (\S+) is petrified
cd "$DATADIR/workspace/$MATCH_1/test:morphs"
assert_morphologies_are_petrified "$MATCH_1" *.morph
IMPLEMENTS THEN (\S+) is not petrified
cd "$DATADIR/workspace/$MATCH_1/test:morphs"
! assert_morphologies_are_petrified "$MATCH_1" *.morph
Tagging.
IMPLEMENTS WHEN tagging system branch (\S+) as (\S+)
cd "$DATADIR/workspace/$MATCH_1/test:morphs"
run_morph tag "$MATCH_2" -- -m "testing morph tagging"
IMPLEMENTS WHEN attempting to tag system branch (\S+) as (\S+)
cd "$DATADIR/workspace/$MATCH_1/test:morphs"
attempt_morph tag "$MATCH_2" -- -m "testing morph tagging"
IMPLEMENTS THEN morph tag (\S+) in (\S+) is an annotated git tag
cd "$DATADIR/workspace/$MATCH_2/test:morphs"
if git show "$MATCH_1" | head -n1 | grep -v '^tag '
then
die "git tag $MATCH_1 is not an annotated tag"
fi
IMPLEMENTS THEN morph tag (\S+) in (\S+) refers to a petrified commit
cd "$DATADIR/workspace/$MATCH_2/test:morphs"
git ls-tree "$MATCH_1" |
awk '$NF ~ /\.morph$/ { print $NF }' |
while read x
do
git cat-file blob "$MATCH_1:$x" > temptemptemp
assert_morphologies_are_petrified "$MATCH_1" temptemptemp
done
|