Skip to content

Commit 1490e15

Browse files
committed
Add some basic assertions to test.sh.
1 parent 0ad3dd8 commit 1490e15

File tree

1 file changed

+72
-1
lines changed

1 file changed

+72
-1
lines changed

test.sh

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash -x
1+
#!/bin/bash
22
. shellopts.sh
33
set -e
44

@@ -8,6 +8,50 @@ create()
88
git add "$1"
99
}
1010

11+
check()
12+
{
13+
echo
14+
echo "check:" "$@"
15+
if "$@"; then
16+
echo ok
17+
return 0
18+
else
19+
echo FAILED
20+
exit 1
21+
fi
22+
}
23+
24+
check_equal()
25+
{
26+
echo
27+
echo "check a:" "$1"
28+
echo " b:" "$2"
29+
if [ "$1" = "$2" ]; then
30+
return 0
31+
else
32+
echo FAILED
33+
exit 1
34+
fi
35+
}
36+
37+
fixnl()
38+
{
39+
t=""
40+
while read x; do
41+
t="$t$x "
42+
done
43+
echo $t
44+
}
45+
46+
multiline()
47+
{
48+
while read x; do
49+
set -- $x
50+
for d in "$@"; do
51+
echo "$d"
52+
done
53+
done
54+
}
1155

1256
rm -rf mainline subproj
1357
mkdir mainline subproj
@@ -19,6 +63,7 @@ create sub1
1963
git commit -m 'sub1'
2064
git branch sub1
2165
git branch -m master subproj
66+
check true
2267

2368
create sub2
2469
git commit -m 'sub2'
@@ -86,7 +131,33 @@ git branch split3 FETCH_HEAD
86131
git merge FETCH_HEAD
87132
git branch subproj-merge-split3
88133

134+
chkm="main4 main6"
135+
chkms="main-sub10 main-sub5 main-sub7 main-sub8"
136+
chkms_sub=$(echo $chkms | multiline | sed 's,^,subdir/,' | fixnl)
137+
chks="sub1 sub2 sub3 sub9"
138+
chks_sub=$(echo $chks | multiline | sed 's,^,subdir/,' | fixnl)
139+
140+
# make sure exactly the right set of files ends up in the subproj
141+
subfiles=$(git ls-files | fixnl)
142+
check_equal "$subfiles" "$chkms $chks"
143+
144+
# make sure the subproj history *only* contains commits that affect the subdir.
145+
allchanges=$(git log --name-only --pretty=format:'' | sort | fixnl)
146+
check_equal "$allchanges" "$chkms $chks"
147+
89148
cd ../mainline
90149
git fetch ../subproj subproj-merge-split3
91150
git branch subproj-merge-split3 FETCH_HEAD
92151
git subtree pull --prefix=subdir ../subproj subproj-merge-split3
152+
153+
# make sure exactly the right set of files ends up in the mainline
154+
mainfiles=$(git ls-files | fixnl)
155+
check_equal "$mainfiles" "$chkm $chkms_sub $chks_sub"
156+
157+
# make sure each filename changed exactly once in the entire history.
158+
# 'main-sub??' and '/subdir/main-sub??' both change, because those are the
159+
# changes that were split into their own history. And 'subdir/sub??' never
160+
# change, since they were *only* changed in the subtree branch.
161+
allchanges=$(git log --name-only --pretty=format:'' | sort | fixnl)
162+
check_equal "$allchanges" "$chkm $chkms $chks $chkms_sub"
163+

0 commit comments

Comments
 (0)