Ref normalization test helpers now doing internal asserts.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
diff --git a/tests-clar/refs/normalize.c b/tests-clar/refs/normalize.c
index 49bc9ac..b10bda6 100644
--- a/tests-clar/refs/normalize.c
+++ b/tests-clar/refs/normalize.c
@@ -6,26 +6,27 @@
// Helpers
-static int ensure_refname_normalized(int is_oid_ref, const char *input_refname, const char *expected_refname)
+static void ensure_refname_normalized(int is_oid_ref, const char *input_refname, const char *expected_refname)
{
- int error = GIT_SUCCESS;
char buffer_out[GIT_REFNAME_MAX];
if (is_oid_ref)
- error = git_reference__normalize_name_oid(buffer_out, sizeof(buffer_out), input_refname);
+ cl_git_pass(git_reference__normalize_name_oid(buffer_out, sizeof(buffer_out), input_refname));
else
- error = git_reference__normalize_name(buffer_out, sizeof(buffer_out), input_refname);
+ cl_git_pass(git_reference__normalize_name(buffer_out, sizeof(buffer_out), input_refname));
- if (error < GIT_SUCCESS)
- return error;
-
- if (expected_refname == NULL)
- return error;
+ if (expected_refname)
+ cl_assert(0 == strcmp(buffer_out, expected_refname));
+}
- if (strcmp(buffer_out, expected_refname))
- error = GIT_ERROR;
+static void ensure_refname_invalid(int is_oid_ref, const char *input_refname)
+{
+ char buffer_out[GIT_REFNAME_MAX];
- return error;
+ if (is_oid_ref)
+ cl_git_fail(git_reference__normalize_name_oid(buffer_out, sizeof(buffer_out), input_refname));
+ else
+ cl_git_fail(git_reference__normalize_name(buffer_out, sizeof(buffer_out), input_refname));
}
#define OID_REF 1
@@ -36,35 +37,35 @@ static int ensure_refname_normalized(int is_oid_ref, const char *input_refname,
void test_refs_normalize__direct(void)
{
// normalize a direct (OID) reference name
- cl_git_fail(ensure_refname_normalized(OID_REF, "a", NULL));
- cl_git_fail(ensure_refname_normalized(OID_REF, "", NULL));
- cl_git_fail(ensure_refname_normalized(OID_REF, "refs/heads/a/", NULL));
- cl_git_fail(ensure_refname_normalized(OID_REF, "refs/heads/a.", NULL));
- cl_git_fail(ensure_refname_normalized(OID_REF, "refs/heads/a.lock", NULL));
- cl_git_pass(ensure_refname_normalized(OID_REF, "refs/dummy/a", NULL));
- cl_git_pass(ensure_refname_normalized(OID_REF, "refs/stash", NULL));
- cl_git_pass(ensure_refname_normalized(OID_REF, "refs/tags/a", "refs/tags/a"));
- cl_git_pass(ensure_refname_normalized(OID_REF, "refs/heads/a/b", "refs/heads/a/b"));
- cl_git_pass(ensure_refname_normalized(OID_REF, "refs/heads/a./b", "refs/heads/a./b"));
- cl_git_fail(ensure_refname_normalized(OID_REF, "refs/heads/foo?bar", NULL));
- cl_git_fail(ensure_refname_normalized(OID_REF, "refs/heads\foo", NULL));
- cl_git_pass(ensure_refname_normalized(OID_REF, "refs/heads/v@ation", "refs/heads/v@ation"));
- cl_git_pass(ensure_refname_normalized(OID_REF, "refs///heads///a", "refs/heads/a"));
- cl_git_fail(ensure_refname_normalized(OID_REF, "refs/heads/.a/b", NULL));
- cl_git_fail(ensure_refname_normalized(OID_REF, "refs/heads/foo/../bar", NULL));
- cl_git_fail(ensure_refname_normalized(OID_REF, "refs/heads/foo..bar", NULL));
- cl_git_fail(ensure_refname_normalized(OID_REF, "refs/heads/./foo", NULL));
- cl_git_fail(ensure_refname_normalized(OID_REF, "refs/heads/v@{ation", NULL));
+ ensure_refname_invalid(OID_REF, "a");
+ ensure_refname_invalid(OID_REF, "");
+ ensure_refname_invalid(OID_REF, "refs/heads/a/");
+ ensure_refname_invalid(OID_REF, "refs/heads/a.");
+ ensure_refname_invalid(OID_REF, "refs/heads/a.lock");
+ ensure_refname_normalized(OID_REF, "refs/dummy/a", NULL);
+ ensure_refname_normalized(OID_REF, "refs/stash", NULL);
+ ensure_refname_normalized(OID_REF, "refs/tags/a", "refs/tags/a");
+ ensure_refname_normalized(OID_REF, "refs/heads/a/b", "refs/heads/a/b");
+ ensure_refname_normalized(OID_REF, "refs/heads/a./b", "refs/heads/a./b");
+ ensure_refname_invalid(OID_REF, "refs/heads/foo?bar");
+ ensure_refname_invalid(OID_REF, "refs/heads\foo");
+ ensure_refname_normalized(OID_REF, "refs/heads/v@ation", "refs/heads/v@ation");
+ ensure_refname_normalized(OID_REF, "refs///heads///a", "refs/heads/a");
+ ensure_refname_invalid(OID_REF, "refs/heads/.a/b");
+ ensure_refname_invalid(OID_REF, "refs/heads/foo/../bar");
+ ensure_refname_invalid(OID_REF, "refs/heads/foo..bar");
+ ensure_refname_invalid(OID_REF, "refs/heads/./foo");
+ ensure_refname_invalid(OID_REF, "refs/heads/v@{ation");
}
void test_refs_normalize__symbolic(void)
{
// normalize a symbolic reference name
- cl_git_pass(ensure_refname_normalized(SYM_REF, "a", "a"));
- cl_git_pass(ensure_refname_normalized(SYM_REF, "a/b", "a/b"));
- cl_git_pass(ensure_refname_normalized(SYM_REF, "refs///heads///a", "refs/heads/a"));
- cl_git_fail(ensure_refname_normalized(SYM_REF, "", NULL));
- cl_git_fail(ensure_refname_normalized(SYM_REF, "heads\foo", NULL));
+ ensure_refname_normalized(SYM_REF, "a", "a");
+ ensure_refname_normalized(SYM_REF, "a/b", "a/b");
+ ensure_refname_normalized(SYM_REF, "refs///heads///a", "refs/heads/a");
+ ensure_refname_invalid(SYM_REF, "");
+ ensure_refname_invalid(SYM_REF, "heads\foo");
}
/* Ported from JGit, BSD licence.
@@ -74,31 +75,31 @@ void test_refs_normalize__jgit_suite(void)
// tests borrowed from JGit
/* EmptyString */
- cl_git_fail(ensure_refname_normalized(SYM_REF, "", NULL));
- cl_git_fail(ensure_refname_normalized(SYM_REF, "/", NULL));
+ ensure_refname_invalid(SYM_REF, "");
+ ensure_refname_invalid(SYM_REF, "/");
/* MustHaveTwoComponents */
- cl_git_fail(ensure_refname_normalized(OID_REF, "master", NULL));
- cl_git_pass(ensure_refname_normalized(SYM_REF, "heads/master", "heads/master"));
+ ensure_refname_invalid(OID_REF, "master");
+ ensure_refname_normalized(SYM_REF, "heads/master", "heads/master");
/* ValidHead */
- cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/master", "refs/heads/master"));
- cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/pu", "refs/heads/pu"));
- cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/z", "refs/heads/z"));
- cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/FoO", "refs/heads/FoO"));
+ ensure_refname_normalized(SYM_REF, "refs/heads/master", "refs/heads/master");
+ ensure_refname_normalized(SYM_REF, "refs/heads/pu", "refs/heads/pu");
+ ensure_refname_normalized(SYM_REF, "refs/heads/z", "refs/heads/z");
+ ensure_refname_normalized(SYM_REF, "refs/heads/FoO", "refs/heads/FoO");
/* ValidTag */
- cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/tags/v1.0", "refs/tags/v1.0"));
+ ensure_refname_normalized(SYM_REF, "refs/tags/v1.0", "refs/tags/v1.0");
/* NoLockSuffix */
- cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master.lock", NULL));
+ ensure_refname_invalid(SYM_REF, "refs/heads/master.lock");
/* NoDirectorySuffix */
- cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master/", NULL));
+ ensure_refname_invalid(SYM_REF, "refs/heads/master/");
/* NoSpace */
- cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/i haz space", NULL));
+ ensure_refname_invalid(SYM_REF, "refs/heads/i haz space");
/* NoAsciiControlCharacters */
{
@@ -109,89 +110,89 @@ void test_refs_normalize__jgit_suite(void)
strncpy(buffer + 15, (const char *)&c, 1);
strncpy(buffer + 16, "er", 2);
buffer[18 - 1] = '\0';
- cl_git_fail(ensure_refname_normalized(SYM_REF, buffer, NULL));
+ ensure_refname_invalid(SYM_REF, buffer);
}
}
/* NoBareDot */
- cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/.", NULL));
- cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/..", NULL));
- cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/./master", NULL));
- cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/../master", NULL));
+ ensure_refname_invalid(SYM_REF, "refs/heads/.");
+ ensure_refname_invalid(SYM_REF, "refs/heads/..");
+ ensure_refname_invalid(SYM_REF, "refs/heads/./master");
+ ensure_refname_invalid(SYM_REF, "refs/heads/../master");
/* NoLeadingOrTrailingDot */
- cl_git_fail(ensure_refname_normalized(SYM_REF, ".", NULL));
- cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/.bar", NULL));
- cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/..bar", NULL));
- cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/bar.", NULL));
+ ensure_refname_invalid(SYM_REF, ".");
+ ensure_refname_invalid(SYM_REF, "refs/heads/.bar");
+ ensure_refname_invalid(SYM_REF, "refs/heads/..bar");
+ ensure_refname_invalid(SYM_REF, "refs/heads/bar.");
/* ContainsDot */
- cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/m.a.s.t.e.r", "refs/heads/m.a.s.t.e.r"));
- cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master..pu", NULL));
+ ensure_refname_normalized(SYM_REF, "refs/heads/m.a.s.t.e.r", "refs/heads/m.a.s.t.e.r");
+ ensure_refname_invalid(SYM_REF, "refs/heads/master..pu");
/* NoMagicRefCharacters */
- cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master^", NULL));
- cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/^master", NULL));
- cl_git_fail(ensure_refname_normalized(SYM_REF, "^refs/heads/master", NULL));
+ ensure_refname_invalid(SYM_REF, "refs/heads/master^");
+ ensure_refname_invalid(SYM_REF, "refs/heads/^master");
+ ensure_refname_invalid(SYM_REF, "^refs/heads/master");
- cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master~", NULL));
- cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/~master", NULL));
- cl_git_fail(ensure_refname_normalized(SYM_REF, "~refs/heads/master", NULL));
+ ensure_refname_invalid(SYM_REF, "refs/heads/master~");
+ ensure_refname_invalid(SYM_REF, "refs/heads/~master");
+ ensure_refname_invalid(SYM_REF, "~refs/heads/master");
- cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master:", NULL));
- cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/:master", NULL));
- cl_git_fail(ensure_refname_normalized(SYM_REF, ":refs/heads/master", NULL));
+ ensure_refname_invalid(SYM_REF, "refs/heads/master:");
+ ensure_refname_invalid(SYM_REF, "refs/heads/:master");
+ ensure_refname_invalid(SYM_REF, ":refs/heads/master");
/* ShellGlob */
- cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master?", NULL));
- cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/?master", NULL));
- cl_git_fail(ensure_refname_normalized(SYM_REF, "?refs/heads/master", NULL));
+ ensure_refname_invalid(SYM_REF, "refs/heads/master?");
+ ensure_refname_invalid(SYM_REF, "refs/heads/?master");
+ ensure_refname_invalid(SYM_REF, "?refs/heads/master");
- cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master[", NULL));
- cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/[master", NULL));
- cl_git_fail(ensure_refname_normalized(SYM_REF, "[refs/heads/master", NULL));
+ ensure_refname_invalid(SYM_REF, "refs/heads/master[");
+ ensure_refname_invalid(SYM_REF, "refs/heads/[master");
+ ensure_refname_invalid(SYM_REF, "[refs/heads/master");
- cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master*", NULL));
- cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/*master", NULL));
- cl_git_fail(ensure_refname_normalized(SYM_REF, "*refs/heads/master", NULL));
+ ensure_refname_invalid(SYM_REF, "refs/heads/master*");
+ ensure_refname_invalid(SYM_REF, "refs/heads/*master");
+ ensure_refname_invalid(SYM_REF, "*refs/heads/master");
/* ValidSpecialCharacters */
- cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/!", "refs/heads/!"));
- cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/\"", "refs/heads/\""));
- cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/#", "refs/heads/#"));
- cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/$", "refs/heads/$"));
- cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/%", "refs/heads/%"));
- cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/&", "refs/heads/&"));
- cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/'", "refs/heads/'"));
- cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/(", "refs/heads/("));
- cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/)", "refs/heads/)"));
- cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/+", "refs/heads/+"));
- cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/,", "refs/heads/,"));
- cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/-", "refs/heads/-"));
- cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/;", "refs/heads/;"));
- cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/<", "refs/heads/<"));
- cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/=", "refs/heads/="));
- cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/>", "refs/heads/>"));
- cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/@", "refs/heads/@"));
- cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/]", "refs/heads/]"));
- cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/_", "refs/heads/_"));
- cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/`", "refs/heads/`"));
- cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/{", "refs/heads/{"));
- cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/|", "refs/heads/|"));
- cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/}", "refs/heads/}"));
+ ensure_refname_normalized(SYM_REF, "refs/heads/!", "refs/heads/!");
+ ensure_refname_normalized(SYM_REF, "refs/heads/\"", "refs/heads/\"");
+ ensure_refname_normalized(SYM_REF, "refs/heads/#", "refs/heads/#");
+ ensure_refname_normalized(SYM_REF, "refs/heads/$", "refs/heads/$");
+ ensure_refname_normalized(SYM_REF, "refs/heads/%", "refs/heads/%");
+ ensure_refname_normalized(SYM_REF, "refs/heads/&", "refs/heads/&");
+ ensure_refname_normalized(SYM_REF, "refs/heads/'", "refs/heads/'");
+ ensure_refname_normalized(SYM_REF, "refs/heads/(", "refs/heads/(");
+ ensure_refname_normalized(SYM_REF, "refs/heads/)", "refs/heads/)");
+ ensure_refname_normalized(SYM_REF, "refs/heads/+", "refs/heads/+");
+ ensure_refname_normalized(SYM_REF, "refs/heads/,", "refs/heads/,");
+ ensure_refname_normalized(SYM_REF, "refs/heads/-", "refs/heads/-");
+ ensure_refname_normalized(SYM_REF, "refs/heads/;", "refs/heads/;");
+ ensure_refname_normalized(SYM_REF, "refs/heads/<", "refs/heads/<");
+ ensure_refname_normalized(SYM_REF, "refs/heads/=", "refs/heads/=");
+ ensure_refname_normalized(SYM_REF, "refs/heads/>", "refs/heads/>");
+ ensure_refname_normalized(SYM_REF, "refs/heads/@", "refs/heads/@");
+ ensure_refname_normalized(SYM_REF, "refs/heads/]", "refs/heads/]");
+ ensure_refname_normalized(SYM_REF, "refs/heads/_", "refs/heads/_");
+ ensure_refname_normalized(SYM_REF, "refs/heads/`", "refs/heads/`");
+ ensure_refname_normalized(SYM_REF, "refs/heads/{", "refs/heads/{");
+ ensure_refname_normalized(SYM_REF, "refs/heads/|", "refs/heads/|");
+ ensure_refname_normalized(SYM_REF, "refs/heads/}", "refs/heads/}");
// This is valid on UNIX, but not on Windows
// hence we make in invalid due to non-portability
//
- cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/\\", NULL));
+ ensure_refname_invalid(SYM_REF, "refs/heads/\\");
/* UnicodeNames */
/*
* Currently this fails.
- * cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/\u00e5ngstr\u00f6m", "refs/heads/\u00e5ngstr\u00f6m"));
+ * ensure_refname_normalized(SYM_REF, "refs/heads/\u00e5ngstr\u00f6m", "refs/heads/\u00e5ngstr\u00f6m");
*/
/* RefLogQueryIsValidRef */
- cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master@{1}", NULL));
- cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master@{1.hour.ago}", NULL));
+ ensure_refname_invalid(SYM_REF, "refs/heads/master@{1}");
+ ensure_refname_invalid(SYM_REF, "refs/heads/master@{1.hour.ago}");
}