Branch data Line data Source code
1 : : #include "sute.h"
2 : :
3 : : /**
4 : : * @brief Truncate an existing file to zero bytes by reopening it in binary write mode
5 : : *
6 : : * @param[in] relative_path_to_tmpdir Relative path from TMPDIR to the target file
7 : : *
8 : : * @return Return status code:
9 : : * - SUCCESS: File was truncated successfully
10 : : * - FAILURE: Path construction or file operation failed
11 : : */
12 : 2 : static Return truncate_file_to_zero_size(
13 : : const char *relative_path_to_tmpdir)
14 : : {
15 : : /* Status returned by this function through provide()
16 : : Default value assumes successful completion */
17 : 2 : Return status = SUCCESS;
18 : :
19 : 2 : create(char,absolute_path);
20 : :
21 [ - + ]: 2 : if(relative_path_to_tmpdir == NULL)
22 : : {
23 : 0 : status = FAILURE;
24 : : }
25 : :
26 [ + - ]: 2 : if(SUCCESS == status)
27 : : {
28 : 2 : status = construct_path(relative_path_to_tmpdir,absolute_path);
29 : : }
30 : :
31 [ + - ]: 2 : if(SUCCESS == status)
32 : : {
33 : 2 : FILE *file = fopen(getcstring(absolute_path),"wb");
34 : :
35 [ - + ]: 2 : if(file == NULL)
36 : : {
37 : 0 : status = FAILURE;
38 [ - + ]: 2 : } else if(fclose(file) != 0){
39 : 0 : status = FAILURE;
40 : : }
41 : : }
42 : :
43 : 2 : del(absolute_path);
44 : :
45 : 2 : return(status);
46 : : }
47 : :
48 : : /**
49 : : *
50 : : * Validate file-level ignore filtering in a mixed directory
51 : : *
52 : : */
53 : 2 : Return test0009_1(void)
54 : : {
55 : 2 : INITTEST;
56 : :
57 : 2 : create(char,result);
58 : 2 : create(char,pattern);
59 : :
60 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","false"));
61 : :
62 : 2 : const char *arguments = "--database=database0009.db "
63 : : "--ignore=\"^(?:skip_|tmp_).*\\.(?:log|bak)$\" "
64 : : "tests/fixtures/ignore_include_cases/chaotic_filenames";
65 : :
66 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
67 : :
68 : 2 : const char *filename = "templates/0009_001_1.txt";
69 : :
70 [ + - + - ]: 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
71 [ + - + - ]: 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
72 : :
73 : 2 : const char *expected_paths[] =
74 : : {
75 : : "alpha_m0n9k2_zz.txt",
76 : : "hold_a1r9v-0pq.bak",
77 : : "keep_4xv7__m2.log",
78 : : "omega_77xy__aa.bin",
79 : : "xqwe_90210.md",
80 : : "zeta_z1-9vv.dat"
81 : : };
82 : :
83 [ + - + - ]: 2 : ASSERT(SUCCESS == db_paths_match("database0009.db",expected_paths,(int)(sizeof(expected_paths) / sizeof(expected_paths[0]))));
84 : :
85 : 2 : const char *command = "rm \"${TMPDIR}/database0009.db\"";
86 : :
87 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
88 : :
89 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
90 : :
91 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
92 : :
93 : 2 : filename = "templates/0009_001_2.txt";
94 : :
95 [ + - + - ]: 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
96 [ + - + - ]: 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
97 : :
98 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
99 : :
100 : 2 : del(pattern);
101 : 2 : del(result);
102 : :
103 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
104 : : }
105 : :
106 : : /**
107 : : *
108 : : * Validate include over ignore with chaotic filenames
109 : : *
110 : : */
111 : 2 : static Return test0009_2(void)
112 : : {
113 : 2 : INITTEST;
114 : :
115 : 2 : create(char,result);
116 : 2 : create(char,pattern);
117 : :
118 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","false"));
119 : :
120 : 2 : const char *arguments = "--database=database0009_2.db "
121 : : "--ignore=\"^(?:skip_|tmp_|zeta_|omega_).+\" "
122 : : "--include=\"^(?:skip_4xv7__m2\\.log|tmp_qwe_90210\\.log|zeta_z1-9vv\\.dat)$\" "
123 : : "tests/fixtures/ignore_include_cases/chaotic_filenames";
124 : :
125 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
126 : :
127 : 2 : const char *filename = "templates/0009_002.txt";
128 : :
129 [ + - + - ]: 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
130 [ + - + - ]: 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
131 : :
132 : 2 : const char *expected_paths[] =
133 : : {
134 : : "alpha_m0n9k2_zz.txt",
135 : : "hold_a1r9v-0pq.bak",
136 : : "keep_4xv7__m2.log",
137 : : "skip_4xv7__m2.log",
138 : : "tmp_qwe_90210.log",
139 : : "xqwe_90210.md",
140 : : "zeta_z1-9vv.dat"
141 : : };
142 : :
143 [ + - + - ]: 2 : ASSERT(SUCCESS == db_paths_match("database0009_2.db",expected_paths,(int)(sizeof(expected_paths) / sizeof(expected_paths[0]))));
144 : :
145 : 2 : const char *command = "rm \"${TMPDIR}/database0009_2.db\"";
146 : :
147 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
148 : :
149 : 2 : del(pattern);
150 : 2 : del(result);
151 : :
152 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
153 : : }
154 : :
155 : : /**
156 : : *
157 : : * Validate whole-directory ignore with selective include
158 : : *
159 : : */
160 : 2 : static Return test0009_3(void)
161 : : {
162 : 2 : INITTEST;
163 : :
164 : 2 : create(char,result);
165 : 2 : create(char,pattern);
166 : :
167 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","false"));
168 : :
169 : 2 : const char *arguments = "--database=database0009_3.db "
170 : : "--ignore=\"^chaotic_filenames(?:/|$)\" "
171 : : "--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)$\" "
172 : : "tests/fixtures/ignore_include_cases";
173 : :
174 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
175 : :
176 : 2 : const char *filename = "templates/0009_003.txt";
177 : :
178 [ + - + - ]: 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
179 [ + - + - ]: 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
180 : :
181 : 2 : const char *expected_paths[] =
182 : : {
183 : : "chaotic_filenames/alpha_m0n9k2_zz.txt",
184 : : "chaotic_filenames/hold_a1r9v-0pq.bak",
185 : : "chaotic_filenames/keep_4xv7__m2.log",
186 : : "chaotic_filenames/omega_77xy__aa.bin",
187 : : "chaotic_filenames/xqwe_90210.md",
188 : : "chaotic_filenames/zeta_z1-9vv.dat"
189 : : };
190 : :
191 [ + - + - ]: 2 : ASSERT(SUCCESS == db_paths_match("database0009_3.db",expected_paths,(int)(sizeof(expected_paths) / sizeof(expected_paths[0]))));
192 : :
193 : 2 : const char *command = "rm \"${TMPDIR}/database0009_3.db\"";
194 : :
195 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
196 : :
197 : 2 : del(pattern);
198 : 2 : del(result);
199 : :
200 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
201 : : }
202 : :
203 : : /**
204 : : * @brief Validate update included branch in three passes
205 : : */
206 : 2 : static Return test0009_4(void)
207 : : {
208 : 2 : INITTEST;
209 : :
210 : 2 : create(char,result);
211 : 2 : create(char,pattern);
212 : :
213 : 2 : const char *prepare_fixture_command =
214 : : "cd \"${TMPDIR}\"; "
215 : : "rm -rf tests/fixtures/ignore_include_cases/chaotic_filenames_backup; "
216 : : "mv tests/fixtures/ignore_include_cases/chaotic_filenames tests/fixtures/ignore_include_cases/chaotic_filenames_backup; "
217 : : "cp -a tests/fixtures/ignore_include_cases/chaotic_filenames_backup tests/fixtures/ignore_include_cases/chaotic_filenames;";
218 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(prepare_fixture_command,NULL,NULL,COMPLETED,ALLOW_BOTH));
219 : :
220 : 2 : const char *remove_db_command = "rm -f \"${TMPDIR}/database0009_4.db\"";
221 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(remove_db_command,NULL,NULL,COMPLETED,ALLOW_BOTH));
222 : :
223 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
224 : :
225 : 2 : const char *arguments_create = "--database=database0009_4.db "
226 : : "--ignore=\"^(?:skip_|tmp_).+\" "
227 : : "--include=\"^(?:skip_4xv7__m2\\.log|tmp_qwe_90210\\.log|tmp_z1-9vv\\.bak)$\" "
228 : : "tests/fixtures/ignore_include_cases/chaotic_filenames";
229 : :
230 : : /*
231 : : * Create the baseline DB using the same ignore/include rules as the later update passes
232 : : * We intentionally build the initial record set as "tracked-after-filters" and not as "all files in directory"
233 : : * Update mode processes the current filtered set and does not retroactively delete rows that were inserted earlier
234 : : * If this first pass omitted filters, all 12 paths would be stored and the update-included scenario would validate a different logic branch
235 : : */
236 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments_create,result,NULL,COMPLETED,ALLOW_BOTH));
237 : :
238 : 2 : const char *filename = "templates/0009_004_1.txt";
239 [ + - + - ]: 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
240 [ + - + - ]: 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
241 : :
242 : 2 : const char *change_file_command = "cd \"${TMPDIR}\"; "
243 : : "printf ' ' >> tests/fixtures/ignore_include_cases/chaotic_filenames/skip_4xv7__m2.log";
244 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(change_file_command,NULL,NULL,COMPLETED,ALLOW_BOTH));
245 : :
246 : 2 : const char *arguments_update = "--update --database=database0009_4.db "
247 : : "--ignore=\"^(?:skip_|tmp_).+\" "
248 : : "--include=\"^(?:skip_4xv7__m2\\.log|tmp_qwe_90210\\.log|tmp_z1-9vv\\.bak)$\" "
249 : : "tests/fixtures/ignore_include_cases/chaotic_filenames";
250 : :
251 : : // Update mode pass where only one included file has changed
252 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments_update,result,NULL,COMPLETED,ALLOW_BOTH));
253 : :
254 : 2 : filename = "templates/0009_004_2.txt";
255 [ + - + - ]: 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
256 [ + - + - ]: 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
257 : :
258 : 2 : const char *change_files_command = "cd \"${TMPDIR}\"; "
259 : : "printf ' ' >> tests/fixtures/ignore_include_cases/chaotic_filenames/tmp_qwe_90210.log; "
260 : : "printf ' ' >> tests/fixtures/ignore_include_cases/chaotic_filenames/tmp_z1-9vv.bak";
261 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(change_files_command,NULL,NULL,COMPLETED,ALLOW_BOTH));
262 : : // Truncate a tracked non-included file to trigger the "update as empty" branch
263 [ + - + - ]: 2 : ASSERT(SUCCESS == truncate_file_to_zero_size("tests/fixtures/ignore_include_cases/chaotic_filenames/alpha_m0n9k2_zz.txt"));
264 : :
265 : 2 : const char *arguments_update_watch = "--watch-timestamps --update --database=database0009_4.db "
266 : : "--ignore=\"^(?:skip_|tmp_).+\" "
267 : : "--include=\"^(?:skip_4xv7__m2\\.log|tmp_qwe_90210\\.log|tmp_z1-9vv\\.bak)$\" "
268 : : "tests/fixtures/ignore_include_cases/chaotic_filenames";
269 : :
270 : : // Update mode with watch-timestamps enabled where one non-included file becomes empty and two included files are updated
271 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments_update_watch,result,NULL,COMPLETED,ALLOW_BOTH));
272 : :
273 : 2 : filename = "templates/0009_004_3.txt";
274 [ + - + - ]: 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
275 [ + - + - ]: 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
276 : :
277 : 2 : const char *expected_paths[] =
278 : : {
279 : : "alpha_m0n9k2_zz.txt",
280 : : "hold_a1r9v-0pq.bak",
281 : : "keep_4xv7__m2.log",
282 : : "omega_77xy__aa.bin",
283 : : "skip_4xv7__m2.log",
284 : : "tmp_qwe_90210.log",
285 : : "tmp_z1-9vv.bak",
286 : : "xqwe_90210.md",
287 : : "zeta_z1-9vv.dat"
288 : : };
289 : :
290 [ + - + - ]: 2 : ASSERT(SUCCESS == db_paths_match("database0009_4.db",expected_paths,(int)(sizeof(expected_paths) / sizeof(expected_paths[0]))));
291 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(remove_db_command,NULL,NULL,COMPLETED,ALLOW_BOTH));
292 : :
293 : 2 : const char *restore_fixture_command =
294 : : "cd \"${TMPDIR}\"; "
295 : : "rm -rf tests/fixtures/ignore_include_cases/chaotic_filenames; "
296 : : "mv tests/fixtures/ignore_include_cases/chaotic_filenames_backup tests/fixtures/ignore_include_cases/chaotic_filenames;";
297 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(restore_fixture_command,NULL,NULL,COMPLETED,ALLOW_BOTH));
298 : :
299 : 2 : del(pattern);
300 : 2 : del(result);
301 : :
302 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
303 : : }
304 : :
305 : 2 : Return test0009(void)
306 : : {
307 : 2 : INITTEST;
308 : :
309 [ + - ]: 2 : TEST(test0009_1,"Ignore regexp splits chaotic filenames into tracked and skipped sets…");
310 [ + - ]: 2 : TEST(test0009_2,"Ignore most files and include back selected ones…");
311 [ + - ]: 2 : TEST(test0009_3,"Directory ignore with selective child include…");
312 [ + - ]: 2 : TEST(test0009_4,"Create then update included files with and without detailed change output…");
313 : :
314 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
315 : : }
|