summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorjoshaber <joshaber@gmail.com>2015-07-22 11:33:18 -0400
committerjoshaber <joshaber@gmail.com>2015-07-22 11:33:18 -0400
commit9830fbba05ef66325f929a09407abc45ab85847d (patch)
treedac363428f4705a632719e03b8b77f2d32ce2bb3 /tests
parentcf198fdf2a044d2e2f0675c2c6b1cd9cdbcf4fcf (diff)
parent42156d561723e92ffe597885719aa63abfe0795c (diff)
downloadlibgit2-fix-init-ordering.tar.gz
Merge branch 'master' into fix-init-orderingfix-init-ordering
Diffstat (limited to 'tests')
-rw-r--r--tests/blame/blame_helpers.c2
-rw-r--r--tests/clar_libgit2.c4
-rw-r--r--tests/clar_libgit2_trace.c19
-rw-r--r--tests/diff/index.c32
-rw-r--r--tests/filter/custom.c107
-rw-r--r--tests/filter/custom_helpers.c108
-rw-r--r--tests/filter/custom_helpers.h18
-rw-r--r--tests/filter/stream.c7
-rw-r--r--tests/filter/wildcard.c184
-rw-r--r--tests/main.c19
-rw-r--r--tests/merge/files.c39
-rw-r--r--tests/merge/merge_helpers.c2
-rw-r--r--tests/revert/workdir.c22
-rw-r--r--tests/submodule/lookup.c41
-rw-r--r--tests/submodule/nosubs.c2
-rw-r--r--tests/trace/windows/stacktrace.c151
16 files changed, 612 insertions, 145 deletions
diff --git a/tests/blame/blame_helpers.c b/tests/blame/blame_helpers.c
index 21cd1a615..b305ba1e3 100644
--- a/tests/blame/blame_helpers.c
+++ b/tests/blame/blame_helpers.c
@@ -4,7 +4,7 @@ void hunk_message(size_t idx, const git_blame_hunk *hunk, const char *fmt, ...)
{
va_list arglist;
- printf("Hunk %zd (line %d +%d): ", idx,
+ printf("Hunk %"PRIuZ" (line %d +%d): ", idx,
hunk->final_start_line_number, hunk->lines_in_hunk-1);
va_start(arglist, fmt);
diff --git a/tests/clar_libgit2.c b/tests/clar_libgit2.c
index f73fc5b00..cc687baeb 100644
--- a/tests/clar_libgit2.c
+++ b/tests/clar_libgit2.c
@@ -486,8 +486,8 @@ void clar__assert_equal_file(
for (pos = 0; pos < bytes && expected_data[pos] == buf[pos]; ++pos)
/* find differing byte offset */;
p_snprintf(
- buf, sizeof(buf), "file content mismatch at byte %d",
- (int)(total_bytes + pos));
+ buf, sizeof(buf), "file content mismatch at byte %"PRIdZ,
+ (ssize_t)(total_bytes + pos));
p_close(fd);
clar__fail(file, line, path, buf, 1);
}
diff --git a/tests/clar_libgit2_trace.c b/tests/clar_libgit2_trace.c
index ae582d1cb..aaeeb7810 100644
--- a/tests/clar_libgit2_trace.c
+++ b/tests/clar_libgit2_trace.c
@@ -142,9 +142,28 @@ void _cl_trace_cb__event_handler(
switch (ev) {
case CL_TRACE__SUITE_BEGIN:
git_trace(GIT_TRACE_TRACE, "\n\n%s\n%s: Begin Suite", HR, suite_name);
+#if 0 && defined(GIT_MSVC_CRTDBG)
+ git_win32__crtdbg_stacktrace__dump(
+ GIT_WIN32__CRTDBG_STACKTRACE__SET_MARK,
+ suite_name);
+#endif
break;
case CL_TRACE__SUITE_END:
+#if 0 && defined(GIT_MSVC_CRTDBG)
+ /* As an example of checkpointing, dump leaks within this suite.
+ * This may generate false positives for things like the global
+ * TLS error state and maybe the odb cache since they aren't
+ * freed until the global shutdown and outside the scope of this
+ * set of tests.
+ *
+ * This may under-report if the test itself uses a checkpoint.
+ * See tests/trace/windows/stacktrace.c
+ */
+ git_win32__crtdbg_stacktrace__dump(
+ GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK,
+ suite_name);
+#endif
git_trace(GIT_TRACE_TRACE, "\n\n%s: End Suite\n%s", suite_name, HR);
break;
diff --git a/tests/diff/index.c b/tests/diff/index.c
index f702568bf..df45ad236 100644
--- a/tests/diff/index.c
+++ b/tests/diff/index.c
@@ -268,3 +268,35 @@ void test_diff_index__not_in_head_conflicted(void)
git_index_free(index);
git_tree_free(a);
}
+
+void test_diff_index__to_index(void)
+{
+ const char *a_commit = "26a125ee1bf"; /* the current HEAD */
+ git_tree *old_tree;
+ git_index *old_index;
+ git_index *new_index;
+ git_diff *diff;
+ diff_expects exp;
+
+ cl_git_pass(git_index_new(&old_index));
+ old_tree = resolve_commit_oid_to_tree(g_repo, a_commit);
+ cl_git_pass(git_index_read_tree(old_index, old_tree));
+
+ cl_git_pass(git_repository_index(&new_index, g_repo));
+
+ cl_git_pass(git_diff_index_to_index(&diff, g_repo, old_index, new_index, NULL));
+
+ memset(&exp, 0, sizeof(diff_expects));
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_binary_cb, diff_hunk_cb, diff_line_cb, &exp));
+ cl_assert_equal_i(8, exp.files);
+ cl_assert_equal_i(3, exp.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(2, exp.file_status[GIT_DELTA_DELETED]);
+ cl_assert_equal_i(3, exp.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(0, exp.file_status[GIT_DELTA_CONFLICTED]);
+
+ git_diff_free(diff);
+ git_index_free(new_index);
+ git_index_free(old_index);
+ git_tree_free(old_tree);
+}
diff --git a/tests/filter/custom.c b/tests/filter/custom.c
index 493d26c80..fd1cd271c 100644
--- a/tests/filter/custom.c
+++ b/tests/filter/custom.c
@@ -5,6 +5,7 @@
#include "buf_text.h"
#include "git2/sys/filter.h"
#include "git2/sys/repository.h"
+#include "custom_helpers.h"
/* going TO_WORKDIR, filters are executed low to high
* going TO_ODB, filters are executed high to low
@@ -12,8 +13,6 @@
#define BITFLIP_FILTER_PRIORITY -1
#define REVERSE_FILTER_PRIORITY -2
-#define VERY_SECURE_ENCRYPTION(b) ((b) ^ 0xff)
-
#ifdef GIT_WIN32
# define NEWLINE "\r\n"
#else
@@ -27,6 +26,8 @@ static char workdir_data[] =
"trivially" NEWLINE
"scrambled." NEWLINE;
+#define REVERSED_DATA_LEN 51
+
/* Represents the data above scrambled (bits flipped) after \r\n -> \n
* conversion, then bytewise reversed
*/
@@ -63,107 +64,6 @@ void test_filter_custom__cleanup(void)
g_repo = NULL;
}
-static int bitflip_filter_apply(
- git_filter *self,
- void **payload,
- git_buf *to,
- const git_buf *from,
- const git_filter_source *source)
-{
- const unsigned char *src = (const unsigned char *)from->ptr;
- unsigned char *dst;
- size_t i;
-
- GIT_UNUSED(self); GIT_UNUSED(payload);
-
- /* verify that attribute path match worked as expected */
- cl_assert_equal_i(
- 0, git__strncmp("hero", git_filter_source_path(source), 4));
-
- if (!from->size)
- return 0;
-
- cl_git_pass(git_buf_grow(to, from->size));
-
- dst = (unsigned char *)to->ptr;
-
- for (i = 0; i < from->size; i++)
- dst[i] = VERY_SECURE_ENCRYPTION(src[i]);
-
- to->size = from->size;
-
- return 0;
-}
-
-static void bitflip_filter_free(git_filter *f)
-{
- git__free(f);
-}
-
-static git_filter *create_bitflip_filter(void)
-{
- git_filter *filter = git__calloc(1, sizeof(git_filter));
- cl_assert(filter);
-
- filter->version = GIT_FILTER_VERSION;
- filter->attributes = "+bitflip";
- filter->shutdown = bitflip_filter_free;
- filter->apply = bitflip_filter_apply;
-
- return filter;
-}
-
-
-static int reverse_filter_apply(
- git_filter *self,
- void **payload,
- git_buf *to,
- const git_buf *from,
- const git_filter_source *source)
-{
- const unsigned char *src = (const unsigned char *)from->ptr;
- const unsigned char *end = src + from->size;
- unsigned char *dst;
-
- GIT_UNUSED(self); GIT_UNUSED(payload); GIT_UNUSED(source);
-
- /* verify that attribute path match worked as expected */
- cl_assert_equal_i(
- 0, git__strncmp("hero", git_filter_source_path(source), 4));
-
- if (!from->size)
- return 0;
-
- cl_git_pass(git_buf_grow(to, from->size));
-
- dst = (unsigned char *)to->ptr + from->size - 1;
-
- while (src < end)
- *dst-- = *src++;
-
- to->size = from->size;
-
- return 0;
-}
-
-static void reverse_filter_free(git_filter *f)
-{
- git__free(f);
-}
-
-static git_filter *create_reverse_filter(const char *attrs)
-{
- git_filter *filter = git__calloc(1, sizeof(git_filter));
- cl_assert(filter);
-
- filter->version = GIT_FILTER_VERSION;
- filter->attributes = attrs;
- filter->shutdown = reverse_filter_free;
- filter->apply = reverse_filter_apply;
-
- return filter;
-}
-
static void register_custom_filters(void)
{
static int filters_registered = 0;
@@ -186,7 +86,6 @@ static void register_custom_filters(void)
}
}
-
void test_filter_custom__to_odb(void)
{
git_filter_list *fl;
diff --git a/tests/filter/custom_helpers.c b/tests/filter/custom_helpers.c
new file mode 100644
index 000000000..2c80212be
--- /dev/null
+++ b/tests/filter/custom_helpers.c
@@ -0,0 +1,108 @@
+#include "clar_libgit2.h"
+#include "posix.h"
+#include "filter.h"
+#include "buf_text.h"
+#include "git2/sys/filter.h"
+
+#define VERY_SECURE_ENCRYPTION(b) ((b) ^ 0xff)
+
+int bitflip_filter_apply(
+ git_filter *self,
+ void **payload,
+ git_buf *to,
+ const git_buf *from,
+ const git_filter_source *source)
+{
+ const unsigned char *src = (const unsigned char *)from->ptr;
+ unsigned char *dst;
+ size_t i;
+
+ GIT_UNUSED(self); GIT_UNUSED(payload);
+
+ /* verify that attribute path match worked as expected */
+ cl_assert_equal_i(
+ 0, git__strncmp("hero", git_filter_source_path(source), 4));
+
+ if (!from->size)
+ return 0;
+
+ cl_git_pass(git_buf_grow(to, from->size));
+
+ dst = (unsigned char *)to->ptr;
+
+ for (i = 0; i < from->size; i++)
+ dst[i] = VERY_SECURE_ENCRYPTION(src[i]);
+
+ to->size = from->size;
+
+ return 0;
+}
+
+static void bitflip_filter_free(git_filter *f)
+{
+ git__free(f);
+}
+
+git_filter *create_bitflip_filter(void)
+{
+ git_filter *filter = git__calloc(1, sizeof(git_filter));
+ cl_assert(filter);
+
+ filter->version = GIT_FILTER_VERSION;
+ filter->attributes = "+bitflip";
+ filter->shutdown = bitflip_filter_free;
+ filter->apply = bitflip_filter_apply;
+
+ return filter;
+}
+
+
+int reverse_filter_apply(
+ git_filter *self,
+ void **payload,
+ git_buf *to,
+ const git_buf *from,
+ const git_filter_source *source)
+{
+ const unsigned char *src = (const unsigned char *)from->ptr;
+ const unsigned char *end = src + from->size;
+ unsigned char *dst;
+
+ GIT_UNUSED(self); GIT_UNUSED(payload); GIT_UNUSED(source);
+
+ /* verify that attribute path match worked as expected */
+ cl_assert_equal_i(
+ 0, git__strncmp("hero", git_filter_source_path(source), 4));
+
+ if (!from->size)
+ return 0;
+
+ cl_git_pass(git_buf_grow(to, from->size));
+
+ dst = (unsigned char *)to->ptr + from->size - 1;
+
+ while (src < end)
+ *dst-- = *src++;
+
+ to->size = from->size;
+
+ return 0;
+}
+
+static void reverse_filter_free(git_filter *f)
+{
+ git__free(f);
+}
+
+git_filter *create_reverse_filter(const char *attrs)
+{
+ git_filter *filter = git__calloc(1, sizeof(git_filter));
+ cl_assert(filter);
+
+ filter->version = GIT_FILTER_VERSION;
+ filter->attributes = attrs;
+ filter->shutdown = reverse_filter_free;
+ filter->apply = reverse_filter_apply;
+
+ return filter;
+}
diff --git a/tests/filter/custom_helpers.h b/tests/filter/custom_helpers.h
new file mode 100644
index 000000000..13cfb23ae
--- /dev/null
+++ b/tests/filter/custom_helpers.h
@@ -0,0 +1,18 @@
+#include "git2/sys/filter.h"
+
+extern git_filter *create_bitflip_filter(void);
+extern git_filter *create_reverse_filter(const char *attr);
+
+extern int bitflip_filter_apply(
+ git_filter *self,
+ void **payload,
+ git_buf *to,
+ const git_buf *from,
+ const git_filter_source *source);
+
+extern int reverse_filter_apply(
+ git_filter *self,
+ void **payload,
+ git_buf *to,
+ const git_buf *from,
+ const git_filter_source *source);
diff --git a/tests/filter/stream.c b/tests/filter/stream.c
index 9228911b6..30f5e5027 100644
--- a/tests/filter/stream.c
+++ b/tests/filter/stream.c
@@ -25,6 +25,7 @@ void test_filter_stream__cleanup(void)
g_repo = NULL;
git_filter_unregister("compress");
+ git__free(compress_filter);
}
#define CHUNKSIZE 10240
@@ -123,11 +124,6 @@ static int compress_filter_stream_init(
return 0;
}
-static void compress_filter_free(git_filter *f)
-{
- git__free(f);
-}
-
git_filter *create_compress_filter(void)
{
git_filter *filter = git__calloc(1, sizeof(git_filter));
@@ -136,7 +132,6 @@ git_filter *create_compress_filter(void)
filter->version = GIT_FILTER_VERSION;
filter->attributes = "+compress";
filter->stream = compress_filter_stream_init;
- filter->shutdown = compress_filter_free;
return filter;
}
diff --git a/tests/filter/wildcard.c b/tests/filter/wildcard.c
new file mode 100644
index 000000000..999b33653
--- /dev/null
+++ b/tests/filter/wildcard.c
@@ -0,0 +1,184 @@
+#include "clar_libgit2.h"
+#include "posix.h"
+#include "blob.h"
+#include "filter.h"
+#include "buf_text.h"
+#include "git2/sys/filter.h"
+#include "git2/sys/repository.h"
+#include "custom_helpers.h"
+
+static git_repository *g_repo = NULL;
+
+static git_filter *create_wildcard_filter(void);
+
+#define DATA_LEN 32
+
+static unsigned char input[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+};
+
+static unsigned char reversed[] = {
+ 0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18,
+ 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10,
+ 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08,
+ 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00,
+};
+
+static unsigned char flipped[] = {
+ 0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8,
+ 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf2, 0xf1, 0xf0,
+ 0xef, 0xee, 0xed, 0xec, 0xeb, 0xea, 0xe9, 0xe8,
+ 0xe7, 0xe6, 0xe5, 0xe4, 0xe3, 0xe2, 0xe1, 0xe0,
+};
+
+void test_filter_wildcard__initialize(void)
+{
+ cl_git_pass(git_filter_register(
+ "wildcard", create_wildcard_filter(), GIT_FILTER_DRIVER_PRIORITY));
+
+ g_repo = cl_git_sandbox_init("empty_standard_repo");
+
+ cl_git_rewritefile(
+ "empty_standard_repo/.gitattributes",
+ "* binary\n"
+ "hero-flip-* filter=wcflip\n"
+ "hero-reverse-* filter=wcreverse\n"
+ "none-* filter=unregistered\n");
+}
+
+void test_filter_wildcard__cleanup(void)
+{
+ cl_git_pass(git_filter_unregister("wildcard"));
+
+ cl_git_sandbox_cleanup();
+ g_repo = NULL;
+}
+
+static int wildcard_filter_check(
+ git_filter *self,
+ void **payload,
+ const git_filter_source *src,
+ const char **attr_values)
+{
+ GIT_UNUSED(self);
+ GIT_UNUSED(src);
+
+ if (strcmp(attr_values[0], "wcflip") == 0 ||
+ strcmp(attr_values[0], "wcreverse") == 0) {
+ *payload = git__strdup(attr_values[0]);
+ GITERR_CHECK_ALLOC(*payload);
+ return 0;
+ }
+
+ return GIT_PASSTHROUGH;
+}
+
+static int wildcard_filter_apply(
+ git_filter *self,
+ void **payload,
+ git_buf *to,
+ const git_buf *from,
+ const git_filter_source *source)
+{
+ const char *filtername = *payload;
+
+ if (filtername && strcmp(filtername, "wcflip") == 0)
+ return bitflip_filter_apply(self, payload, to, from, source);
+ else if (filtername && strcmp(filtername, "wcreverse") == 0)
+ return reverse_filter_apply(self, payload, to, from, source);
+
+ cl_fail("Unexpected attribute");
+ return GIT_PASSTHROUGH;
+}
+
+static void wildcard_filter_cleanup(git_filter *self, void *payload)
+{
+ GIT_UNUSED(self);
+ git__free(payload);
+}
+
+static void wildcard_filter_free(git_filter *f)
+{
+ git__free(f);
+}
+
+static git_filter *create_wildcard_filter(void)
+{
+ git_filter *filter = git__calloc(1, sizeof(git_filter));
+ cl_assert(filter);
+
+ filter->version = GIT_FILTER_VERSION;
+ filter->attributes = "filter=*";
+ filter->check = wildcard_filter_check;
+ filter->apply = wildcard_filter_apply;
+ filter->cleanup = wildcard_filter_cleanup;
+ filter->shutdown = wildcard_filter_free;
+
+ return filter;
+}
+
+void test_filter_wildcard__reverse(void)
+{
+ git_filter_list *fl;
+ git_buf in = GIT_BUF_INIT, out = GIT_BUF_INIT;
+
+ cl_git_pass(git_filter_list_load(
+ &fl, g_repo, NULL, "hero-reverse-foo", GIT_FILTER_TO_ODB, 0));
+
+ cl_git_pass(git_buf_put(&in, (char *)input, DATA_LEN));
+ cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
+
+ cl_assert_equal_i(DATA_LEN, out.size);
+
+ cl_assert_equal_i(
+ 0, memcmp(reversed, out.ptr, out.size));
+
+ git_filter_list_free(fl);
+ git_buf_free(&out);
+ git_buf_free(&in);
+}
+
+void test_filter_wildcard__flip(void)
+{
+ git_filter_list *fl;
+ git_buf in = GIT_BUF_INIT, out = GIT_BUF_INIT;
+
+ cl_git_pass(git_filter_list_load(
+ &fl, g_repo, NULL, "hero-flip-foo", GIT_FILTER_TO_ODB, 0));
+
+ cl_git_pass(git_buf_put(&in, (char *)input, DATA_LEN));
+ cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
+
+ cl_assert_equal_i(DATA_LEN, out.size);
+
+ cl_assert_equal_i(
+ 0, memcmp(flipped, out.ptr, out.size));
+
+ git_filter_list_free(fl);
+ git_buf_free(&out);
+ git_buf_free(&in);
+}
+
+void test_filter_wildcard__none(void)
+{
+ git_filter_list *fl;
+ git_buf in = GIT_BUF_INIT, out = GIT_BUF_INIT;
+
+ cl_git_pass(git_filter_list_load(
+ &fl, g_repo, NULL, "none-foo", GIT_FILTER_TO_ODB, 0));
+
+ cl_git_pass(git_buf_put(&in, (char *)input, DATA_LEN));
+ cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
+
+ cl_assert_equal_i(DATA_LEN, out.size);
+
+ cl_assert_equal_i(
+ 0, memcmp(input, out.ptr, out.size));
+
+ git_filter_list_free(fl);
+ git_buf_free(&out);
+ git_buf_free(&in);
+}
diff --git a/tests/main.c b/tests/main.c
index 56326da1c..f67c8ffbc 100644
--- a/tests/main.c
+++ b/tests/main.c
@@ -1,10 +1,3 @@
-
-#if defined(GIT_MSVC_CRTDBG)
-/* Enable MSVC CRTDBG memory leak reporting. See src/util.h for details. */
-#include <stdlib.h>
-#include <crtdbg.h>
-#endif
-
#include "clar_libgit2.h"
#include "clar_libgit2_trace.h"
@@ -16,18 +9,6 @@ int main(int argc, char *argv[])
{
int res;
-#if defined(GIT_MSVC_CRTDBG)
- _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
-
- _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE);
- _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE);
- _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE);
-
- _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
- _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
- _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
-#endif
-
clar_test_init(argc, argv);
git_libgit2_init();
diff --git a/tests/merge/files.c b/tests/merge/files.c
index 7f461abff..2fd90d066 100644
--- a/tests/merge/files.c
+++ b/tests/merge/files.c
@@ -249,3 +249,42 @@ void test_merge_files__automerge_whitespace_change(void)
git_merge_file_result_free(&result);
}
+
+void test_merge_files__doesnt_add_newline(void)
+{
+ git_merge_file_input ancestor = GIT_MERGE_FILE_INPUT_INIT,
+ ours = GIT_MERGE_FILE_INPUT_INIT,
+ theirs = GIT_MERGE_FILE_INPUT_INIT;
+ git_merge_file_options opts = GIT_MERGE_FILE_OPTIONS_INIT;
+ git_merge_file_result result = {0};
+ const char *expected = "Zero\n1\n2\n3\n4\n5 XXX\n6 YYY\n7\n8\n9\nTen";
+
+ ancestor.ptr = "0\n1\n2\n3\n4\n5 XXX\n6YYY\n7\n8\n9\n10";
+ ancestor.size = strlen(ancestor.ptr);
+ ancestor.path = "testfile.txt";
+ ancestor.mode = 0100755;
+
+ ours.ptr = "Zero\n1\n2\n3\n4\n5 XXX\n6 YYY\n7\n8\n9\n10";
+ ours.size = strlen(ours.ptr);
+ ours.path = "testfile.txt";
+ ours.mode = 0100755;
+
+ theirs.ptr = "0\n1\n2\n3\n4\n5 XXX\n6 YYY\n7\n8\n9\nTen";
+ theirs.size = strlen(theirs.ptr);
+ theirs.path = "testfile.txt";
+ theirs.mode = 0100755;
+
+ opts.flags |= GIT_MERGE_FILE_IGNORE_WHITESPACE_CHANGE;
+ cl_git_pass(git_merge_file(&result, &ancestor, &ours, &theirs, &opts));
+
+ cl_assert_equal_i(1, result.automergeable);
+
+ cl_assert_equal_s("testfile.txt", result.path);
+ cl_assert_equal_i(0100755, result.mode);
+
+ cl_assert_equal_i(strlen(expected), result.len);
+ cl_assert_equal_strn(expected, result.ptr, result.len);
+
+ git_merge_file_result_free(&result);
+}
+
diff --git a/tests/merge/merge_helpers.c b/tests/merge/merge_helpers.c
index 33710f403..f81471424 100644
--- a/tests/merge/merge_helpers.c
+++ b/tests/merge/merge_helpers.c
@@ -110,7 +110,7 @@ void merge__dump_index_entries(git_vector *index_entries)
size_t i;
const git_index_entry *index_entry;
- printf ("\nINDEX [%d]:\n", (int)index_entries->length);
+ printf ("\nINDEX [%"PRIuZ"]:\n", index_entries->length);
for (i = 0; i < index_entries->length; i++) {
index_entry = index_entries->contents[i];
diff --git a/tests/revert/workdir.c b/tests/revert/workdir.c
index 7ccf0f937..9f83bd842 100644
--- a/tests/revert/workdir.c
+++ b/tests/revert/workdir.c
@@ -334,16 +334,18 @@ void test_revert_workdir__again_after_edit_two(void)
cl_assert(merge_test_index(repo_index, merge_index_entries, 3));
cl_git_pass(git_futils_readbuffer(&diff_buf, "revert/file.txt"));
- cl_assert(strcmp(diff_buf.ptr, "a\n" \
- "<<<<<<< HEAD\n" \
- "=======\n" \
- "a\n" \
- ">>>>>>> parent of 97e52d5... Revert me\n" \
- "a\n" \
- "a\n" \
- "a\n" \
- "a\n" \
- "ab\n") == 0);
+ cl_assert_equal_s(
+ "a\n" \
+ "<<<<<<< HEAD\n" \
+ "=======\n" \
+ "a\n" \
+ ">>>>>>> parent of 97e52d5... Revert me\n" \
+ "a\n" \
+ "a\n" \
+ "a\n" \
+ "a\n" \
+ "ab",
+ diff_buf.ptr);
git_commit_free(revert_commit);
git_commit_free(head_commit);
diff --git a/tests/submodule/lookup.c b/tests/submodule/lookup.c
index cddbdcfc2..9b2b3aa19 100644
--- a/tests/submodule/lookup.c
+++ b/tests/submodule/lookup.c
@@ -1,6 +1,7 @@
#include "clar_libgit2.h"
#include "submodule_helpers.h"
#include "git2/sys/repository.h"
+#include "repository.h"
#include "fileops.h"
static git_repository *g_repo = NULL;
@@ -103,8 +104,25 @@ static int sm_lookup_cb(git_submodule *sm, const char *name, void *payload)
void test_submodule_lookup__foreach(void)
{
+ git_config *cfg;
sm_lookup_data data;
+
+ memset(&data, 0, sizeof(data));
+ cl_git_pass(git_submodule_foreach(g_repo, sm_lookup_cb, &data));
+ cl_assert_equal_i(8, data.count);
+
memset(&data, 0, sizeof(data));
+
+ /* Change the path for a submodule so it doesn't match the name */
+ cl_git_pass(git_config_open_ondisk(&cfg, "submod2/.gitmodules"));
+
+ cl_git_pass(git_config_set_string(cfg, "submodule.smchangedindex.path", "sm_changed_index"));
+ cl_git_pass(git_config_set_string(cfg, "submodule.smchangedindex.url", "../submod2_target"));
+ cl_git_pass(git_config_delete_entry(cfg, "submodule.sm_changed_index.path"));
+ cl_git_pass(git_config_delete_entry(cfg, "submodule.sm_changed_index.url"));
+
+ git_config_free(cfg);
+
cl_git_pass(git_submodule_foreach(g_repo, sm_lookup_cb, &data));
cl_assert_equal_i(8, data.count);
}
@@ -269,3 +287,26 @@ void test_submodule_lookup__just_added(void)
refute_submodule_exists(g_repo, "sm_just_added_head", GIT_EEXISTS);
}
+/* Test_App and Test_App2 are fairly similar names, make sure we load the right one */
+void test_submodule_lookup__prefix_name(void)
+{
+ git_submodule *sm;
+
+ cl_git_rewritefile("submod2/.gitmodules",
+ "[submodule \"Test_App\"]\n"
+ " path = Test_App\n"
+ " url = ../Test_App\n"
+ "[submodule \"Test_App2\"]\n"
+ " path = Test_App2\n"
+ " url = ../Test_App\n");
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "Test_App"));
+ cl_assert_equal_s("Test_App", git_submodule_name(sm));
+
+ git_submodule_free(sm);
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "Test_App2"));
+ cl_assert_equal_s("Test_App2", git_submodule_name(sm));
+
+ git_submodule_free(sm);
+}
diff --git a/tests/submodule/nosubs.c b/tests/submodule/nosubs.c
index 538825c1c..8a73dc11a 100644
--- a/tests/submodule/nosubs.c
+++ b/tests/submodule/nosubs.c
@@ -71,8 +71,6 @@ void test_submodule_nosubs__add_and_delete(void)
git_submodule *sm;
git_buf buf = GIT_BUF_INIT;
- /* note lack of calls to git_submodule_reload_all - this *should* work */
-
cl_git_fail(git_submodule_lookup(NULL, repo, "libgit2"));
cl_git_fail(git_submodule_lookup(NULL, repo, "submodules/libgit2"));
diff --git a/tests/trace/windows/stacktrace.c b/tests/trace/windows/stacktrace.c
new file mode 100644
index 000000000..c00c1b774
--- /dev/null
+++ b/tests/trace/windows/stacktrace.c
@@ -0,0 +1,151 @@
+#include "clar_libgit2.h"
+#include "win32/w32_stack.h"
+
+#if defined(GIT_MSVC_CRTDBG)
+static void a(void)
+{
+ char buf[10000];
+
+ cl_assert(git_win32__stack(buf, sizeof(buf), 0, NULL, NULL) == 0);
+
+#if 0
+ fprintf(stderr, "Stacktrace from [%s:%d]:\n%s\n", __FILE__, __LINE__, buf);
+#endif
+}
+
+static void b(void)
+{
+ a();
+}
+
+static void c(void)
+{
+ b();
+}
+#endif
+
+void test_trace_windows_stacktrace__basic(void)
+{
+#if defined(GIT_MSVC_CRTDBG)
+ c();
+#endif
+}
+
+
+void test_trace_windows_stacktrace__leaks(void)
+{
+#if defined(GIT_MSVC_CRTDBG)
+ void * p1;
+ void * p2;
+ void * p3;
+ void * p4;
+ int before, after;
+ int leaks;
+ int error;
+
+ /* remember outstanding leaks due to set setup
+ * and set mark/checkpoint.
+ */
+ before = git_win32__crtdbg_stacktrace__dump(
+ GIT_WIN32__CRTDBG_STACKTRACE__QUIET |
+ GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_TOTAL |
+ GIT_WIN32__CRTDBG_STACKTRACE__SET_MARK,
+ NULL);
+
+ p1 = git__malloc(5);
+ leaks = git_win32__crtdbg_stacktrace__dump(
+ GIT_WIN32__CRTDBG_STACKTRACE__QUIET |
+ GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK,
+ "p1");
+ cl_assert((leaks == 1));
+
+ p2 = git__malloc(5);
+ leaks = git_win32__crtdbg_stacktrace__dump(
+ GIT_WIN32__CRTDBG_STACKTRACE__QUIET |
+ GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK,
+ "p1,p2");
+ cl_assert((leaks == 2));
+
+ p3 = git__malloc(5);
+ leaks = git_win32__crtdbg_stacktrace__dump(
+ GIT_WIN32__CRTDBG_STACKTRACE__QUIET |
+ GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK,
+ "p1,p2,p3");
+ cl_assert((leaks == 3));
+
+ git__free(p2);
+ leaks = git_win32__crtdbg_stacktrace__dump(
+ GIT_WIN32__CRTDBG_STACKTRACE__QUIET |
+ GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK,
+ "p1,p3");
+ cl_assert((leaks == 2));
+
+ /* move the mark. only new leaks should appear afterwards */
+ error = git_win32__crtdbg_stacktrace__dump(
+ GIT_WIN32__CRTDBG_STACKTRACE__SET_MARK,
+ NULL);
+ cl_assert((error == 0));
+
+ leaks = git_win32__crtdbg_stacktrace__dump(
+ GIT_WIN32__CRTDBG_STACKTRACE__QUIET |
+ GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK,
+ "not_p1,not_p3");
+ cl_assert((leaks == 0));
+
+ p4 = git__malloc(5);
+ leaks = git_win32__crtdbg_stacktrace__dump(
+ GIT_WIN32__CRTDBG_STACKTRACE__QUIET |
+ GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK,
+ "p4,not_p1,not_p3");
+ cl_assert((leaks == 1));
+
+ git__free(p1);
+ git__free(p3);
+ leaks = git_win32__crtdbg_stacktrace__dump(
+ GIT_WIN32__CRTDBG_STACKTRACE__QUIET |
+ GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK,
+ "p4");
+ cl_assert((leaks == 1));
+
+ git__free(p4);
+ leaks = git_win32__crtdbg_stacktrace__dump(
+ GIT_WIN32__CRTDBG_STACKTRACE__QUIET |
+ GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK,
+ "end");
+ cl_assert((leaks == 0));
+
+ /* confirm current absolute leaks count matches beginning value. */
+ after = git_win32__crtdbg_stacktrace__dump(
+ GIT_WIN32__CRTDBG_STACKTRACE__QUIET |
+ GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_TOTAL,
+ "total");
+ cl_assert((before == after));
+#endif
+}
+
+#if defined(GIT_MSVC_CRTDBG)
+static void aux_cb_alloc__1(unsigned int *aux_id)
+{
+ static unsigned int aux_counter = 0;
+
+ *aux_id = aux_counter++;
+}
+
+static void aux_cb_lookup__1(unsigned int aux_id, char *aux_msg, unsigned int aux_msg_len)
+{
+ p_snprintf(aux_msg, aux_msg_len, "\tQQ%08x\n", aux_id);
+}
+
+#endif
+
+void test_trace_windows_stacktrace__aux1(void)
+{
+#if defined(GIT_MSVC_CRTDBG)
+ git_win32__stack__set_aux_cb(aux_cb_alloc__1, aux_cb_lookup__1);
+ c();
+ c();
+ c();
+ c();
+ git_win32__stack__set_aux_cb(NULL, NULL);
+#endif
+}