Branch data Line data Source code
1 : : #include "sute.h"
2 : :
3 : : /**
4 : : *
5 : : * Validate file-level ignore filtering in a mixed directory
6 : : *
7 : : */
8 : 2 : Return test0009_1(void)
9 : : {
10 : 2 : INITTEST;
11 : 2 : const char *db_filename = "database0009.db";
12 : :
13 : 2 : create(char,result);
14 : 2 : create(char,pattern);
15 : :
16 : 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","false"));
17 : :
18 : 2 : const char *arguments = "--database=database0009.db "
19 : : "--ignore=\"^(?:skip_|tmp_).*\\.(?:log|bak)$\" "
20 : : "tests/fixtures/ignore_include_cases/chaotic_filenames";
21 : :
22 : 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
23 : :
24 : 2 : const char *filename = "templates/0009_001_1.txt";
25 : :
26 : 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
27 : 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
28 : :
29 : 2 : const char *expected_paths[] =
30 : : {
31 : : "alpha_m0n9k2_zz.txt",
32 : : "hold_a1r9v-0pq.bak",
33 : : "keep_4xv7__m2.log",
34 : : "omega_77xy__aa.bin",
35 : : "xqwe_90210.md",
36 : : "zeta_z1-9vv.dat"
37 : : };
38 : :
39 : 2 : ASSERT(SUCCESS == db_paths_match(db_filename,expected_paths,(int)(sizeof(expected_paths) / sizeof(expected_paths[0]))));
40 : :
41 : 2 : ASSERT(SUCCESS == delete_path(db_filename));
42 : :
43 : 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
44 : :
45 : 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
46 : :
47 : 2 : filename = "templates/0009_001_2.txt";
48 : :
49 : 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
50 : 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
51 : :
52 : 2 : ASSERT(SUCCESS == delete_path(db_filename));
53 : :
54 : 2 : del(pattern);
55 : 2 : del(result);
56 : :
57 : 2 : RETURN_STATUS;
58 : : }
59 : :
60 : : /**
61 : : *
62 : : * Validate include over ignore with chaotic filenames
63 : : *
64 : : */
65 : 2 : static Return test0009_2(void)
66 : : {
67 : 2 : INITTEST;
68 : 2 : const char *db_filename = "database0009_2.db";
69 : :
70 : 2 : create(char,result);
71 : 2 : create(char,pattern);
72 : :
73 : 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","false"));
74 : :
75 : 2 : const char *arguments = "--database=database0009_2.db "
76 : : "--ignore=\"^(?:skip_|tmp_|zeta_|omega_).+\" "
77 : : "--include=\"^(?:skip_4xv7__m2\\.log|tmp_qwe_90210\\.log|zeta_z1-9vv\\.dat)$\" "
78 : : "tests/fixtures/ignore_include_cases/chaotic_filenames";
79 : :
80 : 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
81 : :
82 : 2 : const char *filename = "templates/0009_002.txt";
83 : :
84 : 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
85 : 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
86 : :
87 : 2 : const char *expected_paths[] =
88 : : {
89 : : "alpha_m0n9k2_zz.txt",
90 : : "hold_a1r9v-0pq.bak",
91 : : "keep_4xv7__m2.log",
92 : : "skip_4xv7__m2.log",
93 : : "tmp_qwe_90210.log",
94 : : "xqwe_90210.md",
95 : : "zeta_z1-9vv.dat"
96 : : };
97 : :
98 : 2 : ASSERT(SUCCESS == db_paths_match(db_filename,expected_paths,(int)(sizeof(expected_paths) / sizeof(expected_paths[0]))));
99 : :
100 : 2 : ASSERT(SUCCESS == delete_path(db_filename));
101 : :
102 : 2 : del(pattern);
103 : 2 : del(result);
104 : :
105 : 2 : RETURN_STATUS;
106 : : }
107 : :
108 : : /**
109 : : *
110 : : * Validate whole-directory ignore with selective include
111 : : *
112 : : */
113 : 2 : static Return test0009_3(void)
114 : : {
115 : 2 : INITTEST;
116 : 2 : const char *db_filename = "database0009_3.db";
117 : :
118 : 2 : create(char,result);
119 : 2 : create(char,pattern);
120 : :
121 : 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","false"));
122 : :
123 : 2 : const char *arguments = "--database=database0009_3.db "
124 : : "--ignore=\"^chaotic_filenames(?:/|$)\" "
125 : : "--include=\"^chaotic_filenames/(?:alpha_m0n9k2_zz\\.txt|hold_a1r9v-0pq\\.bak|keep_4xv7__m2\\.log|omega_77xy__aa\\.bin|xqwe_90210\\.md|zeta_z1-9vv\\.dat)$\" "
126 : : "tests/fixtures/ignore_include_cases";
127 : :
128 : 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
129 : :
130 : 2 : const char *filename = "templates/0009_003.txt";
131 : :
132 : 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
133 : 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
134 : :
135 : 2 : const char *expected_paths[] =
136 : : {
137 : : "chaotic_filenames/alpha_m0n9k2_zz.txt",
138 : : "chaotic_filenames/hold_a1r9v-0pq.bak",
139 : : "chaotic_filenames/keep_4xv7__m2.log",
140 : : "chaotic_filenames/omega_77xy__aa.bin",
141 : : "chaotic_filenames/xqwe_90210.md",
142 : : "chaotic_filenames/zeta_z1-9vv.dat"
143 : : };
144 : :
145 : 2 : ASSERT(SUCCESS == db_paths_match(db_filename,expected_paths,(int)(sizeof(expected_paths) / sizeof(expected_paths[0]))));
146 : :
147 : 2 : ASSERT(SUCCESS == delete_path(db_filename));
148 : :
149 : 2 : del(pattern);
150 : 2 : del(result);
151 : :
152 : 2 : RETURN_STATUS;
153 : : }
154 : :
155 : : /**
156 : : * @brief Validate update included branch in three passes
157 : : */
158 : 2 : static Return test0009_4(void)
159 : : {
160 : 2 : INITTEST;
161 : :
162 : 2 : const char *db_filename = "database0009_4.db";
163 : 2 : create(char,result);
164 : 2 : create(char,pattern);
165 : :
166 : 2 : ASSERT(SUCCESS == move_path("tests/fixtures/ignore_include_cases/chaotic_filenames","tests/fixtures/ignore_include_cases/chaotic_filenames_backup"));
167 : 2 : ASSERT(SUCCESS == copy_path("tests/fixtures/ignore_include_cases/chaotic_filenames_backup","tests/fixtures/ignore_include_cases/chaotic_filenames"));
168 : :
169 : 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
170 : :
171 : 2 : const char *arguments_create = "--database=database0009_4.db "
172 : : "--ignore=\"^(?:skip_|tmp_).+\" "
173 : : "--include=\"^(?:skip_4xv7__m2\\.log|tmp_qwe_90210\\.log|tmp_z1-9vv\\.bak)$\" "
174 : : "tests/fixtures/ignore_include_cases/chaotic_filenames";
175 : :
176 : : /*
177 : : * Create the baseline DB using the same ignore/include rules as the later update passes
178 : : * We intentionally build the initial record set as "tracked-after-filters" and not as "all files in directory"
179 : : * Update mode processes the current filtered set and does not retroactively delete rows that were inserted earlier
180 : : * If this first pass omitted filters, all 12 paths would be stored and the update-included scenario would validate a different logic branch
181 : : */
182 : 2 : ASSERT(SUCCESS == runit(arguments_create,result,NULL,COMPLETED,ALLOW_BOTH));
183 : :
184 : 2 : const char *filename = "templates/0009_004_1.txt";
185 : 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
186 : 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
187 : :
188 : 2 : const char *change_file_command = "cd \"${TMPDIR}\"; "
189 : : "printf ' ' >> tests/fixtures/ignore_include_cases/chaotic_filenames/skip_4xv7__m2.log";
190 : 2 : ASSERT(SUCCESS == external_call(change_file_command,NULL,NULL,COMPLETED,ALLOW_BOTH));
191 : :
192 : 2 : const char *arguments_update = "--update --database=database0009_4.db "
193 : : "--ignore=\"^(?:skip_|tmp_).+\" "
194 : : "--include=\"^(?:skip_4xv7__m2\\.log|tmp_qwe_90210\\.log|tmp_z1-9vv\\.bak)$\" "
195 : : "tests/fixtures/ignore_include_cases/chaotic_filenames";
196 : :
197 : : // Update mode pass where only one included file has changed
198 : 2 : ASSERT(SUCCESS == runit(arguments_update,result,NULL,COMPLETED,ALLOW_BOTH));
199 : :
200 : 2 : filename = "templates/0009_004_2.txt";
201 : 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
202 : 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
203 : :
204 : 2 : const char *change_files_command = "cd \"${TMPDIR}\"; "
205 : : "printf ' ' >> tests/fixtures/ignore_include_cases/chaotic_filenames/tmp_qwe_90210.log; "
206 : : "printf ' ' >> tests/fixtures/ignore_include_cases/chaotic_filenames/tmp_z1-9vv.bak";
207 : 2 : ASSERT(SUCCESS == external_call(change_files_command,NULL,NULL,COMPLETED,ALLOW_BOTH));
208 : : // Truncate a tracked non-included file to trigger the "update as empty" branch
209 : 2 : ASSERT(SUCCESS == truncate_file_to_zero_size("tests/fixtures/ignore_include_cases/chaotic_filenames/alpha_m0n9k2_zz.txt"));
210 : :
211 : 2 : const char *arguments_update_watch = "--watch-timestamps --update --database=database0009_4.db "
212 : : "--ignore=\"^(?:skip_|tmp_).+\" "
213 : : "--include=\"^(?:skip_4xv7__m2\\.log|tmp_qwe_90210\\.log|tmp_z1-9vv\\.bak)$\" "
214 : : "tests/fixtures/ignore_include_cases/chaotic_filenames";
215 : :
216 : : // Update mode with watch-timestamps enabled where one non-included file becomes empty and two included files are updated
217 : 2 : ASSERT(SUCCESS == runit(arguments_update_watch,result,NULL,COMPLETED,ALLOW_BOTH));
218 : :
219 : 2 : filename = "templates/0009_004_3.txt";
220 : 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
221 : 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
222 : :
223 : 2 : const char *expected_paths[] =
224 : : {
225 : : "alpha_m0n9k2_zz.txt",
226 : : "hold_a1r9v-0pq.bak",
227 : : "keep_4xv7__m2.log",
228 : : "omega_77xy__aa.bin",
229 : : "skip_4xv7__m2.log",
230 : : "tmp_qwe_90210.log",
231 : : "tmp_z1-9vv.bak",
232 : : "xqwe_90210.md",
233 : : "zeta_z1-9vv.dat"
234 : : };
235 : :
236 : 2 : ASSERT(SUCCESS == db_paths_match(db_filename,expected_paths,(int)(sizeof(expected_paths) / sizeof(expected_paths[0]))));
237 : 2 : ASSERT(SUCCESS == delete_path(db_filename));
238 : :
239 : 2 : ASSERT(SUCCESS == delete_path("tests/fixtures/ignore_include_cases/chaotic_filenames"));
240 : 2 : ASSERT(SUCCESS == move_path("tests/fixtures/ignore_include_cases/chaotic_filenames_backup","tests/fixtures/ignore_include_cases/chaotic_filenames"));
241 : :
242 : 2 : del(pattern);
243 : 2 : del(result);
244 : :
245 : 2 : RETURN_STATUS;
246 : : }
247 : :
248 : 2 : Return test0009(void)
249 : : {
250 : 2 : INITTEST;
251 : :
252 : 2 : TEST(test0009_1,"Ignore regexp splits chaotic filenames into tracked and skipped sets…");
253 : 2 : TEST(test0009_2,"Ignore most files and include back selected ones…");
254 : 2 : TEST(test0009_3,"Directory ignore with selective child include…");
255 : 2 : TEST(test0009_4,"Create then update included files with and without detailed change output…");
256 : :
257 : 2 : RETURN_STATUS;
258 : : }
|