]> git.proxmox.com Git - libgit2.git/blob - tests/filter/bare.c
New upstream version 1.1.0+dfsg.1
[libgit2.git] / tests / filter / bare.c
1 #include "clar_libgit2.h"
2 #include "crlf.h"
3
4 static git_repository *g_repo = NULL;
5 static git_blob_filter_options filter_opts = GIT_BLOB_FILTER_OPTIONS_INIT;
6
7 void test_filter_bare__initialize(void)
8 {
9 cl_fixture_sandbox("crlf.git");
10 cl_git_pass(git_repository_open(&g_repo, "crlf.git"));
11
12 filter_opts.flags |= GIT_BLOB_FILTER_NO_SYSTEM_ATTRIBUTES;
13 filter_opts.flags |= GIT_BLOB_FILTER_ATTTRIBUTES_FROM_HEAD;
14 }
15
16 void test_filter_bare__cleanup(void)
17 {
18 git_repository_free(g_repo);
19 cl_fixture_cleanup("crlf.git");
20 }
21
22 void test_filter_bare__all_crlf(void)
23 {
24 git_blob *blob;
25 git_buf buf = { 0 };
26
27 cl_git_pass(git_revparse_single(
28 (git_object **)&blob, g_repo, "a9a2e89")); /* all-crlf */
29
30 cl_assert_equal_s(ALL_CRLF_TEXT_RAW, git_blob_rawcontent(blob));
31
32 cl_git_pass(git_blob_filter(&buf, blob, "file.bin", &filter_opts));
33
34 cl_assert_equal_s(ALL_CRLF_TEXT_RAW, buf.ptr);
35
36 cl_git_pass(git_blob_filter(&buf, blob, "file.crlf", &filter_opts));
37
38 /* in this case, raw content has crlf in it already */
39 cl_assert_equal_s(ALL_CRLF_TEXT_AS_CRLF, buf.ptr);
40
41 cl_git_pass(git_blob_filter(&buf, blob, "file.lf", &filter_opts));
42
43 /* we never convert CRLF -> LF on platforms that have LF */
44 cl_assert_equal_s(ALL_CRLF_TEXT_AS_CRLF, buf.ptr);
45
46 cl_git_pass(git_blob_filter(&buf, blob, "file.txt", &filter_opts));
47
48 /* in this case, raw content has crlf in it already */
49 cl_assert_equal_s(ALL_CRLF_TEXT_AS_CRLF, buf.ptr);
50
51 git_buf_dispose(&buf);
52 git_blob_free(blob);
53 }
54
55 void test_filter_bare__from_lf(void)
56 {
57 git_blob *blob;
58 git_buf buf = { 0 };
59
60 cl_git_pass(git_revparse_single(
61 (git_object **)&blob, g_repo, "799770d")); /* all-lf */
62
63 cl_assert_equal_s(ALL_LF_TEXT_RAW, git_blob_rawcontent(blob));
64
65 cl_git_pass(git_blob_filter(&buf, blob, "file.bin", &filter_opts));
66
67 cl_assert_equal_s(ALL_LF_TEXT_RAW, buf.ptr);
68
69 cl_git_pass(git_blob_filter(&buf, blob, "file.crlf", &filter_opts));
70
71 /* in this case, raw content has crlf in it already */
72 cl_assert_equal_s(ALL_LF_TEXT_AS_CRLF, buf.ptr);
73
74 cl_git_pass(git_blob_filter(&buf, blob, "file.lf", &filter_opts));
75
76 /* we never convert CRLF -> LF on platforms that have LF */
77 cl_assert_equal_s(ALL_LF_TEXT_AS_LF, buf.ptr);
78
79 git_buf_dispose(&buf);
80 git_blob_free(blob);
81 }
82
83 void test_filter_bare__nested_attributes(void)
84 {
85 git_blob *blob;
86 git_buf buf = { 0 };
87
88 cl_git_pass(git_revparse_single(
89 (git_object **)&blob, g_repo, "799770d")); /* all-lf */
90
91 cl_assert_equal_s(ALL_LF_TEXT_RAW, git_blob_rawcontent(blob));
92
93 cl_git_pass(git_blob_filter(&buf, blob, "raw/file.bin", &filter_opts));
94 cl_assert_equal_s(ALL_LF_TEXT_RAW, buf.ptr);
95
96 cl_git_pass(git_blob_filter(&buf, blob, "raw/file.crlf", &filter_opts));
97 cl_assert_equal_s(ALL_LF_TEXT_RAW, buf.ptr);
98
99 cl_git_pass(git_blob_filter(&buf, blob, "raw/file.lf", &filter_opts));
100 cl_assert_equal_s(ALL_LF_TEXT_RAW, buf.ptr);
101
102 git_buf_dispose(&buf);
103 git_blob_free(blob);
104 }
105
106 void test_filter_bare__sanitizes(void)
107 {
108 git_blob *blob;
109 git_buf buf = GIT_BUF_INIT;
110
111 cl_git_pass(git_revparse_single(
112 (git_object **)&blob, g_repo, "e69de29")); /* zero-byte */
113
114 cl_assert_equal_i(0, git_blob_rawsize(blob));
115 cl_assert_equal_s("", git_blob_rawcontent(blob));
116
117 cl_git_pass(git_blob_filter(&buf, blob, "file.bin", &filter_opts));
118 cl_assert_equal_sz(0, buf.size);
119 cl_assert_equal_s("", buf.ptr);
120 git_buf_dispose(&buf);
121
122 cl_git_pass(git_blob_filter(&buf, blob, "file.crlf", &filter_opts));
123 cl_assert_equal_sz(0, buf.size);
124 cl_assert_equal_s("", buf.ptr);
125 git_buf_dispose(&buf);
126
127 cl_git_pass(git_blob_filter(&buf, blob, "file.lf", &filter_opts));
128 cl_assert_equal_sz(0, buf.size);
129 cl_assert_equal_s("", buf.ptr);
130 git_buf_dispose(&buf);
131
132 git_blob_free(blob);
133 }
134