Commit 8e82600e by Ben Straub

Ref normalization test helpers now doing internal asserts.

parent 1cb9b31e
...@@ -6,26 +6,27 @@ ...@@ -6,26 +6,27 @@
// Helpers // 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]; char buffer_out[GIT_REFNAME_MAX];
if (is_oid_ref) 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 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) if (expected_refname)
return error; cl_assert(0 == strcmp(buffer_out, expected_refname));
}
if (expected_refname == NULL)
return error;
if (strcmp(buffer_out, expected_refname)) static void ensure_refname_invalid(int is_oid_ref, const char *input_refname)
error = GIT_ERROR; {
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 #define OID_REF 1
...@@ -36,35 +37,35 @@ static int ensure_refname_normalized(int is_oid_ref, const char *input_refname, ...@@ -36,35 +37,35 @@ static int ensure_refname_normalized(int is_oid_ref, const char *input_refname,
void test_refs_normalize__direct(void) void test_refs_normalize__direct(void)
{ {
// normalize a direct (OID) reference name // normalize a direct (OID) reference name
cl_git_fail(ensure_refname_normalized(OID_REF, "a", NULL)); ensure_refname_invalid(OID_REF, "a");
cl_git_fail(ensure_refname_normalized(OID_REF, "", NULL)); ensure_refname_invalid(OID_REF, "");
cl_git_fail(ensure_refname_normalized(OID_REF, "refs/heads/a/", NULL)); ensure_refname_invalid(OID_REF, "refs/heads/a/");
cl_git_fail(ensure_refname_normalized(OID_REF, "refs/heads/a.", NULL)); ensure_refname_invalid(OID_REF, "refs/heads/a.");
cl_git_fail(ensure_refname_normalized(OID_REF, "refs/heads/a.lock", NULL)); ensure_refname_invalid(OID_REF, "refs/heads/a.lock");
cl_git_pass(ensure_refname_normalized(OID_REF, "refs/dummy/a", NULL)); ensure_refname_normalized(OID_REF, "refs/dummy/a", NULL);
cl_git_pass(ensure_refname_normalized(OID_REF, "refs/stash", NULL)); ensure_refname_normalized(OID_REF, "refs/stash", NULL);
cl_git_pass(ensure_refname_normalized(OID_REF, "refs/tags/a", "refs/tags/a")); 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")); 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")); 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)); ensure_refname_invalid(OID_REF, "refs/heads/foo?bar");
cl_git_fail(ensure_refname_normalized(OID_REF, "refs/heads\foo", NULL)); ensure_refname_invalid(OID_REF, "refs/heads\foo");
cl_git_pass(ensure_refname_normalized(OID_REF, "refs/heads/v@ation", "refs/heads/v@ation")); 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")); ensure_refname_normalized(OID_REF, "refs///heads///a", "refs/heads/a");
cl_git_fail(ensure_refname_normalized(OID_REF, "refs/heads/.a/b", NULL)); ensure_refname_invalid(OID_REF, "refs/heads/.a/b");
cl_git_fail(ensure_refname_normalized(OID_REF, "refs/heads/foo/../bar", NULL)); ensure_refname_invalid(OID_REF, "refs/heads/foo/../bar");
cl_git_fail(ensure_refname_normalized(OID_REF, "refs/heads/foo..bar", NULL)); ensure_refname_invalid(OID_REF, "refs/heads/foo..bar");
cl_git_fail(ensure_refname_normalized(OID_REF, "refs/heads/./foo", NULL)); ensure_refname_invalid(OID_REF, "refs/heads/./foo");
cl_git_fail(ensure_refname_normalized(OID_REF, "refs/heads/v@{ation", NULL)); ensure_refname_invalid(OID_REF, "refs/heads/v@{ation");
} }
void test_refs_normalize__symbolic(void) void test_refs_normalize__symbolic(void)
{ {
// normalize a symbolic reference name // normalize a symbolic reference name
cl_git_pass(ensure_refname_normalized(SYM_REF, "a", "a")); ensure_refname_normalized(SYM_REF, "a", "a");
cl_git_pass(ensure_refname_normalized(SYM_REF, "a/b", "a/b")); ensure_refname_normalized(SYM_REF, "a/b", "a/b");
cl_git_pass(ensure_refname_normalized(SYM_REF, "refs///heads///a", "refs/heads/a")); ensure_refname_normalized(SYM_REF, "refs///heads///a", "refs/heads/a");
cl_git_fail(ensure_refname_normalized(SYM_REF, "", NULL)); ensure_refname_invalid(SYM_REF, "");
cl_git_fail(ensure_refname_normalized(SYM_REF, "heads\foo", NULL)); ensure_refname_invalid(SYM_REF, "heads\foo");
} }
/* Ported from JGit, BSD licence. /* Ported from JGit, BSD licence.
...@@ -74,31 +75,31 @@ void test_refs_normalize__jgit_suite(void) ...@@ -74,31 +75,31 @@ void test_refs_normalize__jgit_suite(void)
// tests borrowed from JGit // tests borrowed from JGit
/* EmptyString */ /* EmptyString */
cl_git_fail(ensure_refname_normalized(SYM_REF, "", NULL)); ensure_refname_invalid(SYM_REF, "");
cl_git_fail(ensure_refname_normalized(SYM_REF, "/", NULL)); ensure_refname_invalid(SYM_REF, "/");
/* MustHaveTwoComponents */ /* MustHaveTwoComponents */
cl_git_fail(ensure_refname_normalized(OID_REF, "master", NULL)); ensure_refname_invalid(OID_REF, "master");
cl_git_pass(ensure_refname_normalized(SYM_REF, "heads/master", "heads/master")); ensure_refname_normalized(SYM_REF, "heads/master", "heads/master");
/* ValidHead */ /* ValidHead */
cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/master", "refs/heads/master")); 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")); 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")); 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/FoO", "refs/heads/FoO");
/* ValidTag */ /* 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 */ /* NoLockSuffix */
cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master.lock", NULL)); ensure_refname_invalid(SYM_REF, "refs/heads/master.lock");
/* NoDirectorySuffix */ /* NoDirectorySuffix */
cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master/", NULL)); ensure_refname_invalid(SYM_REF, "refs/heads/master/");
/* NoSpace */ /* 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 */ /* NoAsciiControlCharacters */
{ {
...@@ -109,89 +110,89 @@ void test_refs_normalize__jgit_suite(void) ...@@ -109,89 +110,89 @@ void test_refs_normalize__jgit_suite(void)
strncpy(buffer + 15, (const char *)&c, 1); strncpy(buffer + 15, (const char *)&c, 1);
strncpy(buffer + 16, "er", 2); strncpy(buffer + 16, "er", 2);
buffer[18 - 1] = '\0'; buffer[18 - 1] = '\0';
cl_git_fail(ensure_refname_normalized(SYM_REF, buffer, NULL)); ensure_refname_invalid(SYM_REF, buffer);
} }
} }
/* NoBareDot */ /* NoBareDot */
cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/.", NULL)); ensure_refname_invalid(SYM_REF, "refs/heads/.");
cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/..", NULL)); ensure_refname_invalid(SYM_REF, "refs/heads/..");
cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/./master", NULL)); ensure_refname_invalid(SYM_REF, "refs/heads/./master");
cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/../master", NULL)); ensure_refname_invalid(SYM_REF, "refs/heads/../master");
/* NoLeadingOrTrailingDot */ /* NoLeadingOrTrailingDot */
cl_git_fail(ensure_refname_normalized(SYM_REF, ".", NULL)); ensure_refname_invalid(SYM_REF, ".");
cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/.bar", NULL)); ensure_refname_invalid(SYM_REF, "refs/heads/.bar");
cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/..bar", NULL)); ensure_refname_invalid(SYM_REF, "refs/heads/..bar");
cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/bar.", NULL)); ensure_refname_invalid(SYM_REF, "refs/heads/bar.");
/* ContainsDot */ /* 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")); 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_invalid(SYM_REF, "refs/heads/master..pu");
/* NoMagicRefCharacters */ /* NoMagicRefCharacters */
cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master^", NULL)); ensure_refname_invalid(SYM_REF, "refs/heads/master^");
cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/^master", NULL)); ensure_refname_invalid(SYM_REF, "refs/heads/^master");
cl_git_fail(ensure_refname_normalized(SYM_REF, "^refs/heads/master", NULL)); ensure_refname_invalid(SYM_REF, "^refs/heads/master");
cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master~", NULL)); ensure_refname_invalid(SYM_REF, "refs/heads/master~");
cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/~master", NULL)); ensure_refname_invalid(SYM_REF, "refs/heads/~master");
cl_git_fail(ensure_refname_normalized(SYM_REF, "~refs/heads/master", NULL)); ensure_refname_invalid(SYM_REF, "~refs/heads/master");
cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master:", NULL)); ensure_refname_invalid(SYM_REF, "refs/heads/master:");
cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/:master", NULL)); ensure_refname_invalid(SYM_REF, "refs/heads/:master");
cl_git_fail(ensure_refname_normalized(SYM_REF, ":refs/heads/master", NULL)); ensure_refname_invalid(SYM_REF, ":refs/heads/master");
/* ShellGlob */ /* ShellGlob */
cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master?", NULL)); ensure_refname_invalid(SYM_REF, "refs/heads/master?");
cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/?master", NULL)); ensure_refname_invalid(SYM_REF, "refs/heads/?master");
cl_git_fail(ensure_refname_normalized(SYM_REF, "?refs/heads/master", NULL)); ensure_refname_invalid(SYM_REF, "?refs/heads/master");
cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master[", NULL)); ensure_refname_invalid(SYM_REF, "refs/heads/master[");
cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/[master", NULL)); ensure_refname_invalid(SYM_REF, "refs/heads/[master");
cl_git_fail(ensure_refname_normalized(SYM_REF, "[refs/heads/master", NULL)); ensure_refname_invalid(SYM_REF, "[refs/heads/master");
cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master*", NULL)); ensure_refname_invalid(SYM_REF, "refs/heads/master*");
cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/*master", NULL)); ensure_refname_invalid(SYM_REF, "refs/heads/*master");
cl_git_fail(ensure_refname_normalized(SYM_REF, "*refs/heads/master", NULL)); ensure_refname_invalid(SYM_REF, "*refs/heads/master");
/* ValidSpecialCharacters */ /* ValidSpecialCharacters */
cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/!", "refs/heads/!")); 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/\"");
cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/#", "refs/heads/#")); 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/$");
cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/%", "refs/heads/%")); 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/&");
cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/'", "refs/heads/'")); 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/(");
cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/)", "refs/heads/)")); 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/+");
cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/,", "refs/heads/,")); 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/-");
cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/;", "refs/heads/;")); 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/<");
cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/=", "refs/heads/=")); 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/>");
cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/@", "refs/heads/@")); 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/]");
cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/_", "refs/heads/_")); 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/`");
cl_git_pass(ensure_refname_normalized(SYM_REF, "refs/heads/{", "refs/heads/{")); 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/|");
cl_git_pass(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 // This is valid on UNIX, but not on Windows
// hence we make in invalid due to non-portability // 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 */ /* UnicodeNames */
/* /*
* Currently this fails. * 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 */ /* RefLogQueryIsValidRef */
cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master@{1}", NULL)); ensure_refname_invalid(SYM_REF, "refs/heads/master@{1}");
cl_git_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master@{1.hour.ago}", NULL)); 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