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 : m_create(char,result,MEMORY_STRING);
14 : 2 : m_create(char,pattern,MEMORY_STRING);
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 : m_del(pattern);
55 : 2 : m_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 : m_create(char,result,MEMORY_STRING);
71 : 2 : m_create(char,pattern,MEMORY_STRING);
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 : m_del(pattern);
103 : 2 : m_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 : m_create(char,result,MEMORY_STRING);
119 : 2 : m_create(char,pattern,MEMORY_STRING);
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 : m_del(pattern);
150 : 2 : m_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 : m_create(char,result,MEMORY_STRING);
164 : 2 : m_create(char,pattern,MEMORY_STRING);
165 : :
166 : 2 : ASSERT(SUCCESS == prepare_mutable_fixture("tests/fixtures/ignore_include_cases/chaotic_filenames"));
167 : :
168 : 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
169 : :
170 : 2 : const char *arguments_create = "--database=database0009_4.db "
171 : : "--ignore=\"^(?:skip_|tmp_).+\" "
172 : : "--include=\"^(?:skip_4xv7__m2\\.log|tmp_qwe_90210\\.log|tmp_z1-9vv\\.bak)$\" "
173 : : "tests/fixtures/ignore_include_cases/chaotic_filenames";
174 : :
175 : : /*
176 : : * Create the baseline DB using the same ignore/include rules as the later update passes
177 : : * We intentionally build the initial record set as "tracked-after-filters" and not as "all files in directory"
178 : : * Update mode processes the current filtered set and does not retroactively delete rows that were inserted earlier
179 : : * If this first pass omitted filters, all 12 paths would be stored and the update-included scenario would validate a different logic branch
180 : : */
181 : 2 : ASSERT(SUCCESS == runit(arguments_create,result,NULL,COMPLETED,ALLOW_BOTH));
182 : :
183 : 2 : const char *filename = "templates/0009_004_1.txt";
184 : 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
185 : 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
186 : :
187 : 2 : ASSERT(SUCCESS == add_string_to(" ","tests/fixtures/ignore_include_cases/chaotic_filenames/skip_4xv7__m2.log"));
188 : :
189 : 2 : const char *arguments_update = "--update --database=database0009_4.db "
190 : : "--ignore=\"^(?:skip_|tmp_).+\" "
191 : : "--include=\"^(?:skip_4xv7__m2\\.log|tmp_qwe_90210\\.log|tmp_z1-9vv\\.bak)$\" "
192 : : "tests/fixtures/ignore_include_cases/chaotic_filenames";
193 : :
194 : : // Update mode pass where only one included file has changed
195 : 2 : ASSERT(SUCCESS == runit(arguments_update,result,NULL,COMPLETED,ALLOW_BOTH));
196 : :
197 : 2 : filename = "templates/0009_004_2.txt";
198 : 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
199 : 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
200 : :
201 : 2 : ASSERT(SUCCESS == add_string_to(" ","tests/fixtures/ignore_include_cases/chaotic_filenames/tmp_qwe_90210.log"));
202 : 2 : ASSERT(SUCCESS == add_string_to(" ","tests/fixtures/ignore_include_cases/chaotic_filenames/tmp_z1-9vv.bak"));
203 : : // Truncate a tracked non-included file to trigger the "update as empty" branch
204 : 2 : ASSERT(SUCCESS == truncate_file_to_zero_size("tests/fixtures/ignore_include_cases/chaotic_filenames/alpha_m0n9k2_zz.txt"));
205 : :
206 : 2 : const char *arguments_update_watch = "--watch-timestamps --update --database=database0009_4.db "
207 : : "--ignore=\"^(?:skip_|tmp_).+\" "
208 : : "--include=\"^(?:skip_4xv7__m2\\.log|tmp_qwe_90210\\.log|tmp_z1-9vv\\.bak)$\" "
209 : : "tests/fixtures/ignore_include_cases/chaotic_filenames";
210 : :
211 : : // Update mode with watch-timestamps enabled where one non-included file becomes empty and two included files are updated
212 : 2 : ASSERT(SUCCESS == runit(arguments_update_watch,result,NULL,COMPLETED,ALLOW_BOTH));
213 : :
214 : 2 : filename = "templates/0009_004_3.txt";
215 : 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
216 : 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
217 : :
218 : 2 : const char *expected_paths[] =
219 : : {
220 : : "alpha_m0n9k2_zz.txt",
221 : : "hold_a1r9v-0pq.bak",
222 : : "keep_4xv7__m2.log",
223 : : "omega_77xy__aa.bin",
224 : : "skip_4xv7__m2.log",
225 : : "tmp_qwe_90210.log",
226 : : "tmp_z1-9vv.bak",
227 : : "xqwe_90210.md",
228 : : "zeta_z1-9vv.dat"
229 : : };
230 : :
231 : 2 : ASSERT(SUCCESS == db_paths_match(db_filename,expected_paths,(int)(sizeof(expected_paths) / sizeof(expected_paths[0]))));
232 : 2 : ASSERT(SUCCESS == delete_path(db_filename));
233 : :
234 : 2 : ASSERT(SUCCESS == restore_mutable_fixture("tests/fixtures/ignore_include_cases/chaotic_filenames"));
235 : :
236 : 2 : m_del(pattern);
237 : 2 : m_del(result);
238 : :
239 : 2 : RETURN_STATUS;
240 : : }
241 : :
242 : : /**
243 : : * @brief Verify ignored missing DB rows stay outside cleanup without --db-drop-ignored
244 : : *
245 : : * The test creates a database with all fixture files, removes one file below a
246 : : * later ignored subtree, then runs update with the matching --ignore pattern.
247 : : * The deleted ignored row must remain in the DB and must not be reported as
248 : : * missing-file cleanup
249 : : */
250 : 2 : static Return test0009_5(void)
251 : : {
252 : 2 : INITTEST;
253 : :
254 : 2 : const char *db_file_name = "database0009_5.db";
255 : 2 : const char *ignored_relative_path = "path2/AAA/ZAW/D/e/f/b_file.txt";
256 : 2 : const char *arguments = NULL;
257 : 2 : bool ignored_row_exists = false;
258 : 2 : m_create(char,result,MEMORY_STRING);
259 : 2 : m_create(char,pattern,MEMORY_STRING);
260 : :
261 : 2 : ASSERT(SUCCESS == prepare_mutable_fixture("tests/fixtures/diffs/diff1"));
262 : 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
263 : :
264 : 2 : arguments = "--database=database0009_5.db tests/fixtures/diffs/diff1";
265 : 2 : ASSERT(SUCCESS == runit(arguments,NULL,NULL,COMPLETED,ALLOW_BOTH));
266 : :
267 : 2 : ASSERT(SUCCESS == delete_path("tests/fixtures/diffs/diff1/path2/AAA/ZAW/D/e/f/b_file.txt"));
268 : :
269 : 2 : arguments = "--update --ignore=\"^path2/AAA/ZAW/.*\" "
270 : : "--database=database0009_5.db tests/fixtures/diffs/diff1";
271 : 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
272 : :
273 : 2 : const char *filename = "templates/0009_005.txt";
274 : 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
275 : 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
276 : :
277 : 2 : ASSERT(SUCCESS == db_relative_path_exists(db_file_name,ignored_relative_path,&ignored_row_exists));
278 : 2 : ASSERT(ignored_row_exists == true);
279 : :
280 : 2 : ASSERT(SUCCESS == delete_path(db_file_name));
281 : 2 : ASSERT(SUCCESS == restore_mutable_fixture("tests/fixtures/diffs/diff1"));
282 : :
283 : 2 : m_del(pattern);
284 : 2 : m_del(result);
285 : :
286 : 2 : RETURN_STATUS;
287 : : }
288 : :
289 : : /**
290 : : * @brief Verify --include restores an ignored missing DB row to cleanup scope
291 : : *
292 : : * The test deletes a file that matches both --ignore and --include during the
293 : : * update run. The include pattern must make cleanup treat the missing row as a
294 : : * normal tracked path, delete it from the DB, and report it as no longer present
295 : : */
296 : 2 : static Return test0009_6(void)
297 : : {
298 : 2 : INITTEST;
299 : :
300 : 2 : const char *db_file_name = "database0009_6.db";
301 : 2 : const char *included_relative_path = "path2/AAA/ZAW/D/e/f/b_file.txt";
302 : 2 : const char *arguments = NULL;
303 : 2 : bool included_row_exists = true;
304 : 2 : m_create(char,result,MEMORY_STRING);
305 : 2 : m_create(char,pattern,MEMORY_STRING);
306 : :
307 : 2 : ASSERT(SUCCESS == prepare_mutable_fixture("tests/fixtures/diffs/diff1"));
308 : 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
309 : :
310 : 2 : arguments = "--database=database0009_6.db tests/fixtures/diffs/diff1";
311 : 2 : ASSERT(SUCCESS == runit(arguments,NULL,NULL,COMPLETED,ALLOW_BOTH));
312 : :
313 : 2 : ASSERT(SUCCESS == delete_path("tests/fixtures/diffs/diff1/path2/AAA/ZAW/D/e/f/b_file.txt"));
314 : :
315 : 2 : arguments = "--update --ignore=\"^path2/AAA/ZAW/.*\" "
316 : : "--include=\"^path2/AAA/ZAW/D/e/f/b_file\\.txt$\" "
317 : : "--database=database0009_6.db tests/fixtures/diffs/diff1";
318 : 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
319 : :
320 : 2 : const char *filename = "templates/0009_006.txt";
321 : 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
322 : 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
323 : :
324 : 2 : ASSERT(SUCCESS == db_relative_path_exists(db_file_name,included_relative_path,&included_row_exists));
325 : 2 : ASSERT(included_row_exists == false);
326 : :
327 : 2 : ASSERT(SUCCESS == delete_path(db_file_name));
328 : 2 : ASSERT(SUCCESS == restore_mutable_fixture("tests/fixtures/diffs/diff1"));
329 : :
330 : 2 : m_del(pattern);
331 : 2 : m_del(result);
332 : :
333 : 2 : RETURN_STATUS;
334 : : }
335 : :
336 : : /**
337 : : * @brief Verify --db-drop-ignored removes an ignored missing DB row as ignored
338 : : *
339 : : * A deleted file row that matches --ignore must be classified as ignored cleanup
340 : : * when --db-drop-ignored is present, not as ordinary missing-file cleanup
341 : : */
342 : 2 : static Return test0009_7(void)
343 : : {
344 : 2 : INITTEST;
345 : :
346 : 2 : const char *db_file_name = "database0009_7.db";
347 : 2 : const char *ignored_relative_path = "path2/AAA/ZAW/D/e/f/b_file.txt";
348 : 2 : const char *arguments = NULL;
349 : 2 : bool ignored_row_exists = true;
350 : 2 : m_create(char,result,MEMORY_STRING);
351 : 2 : m_create(char,pattern,MEMORY_STRING);
352 : :
353 : 2 : ASSERT(SUCCESS == prepare_mutable_fixture("tests/fixtures/diffs/diff1"));
354 : 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
355 : :
356 : 2 : arguments = "--database=database0009_7.db tests/fixtures/diffs/diff1";
357 : 2 : ASSERT(SUCCESS == runit(arguments,NULL,NULL,COMPLETED,ALLOW_BOTH));
358 : :
359 : 2 : ASSERT(SUCCESS == delete_path("tests/fixtures/diffs/diff1/path2/AAA/ZAW/D/e/f/b_file.txt"));
360 : :
361 : 2 : arguments = "--update --db-drop-ignored "
362 : : "--ignore=\"^path2/AAA/ZAW/D/e/f/b_file\\.txt$\" "
363 : : "--database=database0009_7.db tests/fixtures/diffs/diff1";
364 : 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
365 : :
366 : 2 : const char *filename = "templates/0009_007.txt";
367 : 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
368 : 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
369 : :
370 : 2 : ASSERT(SUCCESS == db_relative_path_exists(db_file_name,ignored_relative_path,&ignored_row_exists));
371 : 2 : ASSERT(ignored_row_exists == false);
372 : :
373 : 2 : ASSERT(SUCCESS == delete_path(db_file_name));
374 : 2 : ASSERT(SUCCESS == restore_mutable_fixture("tests/fixtures/diffs/diff1"));
375 : :
376 : 2 : m_del(pattern);
377 : 2 : m_del(result);
378 : :
379 : 2 : RETURN_STATUS;
380 : : }
381 : :
382 : : /**
383 : : * @brief Verify --db-drop-ignored removes an ignored existing DB row
384 : : *
385 : : * The ignored file still exists on disk, so this covers explicit ignored
386 : : * cleanup independently from missing-file cleanup
387 : : */
388 : 2 : static Return test0009_8(void)
389 : : {
390 : 2 : INITTEST;
391 : :
392 : 2 : const char *db_file_name = "database0009_8.db";
393 : 2 : const char *ignored_relative_path = "path2/AAA/ZAW/D/e/f/b_file.txt";
394 : 2 : const char *arguments = NULL;
395 : 2 : bool ignored_row_exists = true;
396 : 2 : m_create(char,result,MEMORY_STRING);
397 : 2 : m_create(char,pattern,MEMORY_STRING);
398 : :
399 : 2 : ASSERT(SUCCESS == prepare_mutable_fixture("tests/fixtures/diffs/diff1"));
400 : 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
401 : :
402 : 2 : arguments = "--database=database0009_8.db tests/fixtures/diffs/diff1";
403 : 2 : ASSERT(SUCCESS == runit(arguments,NULL,NULL,COMPLETED,ALLOW_BOTH));
404 : :
405 : 2 : arguments = "--update --db-drop-ignored "
406 : : "--ignore=\"^path2/AAA/ZAW/D/e/f/b_file\\.txt$\" "
407 : : "--database=database0009_8.db tests/fixtures/diffs/diff1";
408 : 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
409 : :
410 : 2 : const char *filename = "templates/0009_008.txt";
411 : 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
412 : 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
413 : :
414 : 2 : ASSERT(SUCCESS == db_relative_path_exists(db_file_name,ignored_relative_path,&ignored_row_exists));
415 : 2 : ASSERT(ignored_row_exists == false);
416 : :
417 : 2 : ASSERT(SUCCESS == delete_path(db_file_name));
418 : 2 : ASSERT(SUCCESS == restore_mutable_fixture("tests/fixtures/diffs/diff1"));
419 : :
420 : 2 : m_del(pattern);
421 : 2 : m_del(result);
422 : :
423 : 2 : RETURN_STATUS;
424 : : }
425 : :
426 : 2 : Return test0009(void)
427 : : {
428 : 2 : INITTEST;
429 : :
430 : 2 : TEST(test0009_1,"Ignore regexp splits chaotic filenames into tracked and skipped sets");
431 : 2 : TEST(test0009_2,"Ignore most files and include back selected ones");
432 : 2 : TEST(test0009_3,"Directory ignore with selective child include");
433 : 2 : TEST(test0009_4,"Create then update included files with and without detailed change output");
434 : 2 : TEST(test0009_5,"Ignored missing DB rows stay outside cleanup without --db-drop-ignored");
435 : 2 : TEST(test0009_6,"--include restores an ignored missing DB row to cleanup scope");
436 : 2 : TEST(test0009_7,"--db-drop-ignored removes an ignored missing DB row as ignored");
437 : 2 : TEST(test0009_8,"--db-drop-ignored removes an ignored existing DB row");
438 : :
439 : 2 : RETURN_STATUS;
440 : : }
|