Add some basic assertions to test.sh.
Avery Pennarun committed
Apr 26, 2009 at 16:28 UTC
1490e1546a380814fdd68dc3776023e58da60d48
1 file changed
+72
-1
test.sh
+72
-1
@@ -1,4 +1,4 @@
1
-#!/bin/bash -x
1
+#!/bin/bash
2
. shellopts.sh
3
set -e
4
@@ -8,6 +8,50 @@ create()
8
git add "$1"
9
}
10
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
+}
55
56
rm -rf mainline subproj
57
mkdir mainline subproj
@@ -19,6 +63,7 @@ create sub1
63
git commit -m 'sub1'
64
git branch sub1
65
git branch -m master subproj
66
+check true
67
68
create sub2
69
git commit -m 'sub2'
@@ -86,7 +131,33 @@ git branch split3 FETCH_HEAD
131
git merge FETCH_HEAD
132
git branch subproj-merge-split3
133
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
+
148
cd ../mainline
149
git fetch ../subproj subproj-merge-split3
150
git branch subproj-merge-split3 FETCH_HEAD
151
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
+