t1350: test topgit_deps_prepare.awk functionality
[topgit/pro.git] / t / t1350-awk-topgit_deps_prepare.sh
blob1e961e826c2518a6c3594164e16206aabe983594
1 #!/bin/sh
3 test_description='topgit_deps_prepare.awk functionality'
5 TEST_NO_CREATE_REPO=1
7 . ./test-lib.sh
9 ap="$(tg --awk-path)" && test -n "$ap" && test -d "$ap" || die
10 aptdp="$ap/topgit_deps_prepare"
11 test -f "$aptdp" && test -r "$aptdp" && test -x "$aptdp" || die
13 # Example use of topgit_deps_prepare:
15 # $ printf "%s\n" "refs/heads/{top-bases}/t/sample" |
16 # awk -f "$(tg --awk-path)/ref_prepare" \
17 # -v "topbases=refs/heads/{top-bases}" \
18 # -v "chkblob=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391" -v "depsblob=1" |
19 # tee /dev/stderr |
20 # git cat-file --batch-check="%(objectname) %(objecttype) %(rest)" |
21 # tee /dev/stderr |
22 # awk -f "$(tg --awk-path)/topgit_deps_prepare" \
23 # -v "missing=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"
25 # e69de29bb2d1d6434b8b29ae775ad8c2e48c5391^{blob} check ?
26 # refs/heads/{top-bases}/t/sample t/sample :
27 # refs/heads/{top-bases}/t/sample^0
28 # refs/heads/t/sample^0
29 # refs/heads/{top-bases}/t/sample^{tree}
30 # refs/heads/t/sample^{tree}
31 # refs/heads/t/sample^{tree}:.topdeps
33 # e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 blob check ?
34 # c9f100930c289c97b21ad9b1a8145754d0543e72 commit t/sample :
35 # c9f100930c289c97b21ad9b1a8145754d0543e72 commit
36 # e999108a1ccecd83c8a0f83f1cb2d84053abc282 commit
37 # 3208ec7914a3bcb6da4ba32f54b2457d5ffd64fa tree
38 # 3431161db7d2a5adfcba4d91bcf81d10e5b432b2 tree
39 # 2ccee31ddc46c17d0aff9187a8e2d7fd9cfeaa47 blob
41 # 2ccee31ddc46c17d0aff9187a8e2d7fd9cfeaa47 t/sample
43 # Note that topgit_deps_prepare does not concern itself with the actual value
44 # of any of the hashes (other than for equality testing), but it does care
45 # about object types and whether things are "missing" or not.
47 # It also doesn't detect obviously corrupt input (both commits are the same
48 # but their trees are not).
50 test_plan 22
52 chkmb="checkblob"
53 cat <<-EOT >"$chkmb"
54 12345678 blob check ?
55 EOT
57 cmd0="cmd0"
58 cat <<-EOT >"$cmd0" || die
59 10000000 whatever cmd0 :
60 10000002 commit
61 10000003 commit
62 10000004 tree
63 10000005 tree
64 10000006 blob
65 EOT
66 echo "10000006 cmd0" >"$cmd0.out" || die
67 echo "cmd0" >"$cmd0.br" || die
69 cmd1="cmd1"
70 cat <<-EOT >"$cmd1" || die
71 10000000 whatever cmd1 :
72 10000002 commit
73 10000003 commit
74 10000004 tree
75 10000005 tree
76 10000006 missing
77 EOT
79 cmd2="cmd2"
80 cat <<-EOT >"$cmd2" || die
81 10000000 whatever cmd2 :
82 10000002 commit
83 10000003 commit
84 10000004 tree
85 10000004 tree
86 10000006 missing
87 EOT
89 mt_base="one-rather-lengthy-and-unlikely-blob-name-for-sure"
91 test_expect_success 'test setup' '
92 branch_base="some-very-long-branch-base-name-goes-here-for-sure" &&
93 bn=10000000 &&
94 >biginput && >bigoutput && >bigbrfile &&
95 i=1 && while i=$(($i + 10)) && test $i -le 10000; do
96 printf "%08d whatever %s-%d :\n" $(( $bn + $i )) "$branch_base" $(( $bn + $i )) >>biginput &&
97 printf "%08d commit\n" $(( $bn + $i + 1 )) >>biginput &&
98 printf "%08d commit\n" $(( $bn + $i + 2 )) >>biginput &&
99 printf "%08d tree\n" $(( $bn + $i + 3 )) >>biginput &&
100 printf "%08d tree\n" $(( $bn + $i + 3 )) >>biginput &&
101 printf "%08d blob\n" $(( $bn + $i + 4 )) >>biginput &&
102 printf "%s-%d\n" "$branch_base" $(( $bn + $i )) >>bigbrfile &&
103 printf "%s^{blob} %s-%d\n" "$mt_base" "$branch_base" $(( $bn + $i )) >>bigoutput
104 done &&
105 cat bigbrfile bigoutput >bigcombined
108 test_expect_success 'topgit_deps_prepare runs' '
109 # some stupid awks might not even compile it
110 awk -f "$aptdp" </dev/null &&
111 # and make sure various file arg combinations are accepted
112 awk -f "$aptdp" </dev/null -v brfile=brfile && rm -f brfile &&
113 awk -f "$aptdp" </dev/null -v anfile=anfile && rm -f anfile &&
114 awk -f "$aptdp" </dev/null -v brfile=brfile -v anfile=anfile
117 test_expect_success 'output files always truncated' '
118 echo brfile > brfile && test -s brfile &&
119 echo anfile > anfile && test -s anfile &&
120 awk -f "$aptdp" </dev/null -v brfile=brfile -v anfile=anfile &&
121 test ! -s brfile &&
122 test ! -s anfile
125 capture() {
126 IFS= read -r line || return &&
127 cat "$1" >"$2" &&
128 printf '%s\n' "$line" >>"$2" &&
129 cat >>"$2"
132 test_expect_success 'output brfile ordering' '
133 >result &&
134 awk -f "$aptdp" <biginput -v missing="$mt_base" -v brfile=brfile | capture brfile result &&
135 test_cmp result bigcombined
138 test_expect_success 'output anfile ordering' '
139 >result &&
140 awk -f "$aptdp" <biginput -v missing="$mt_base" -v anfile=anfile | capture anfile result &&
141 test_cmp result bigcombined
144 test_expect_success 'anfile only' '
145 awk -f "$aptdp" <biginput -v anfile=anlist >out &&
146 test ! -s out && test_cmp anlist bigbrfile
149 test_expect_success 'anfile only one out' '
150 cat "$cmd0" biginput | awk -f "$aptdp" -v anfile=anlist >out &&
151 test_cmp out "$cmd0.out" && test_cmp anlist bigbrfile
154 test_expect_success 'noann=1 empty brfile' '
155 awk -f "$aptdp" <biginput -v noann=1 -v brfile=brlist >out &&
156 test ! -s out && test -e brlist && test ! -s brlist
159 test_expect_success 'one in brfile only' '
160 cat "$cmd0" biginput | awk -f "$aptdp" -v noann=1 -v brfile=brlist >out &&
161 test_cmp out "$cmd0.out" && test_cmp brlist "$cmd0.br"
164 test_expect_success 'brfile only' '
165 awk -f "$aptdp" <biginput -v brfile=brlist >out &&
166 test ! -s out && test_cmp brlist bigbrfile
169 test_expect_success 'anfile and noann=1 empty brfile' '
170 awk -f "$aptdp" <biginput -v noann=1 -v anfile=anlist -v brfile=brlist >out &&
171 test ! -s out && test_cmp anlist bigbrfile && test -e brlist && test ! -s brlist
174 test_expect_success 'anfile and one in brfile' '
175 cat "$cmd0" biginput | awk -f "$aptdp" -v noann=1 -v anfile=anlist -v brfile=brlist >out &&
176 test_cmp out "$cmd0.out" && test_cmp anlist bigbrfile && test_cmp brlist "$cmd0.br"
179 # The only kind of "bad" input that's detected is not enough lines after
180 # the starting 4-field ':' line
181 test_expect_success 'bad input detected' '
182 echo "0001 commit branch :" >input &&
183 test_must_fail awk -f "$aptdp" <input &&
184 echo "0002 commit" >>input &&
185 test_must_fail awk -f "$aptdp" <input &&
186 echo "0003 commit" >>input &&
187 test_must_fail awk -f "$aptdp" <input &&
188 echo "0004 tree" >>input &&
189 test_must_fail awk -f "$aptdp" <input &&
190 echo "0005 tree" >>input &&
191 test_must_fail awk -f "$aptdp" <input &&
192 echo "0006 blob" >>input &&
193 awk -f "$aptdp" <input &&
194 echo "0007 blob" >>input &&
195 awk -f "$aptdp" <input
198 test_expect_success 'missing command does not run' '
199 rm -f run* &&
200 awk -f "$aptdp" <"$cmd0" -v misscmd="echo r0>>run0" >out &&
201 test_cmp "$cmd0.out" out && test ! -e run0 &&
202 awk -f "$aptdp" <"$cmd1" -v misscmd="echo r1>>run1" >out &&
203 test ! -s out && test ! -e run1 &&
204 awk -f "$aptdp" <"$cmd2" -v misscmd="echo r2>>run2" >out &&
205 awk -f "$aptdp" <"$cmd2" -v noann=1 -v missing=other -v misscmd="echo r2>>run2" >>out &&
206 test ! -s out && test ! -e run2 &&
207 cat "$chkmb" "$cmd0" | awk -f "$aptdp" -v missing=12345678 -v misscmd="echo r0>>run0" >outa &&
208 cat "$chkmb" "$cmd0" | awk -f "$aptdp" -v missing=other -v misscmd="echo r0>>run0" >outb &&
209 test_cmp "$cmd0.out" outa && test_cmp "$cmd0.out" outb && test ! -e run0 &&
210 echo "12345678^{blob} cmd1" >expected &&
211 cat "$chkmb" "$cmd1" | awk -f "$aptdp" -v missing=12345678 -v misscmd="echo r1>>run1" >out &&
212 test ! -e run1 && test_cmp out expected &&
213 echo "12345678^{blob} cmd2" >expected &&
214 cat "$chkmb" "$cmd2" | awk -f "$aptdp" -v missing=12345678 -v misscmd="echo r2>>run2" >out &&
215 test ! -e run2 && test_cmp out expected
218 test_expect_success 'missing command does run' '
219 rm -f run* &&
220 <"$cmd1" awk -f "$aptdp" -v missing=12345678 -v misscmd="echo r1>>run1" &&
221 test -s run1 && read -r l <run1 && test "$l" = "r1" &&
222 <"$cmd2" awk -f "$aptdp" -v missing=12345678 -v misscmd="echo r2>>run2" &&
223 test -s run2 && read -r l <run2 && test "$l" = "r2"
226 test_expect_success 'missing command runs once' '
227 rm -f run* &&
228 cat "$cmd1" "$cmd2" | awk -f "$aptdp" -v missing=12345678 -v misscmd="echo r1>>run1" &&
229 echo "r1" >expected &&
230 test -s run1 && test_cmp run1 expected
233 test_expect_success 'none out' '
234 <biginput awk -f "$aptdp" >out &&
235 test ! -s out
238 test_expect_success 'none out noann=1' '
239 <biginput awk -f "$aptdp" -v noann=1 -v missing=other >out &&
240 test ! -s out
243 test_expect_success 'only one out' '
244 <"$cmd0" awk -f "$aptdp" >out &&
245 test_cmp out "$cmd0.out"
248 test_expect_success 'only one out of many' '
249 cat "$cmd0" biginput | awk -f "$aptdp" >out &&
250 test_cmp out "$cmd0.out"
253 test_expect_success 'only one out of many noann=1' '
254 cat "$cmd0" biginput | awk -f "$aptdp" -v noann=1 -v missing=other >out &&
255 test_cmp out "$cmd0.out"
258 test_expect_success 'many out' '
259 <biginput awk -f "$aptdp" -v "missing=$mt_base" >out &&
260 test_cmp out bigoutput
263 test_done