various: use "command" instead of "subcommand"
[topgit/pro.git] / t / t1310-awk-ref_prefixes.sh
blob06913bc204cfee55b1b80a0ec447256d3f3d9f24
1 #!/bin/sh
3 test_description='ref_prefixes.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 aprp="$ap/ref_prefixes"
11 test -f "$aprp" && test -r "$aprp" && test -x "$aprp" || die
13 test_plan 14
15 test_expect_success 'ref_prefixes runs' '
16 # some stupid awks might not even compile it
17 awk -v prefix1="refs/a" -v prefix2="refs/b" -f "$aprp" </dev/null
20 test_expect_success 'ref_prefixes exit 66' '
21 test_expect_code 66 \
22 awk -v prefix1="refs/a" -v prefix2="refs/b" -v nodef=1 -f "$aprp" </dev/null
25 test_expect_success 'ref_prefixes exit 65' '
26 test_expect_code 65 \
27 awk -v prefix1="refs/a" -v prefix2="refs/b" -f "$aprp" <<-EOT
28 refs/a/1
29 refs/b/1
30 EOT
33 test_expect_success 'ref_prefixes exit noerr 65' '
34 awk -v prefix1="refs/a" -v prefix2="refs/b" -v noerr=1 -f "$aprp" <<-EOT
35 refs/a/1
36 refs/b/1
37 EOT
40 test_expect_success 'ref_prefixes bad usage' '
41 exec 0</dev/null &&
42 test_must_fail awk -f "$aprp" &&
43 test_must_fail awk -v prefix1="refs/a" -f "$aprp" &&
44 test_must_fail awk -v prefix2="refs/b" -f "$aprp" &&
45 test_must_fail awk -v prefix1="refs/a" -v prefix2="refs/a" -f "$aprp" &&
46 test_must_fail awk -v prefix1="refs/a" -v prefix2="refs/b" -v prefixh="refs/a" -f "$aprp" &&
47 test_must_fail awk -v prefix1="refs/a" -v prefix2="refs/b" -v prefixh="refs/b" -f "$aprp" &&
48 test_must_fail awk -v prefix1="refx/a" -v prefix2="refs/b" -v prefixh="refs/c" -f "$aprp" &&
49 test_must_fail awk -v prefix1="refs/a" -v prefix2="refx/b" -v prefixh="refs/c" -f "$aprp" &&
50 test_must_fail awk -v prefix1="refs/a" -v prefix2="refs/b" -v prefixh="refx/c" -f "$aprp"
53 test_expect_success 'ref_prefixes no matches no default' '
54 printf >input "%s" "\
55 refs/l/a 000A
56 refs/n/1 000a
57 refs/l/b 000b
58 refs/l/a 000A
59 refs/n/3 0003
60 refs/l/c 000C
61 refs/n/2 0002
62 refs/l/b 000B
63 " && val="$(test_expect_code 66 awk -v prefix1="refs/x" -v prefix2="refs/y" -v nodef=1 -f "$aprp" <input)" &&
64 test z"$val" = z""
67 test_expect_success 'ref_prefixes no matches with default' '
68 printf >input "%s" "\
69 refs/l/a 000A
70 refs/n/1 000a
71 refs/l/b 000b
72 refs/l/a 000A
73 refs/n/3 0003
74 refs/l/c 000C
75 refs/n/2 0002
76 refs/l/b 000B
77 " && val="$(awk -v prefix1="refs/x" -v prefix2="refs/y" -f "$aprp" <input)" &&
78 test z"$val" = z"refs/x"
81 test_expect_success 'ref_prefixes two matches with error' '
82 printf >input "%s" "\
83 refs/l/a 000A
84 refs/n/1 000a
85 refs/l/b 000b
86 refs/l/a 000A
87 refs/n/3 0003
88 refs/l/c 000C
89 refs/n/2 0002
90 refs/l/b 000B
91 " && val="$(test_expect_code 65 awk -v prefix1="refs/l" -v prefix2="refs/n" -f "$aprp" <input)" &&
92 test z"$val" = z""
95 test_expect_success 'ref_prefixes two matches use default' '
96 printf >input "%s" "\
97 refs/l/a 000A
98 refs/n/1 000a
99 refs/l/b 000b
100 refs/l/a 000A
101 refs/n/3 0003
102 refs/l/c 000C
103 refs/n/2 0002
104 refs/l/b 000B
105 " && val="$(awk -v prefix1="refs/n" -v prefix2="refs/l" -v noerr=1 -f "$aprp" <input)" &&
106 test z"$val" = z"refs/n"
109 test_expect_success 'ref_prefixes two matches with prefixh with error' '
110 printf >input "%s" "\
111 refs/l/a 000A
112 refs/n/1 000a
113 refs/l/b 000b
114 refs/l/a 000A
115 refs/n/3 0003
116 refs/l/c 000C
117 refs/n/2 0002
118 refs/l/b 000B
119 refs/h/b 0123
120 refs/h/2 0123
121 " && val="$(test_expect_code 65 awk -v prefix1="refs/l" -v prefix2="refs/n" -v prefixh="refs/h" -f "$aprp" <input)" &&
122 test z"$val" = z""
125 test_expect_success 'ref_prefixes two matches with prefixh use default' '
126 printf >input "%s" "\
127 refs/l/a 000A
128 refs/n/1 000a
129 refs/l/b 000b
130 refs/l/a 000A
131 refs/n/3 0003
132 refs/l/c 000C
133 refs/n/2 0002
134 refs/l/b 000B
135 refs/h/b 0123
136 refs/h/2 0123
137 " && val="$(awk -v prefix1="refs/l" -v prefix2="refs/n" -v prefixh="refs/h" -v noerr=1 -f "$aprp" <input)" &&
138 test z"$val" = z"refs/l"
141 test_expect_success 'ref_prefixes no matches without prefixh use default' '
142 printf >input "%s" "\
143 refs/l/a 000A
144 refs/n/1 000a
145 refs/l/b 000b
146 refs/l/a 000A
147 refs/n/3 0003
148 refs/l/c 000C
149 refs/n/2 0002
150 refs/l/b 000B
151 " && val="$(awk -v prefix1="refs/l" -v prefix2="refs/n" -v prefixh="refs/h" -f "$aprp" <input)" &&
152 test z"$val" = z"refs/l"
155 test_expect_success 'ref_prefixes no matches without prefixh no default' '
156 printf >input "%s" "\
157 refs/l/a 000A
158 refs/n/1 000a
159 refs/l/b 000b
160 refs/l/a 000A
161 refs/n/3 0003
162 refs/l/c 000C
163 refs/n/2 0002
164 refs/l/b 000B
165 " && val="$(test_expect_code 66 awk -v prefix1="refs/n" -v prefix2="refs/l" -v prefixh="refs/h" -v nodef=1 -f "$aprp" <input)" &&
166 test z"$val" = z""
169 test_expect_success 'ref_prefixes matches with pckdrefs format' '
170 printf >input "%s" "\
171 000A refs/l/a
172 000a refs/n/1
173 000b refs/l/b
174 000A refs/l/a
175 0003 refs/n/3
176 000C refs/l/c
177 0002 refs/n/2
178 000B refs/l/b
179 0123 refs/h/2
180 " && val="$(awk -v prefix1="refs/l" -v prefix2="refs/n" -v prefixh="refs/h" -v pckdrefs=1 -f "$aprp" <input)" &&
181 test z"$val" = z"refs/n"
184 test_done