Commit 8e82600e by Ben Straub

Ref normalization test helpers now doing internal asserts.

parent 1cb9b31e
......@@ -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}");
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment