3 test_description
='ref_prefixes.awk functionality'
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
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' '
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' '
27 awk -v prefix1="refs/a" -v prefix2="refs/b" -f "$aprp" <<-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
40 test_expect_success
'ref_prefixes bad usage' '
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' '
63 " && val="$(test_expect_code 66 awk -v prefix1="refs/x" -v prefix2="refs/y" -v nodef=1 -f "$aprp" <input)" &&
67 test_expect_success
'ref_prefixes no matches with default' '
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' '
91 " && val="$(test_expect_code 65 awk -v prefix1="refs/l" -v prefix2="refs/n" -f "$aprp" <input)" &&
95 test_expect_success
'ref_prefixes two matches use default' '
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" "\
121 " && val="$(test_expect_code 65 awk -v prefix1="refs/l" -v prefix2="refs/n" -v prefixh="refs/h" -f "$aprp" <input)" &&
125 test_expect_success
'ref_prefixes two matches with prefixh use default' '
126 printf >input "%s" "\
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" "\
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" "\
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)" &&
169 test_expect_success
'ref_prefixes matches with pckdrefs format' '
170 printf >input "%s" "\
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"