Branch data Line data Source code
1 : : #include "sute.h"
2 : :
3 : : /**
4 : : * The Example 1 from README:
5 : : * Now some tests could be running:
6 : : * Stage 1. Adding:
7 : : * precizer --progress --database=database1.db tests/fixtures/diffs/diff1
8 : : * Stage 2. Adding:
9 : : * precizer --progress --database=database2.db tests/fixtures/diffs/diff2
10 : : * Final stage. Comparing:
11 : : * precizer --compare database1.db database2.db
12 : : */
13 : 2 : static Return test0011_1(void)
14 : : {
15 : 2 : INITTEST;
16 : :
17 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
18 : :
19 : : // Create memory for the result
20 : 2 : create(char,result);
21 : 2 : create(char,chunk);
22 : :
23 : 2 : const char *arguments = "--progress --database=database1.db "
24 : : "tests/fixtures/diffs/diff1";
25 : :
26 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,chunk,NULL,COMPLETED,ALLOW_BOTH));
27 [ + - + - ]: 2 : ASSERT(SUCCESS == copy(result,chunk));
28 : :
29 : 2 : arguments = "--progress --database=database2.db "
30 : : "tests/fixtures/diffs/diff2";
31 : :
32 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,chunk,NULL,COMPLETED,ALLOW_BOTH));
33 [ + - + - ]: 2 : ASSERT(SUCCESS == concat_strings(result,chunk));
34 : :
35 : 2 : arguments = "--compare database1.db database2.db";
36 : :
37 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,chunk,NULL,COMPLETED,ALLOW_BOTH));
38 [ + - + - ]: 2 : ASSERT(SUCCESS == concat_strings(result,chunk));
39 : :
40 : 2 : create(char,pattern);
41 : :
42 : 2 : const char *filename = "templates/0011_001.txt";
43 : :
44 [ + - + - ]: 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
45 : :
46 : : // Match the result against the pattern
47 [ + - + - ]: 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
48 : :
49 : : // Clean up test results
50 : 2 : const char *command = "cd ${TMPDIR};"
51 : : "rm database1.db database2.db";
52 : :
53 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
54 : :
55 : 2 : del(pattern);
56 : 2 : del(chunk);
57 : 2 : del(result);
58 : :
59 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
60 : : }
61 : :
62 : : /**
63 : : * The Example 2 from README
64 : : * Updating the database:
65 : : * Stage 1. Adding:
66 : : * precizer --progress --database=database1.db tests/fixtures/diffs/diff1
67 : : * Stage 2. Reuse previous example once agan. The first try. The warning message.
68 : : * precizer --progress --database=database1.db tests/fixtures/diffs/diff1
69 : : * Stage 3. Run of database update without making actual changes to disk:
70 : : * precizer --update --progress --database=database1.db tests/fixtures/diffs/diff1
71 : : * Stage 4. Now let's make some changes:
72 : : * # Backup
73 : : * mv tests/fixtures/diffs/diff1 tests/fixtures/diff1_backup
74 : : * cp -a tests/fixtures/diff1_backup tests/fixtures/diffs/diff1
75 : : * # Modify a file
76 : : * echo -n " " >> tests/fixtures/diffs/diff1/1/AAA/BCB/CCC/a.txt
77 : : * # Add a new file
78 : : * touch tests/fixtures/diffs/diff1/1/AAA/BCB/CCC/c.txt
79 : : * # Remove a file
80 : : * rm tests/fixtures/diffs/diff1/path2/AAA/ZAW/D/e/f/b_file.txt
81 : : * Stage 5. Run the precizer once again:
82 : : * precizer --update --progress --database=database1.db tests/fixtures/diffs/diff1
83 : : * Final stage. Recover from backup:
84 : : * rm -rf tests/fixtures/diffs/diff1
85 : : * mv tests/fixtures/diff1_backup tests/fixtures/diffs/diff1
86 : : */
87 : 2 : static Return test0011_2(void)
88 : : {
89 : 2 : INITTEST;
90 : :
91 : 2 : const char *command = "cd ${TMPDIR};"
92 : : "mv tests/fixtures/diffs/diff1 tests/fixtures/diff1_backup;"
93 : : "cp -a tests/fixtures/diff1_backup tests/fixtures/diffs/diff1;";
94 : :
95 : : // Preparation for tests
96 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
97 : :
98 : 2 : const char *arguments = "--progress --database=database1.db "
99 : : "tests/fixtures/diffs/diff1";
100 : :
101 : : // Create memory for the result
102 : 2 : create(char,result);
103 : :
104 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
105 : :
106 : 2 : create(char,pattern);
107 : :
108 : 2 : const char *filename = "templates/0011_002_1.txt";
109 : :
110 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
111 : :
112 [ + - + - ]: 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
113 : :
114 : : // Match the result against the pattern
115 [ + - + - ]: 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
116 : :
117 : : // Clean to use it iteratively
118 : 2 : del(pattern);
119 : 2 : del(result);
120 : :
121 : 2 : arguments = "--progress --database=database1.db "
122 : : "tests/fixtures/diffs/diff1";
123 : :
124 : 2 : filename = "templates/0011_002_2.txt";
125 : :
126 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,WARNING,ALLOW_BOTH));
127 : :
128 [ + - + - ]: 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
129 : :
130 [ + - + - ]: 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
131 : :
132 : : // Clean to use it iteratively
133 : 2 : del(pattern);
134 : 2 : del(result);
135 : :
136 : 2 : create(char,chunk);
137 : :
138 : 2 : arguments = "--update --progress --database=database1.db "
139 : : "tests/fixtures/diffs/diff1";
140 : :
141 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,chunk,NULL,COMPLETED,ALLOW_BOTH));
142 : :
143 [ + - + - ]: 2 : ASSERT(SUCCESS == copy(result,chunk));
144 : :
145 : 2 : command = "cd ${TMPDIR};"
146 : : "echo -n ' ' >> tests/fixtures/diffs/diff1/1/AAA/BCB/CCC/a.txt;"
147 : : "touch tests/fixtures/diffs/diff1/1/AAA/BCB/CCC/c.txt;"
148 : : "rm tests/fixtures/diffs/diff1/path2/AAA/ZAW/D/e/f/b_file.txt";
149 : :
150 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
151 : :
152 : 2 : arguments = "--watch-timestamps --update --progress "
153 : : "--database=database1.db tests/fixtures/diffs/diff1";
154 : :
155 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,chunk,NULL,COMPLETED,ALLOW_BOTH));
156 : :
157 [ + - + - ]: 2 : ASSERT(SUCCESS == concat_strings(result,chunk));
158 : :
159 : 2 : filename = "templates/0011_002_3.txt";
160 : :
161 [ + - + - ]: 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
162 : :
163 [ + - + - ]: 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
164 : :
165 : 2 : del(pattern);
166 : 2 : del(result);
167 : 2 : del(chunk);
168 : :
169 : : // Don't clean up test results to use on the next test
170 : :
171 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
172 : : }
173 : :
174 : : /**
175 : : * The Example 3 from README
176 : : * Using the --silent mode. When this mode is enabled, the program does not display
177 : : * anything on the screen. This makes sense when using the program inside scripts.
178 : : * Let's add the --silent option to the previous example:
179 : : *
180 : : * precizer --silent --update --progress --database=database1.db tests/fixtures/diffs/diff1
181 : : *
182 : : *
183 : : */
184 : 2 : static Return test0011_3(void)
185 : : {
186 : 2 : INITTEST;
187 : :
188 : : // Create memory for the result
189 : 2 : create(char,result);
190 : :
191 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","false"));
192 : :
193 : 2 : const char *arguments = "--silent --update --progress --database=database1.db "
194 : : "tests/fixtures/diffs/diff1";
195 : :
196 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
197 : :
198 : : // Verify that silent mode produced no stdout after command execution
199 [ - + ]: 2 : if(result->length > 0)
200 : : {
201 : 0 : echo(STDERR,"ERROR: In silent mode stdout must be empty\n");
202 : 0 : echo(STDERR,YELLOW "Output:\n>>" RESET "%s" YELLOW "<<\n" RESET,getcstring(result));
203 : 0 : status = FAILURE;
204 : : }
205 : :
206 [ - + - + ]: 2 : call(del(result));
207 : :
208 : 2 : create(char,pattern);
209 : :
210 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
211 : :
212 : 2 : const char *filename = "templates/0011_003.txt";
213 : :
214 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
215 [ + - + - ]: 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
216 [ + - + - ]: 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
217 : :
218 : 2 : del(pattern);
219 : 2 : del(result);
220 : :
221 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
222 : : }
223 : :
224 : : /**
225 : : *
226 : : * The Example 4 from README
227 : : * Additional information with --verbose mode
228 : : *
229 : : */
230 : 2 : static Return test0011_4(void)
231 : : {
232 : 2 : INITTEST;
233 : :
234 : : // Create memory for the result
235 : 2 : create(char,result);
236 : :
237 : 2 : create(char,pattern);
238 : :
239 : 2 : const char *filename = "templates/0011_004_1.txt";
240 : :
241 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","false"));
242 : :
243 : 2 : const char *arguments = "--verbose --update --progress --database=database1.db "
244 : : "tests/fixtures/diffs/diff1";
245 : :
246 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
247 [ + - + - ]: 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
248 [ + - + - ]: 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
249 : :
250 : : // Clean up test results
251 : 2 : del(pattern);
252 : 2 : del(result);
253 : :
254 : 2 : const char *command = "cd ${TMPDIR} && "
255 : : "rm database1.db && "
256 : : "rm -rf tests/fixtures/diffs/diff1 && "
257 : : "mv tests/fixtures/diff1_backup tests/fixtures/diffs/diff1";
258 : :
259 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
260 : :
261 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
262 : : }
263 : :
264 : : /**
265 : : *
266 : : * The Example 5 from README
267 : : * Disable recursion with --maxdepth=0 option
268 : : *
269 : : *
270 : : */
271 : 2 : static Return test0011_5(void)
272 : : {
273 : 2 : INITTEST;
274 : :
275 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
276 : :
277 : 2 : const char *arguments = "--maxdepth=0 tests/fixtures/4";
278 : :
279 : 2 : const char *filename = "templates/0011_005_1.txt";
280 : :
281 : 2 : const char *template = "%DB_NAME%";
282 : :
283 : 2 : const char *replacement = getenv("DBNAME"); // Database name
284 : :
285 [ + - + - ]: 2 : ASSERT(replacement != NULL);
286 : :
287 [ + - + - ]: 2 : ASSERT(SUCCESS == match_app_output(arguments,filename,template,replacement,COMPLETED));
288 : :
289 : : /* At the second stage, the --maxdepth=0 option is not used.
290 : : Therefore, all files that were not previously included
291 : : will be added to the database. */
292 : :
293 : 2 : arguments = "--update tests/fixtures/4";
294 : :
295 : 2 : filename = "templates/0011_005_2.txt";
296 : :
297 [ + - + - ]: 2 : ASSERT(SUCCESS == match_app_output(arguments,filename,template,replacement,COMPLETED));
298 : :
299 : 2 : const char *command = "rm \"${TMPDIR}/${DBNAME}\"";
300 : :
301 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
302 : :
303 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
304 : : }
305 : :
306 : : /**
307 : : *
308 : : * The Example 6 from README
309 : : * Relative path to ignore with --ignore
310 : : *
311 : : *
312 : : */
313 : 2 : static Return test0011_6(void)
314 : : {
315 : 2 : INITTEST;
316 : :
317 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","false"));
318 : :
319 : 2 : const char *arguments = "--ignore=\"^diff1/1/.*\" tests/fixtures/diffs";
320 : :
321 : 2 : const char *filename = "templates/0011_006_1.txt";
322 : :
323 : 2 : const char *template = "%DB_NAME%";
324 : :
325 : 2 : const char *replacement = getenv("DBNAME"); // Database name
326 : :
327 [ + - + - ]: 2 : ASSERT(replacement != NULL);
328 : :
329 [ + - + - ]: 2 : ASSERT(SUCCESS == match_app_output(arguments,filename,template,replacement,COMPLETED));
330 : :
331 : 2 : filename = "templates/0011_006_2.txt";
332 : :
333 : 2 : arguments = "--update tests/fixtures/diffs";
334 : :
335 [ + - + - ]: 2 : ASSERT(SUCCESS == match_app_output(arguments,filename,template,replacement,COMPLETED));
336 : :
337 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
338 : : }
339 : :
340 : : /**
341 : : *
342 : : * The Example 7 from README
343 : : * Multiple regular expressions for ignoring can be specified
344 : : * using many --ignore options
345 : : *
346 : : */
347 : 2 : static Return test0011_7(void)
348 : : {
349 : 2 : INITTEST;
350 : :
351 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","false"));
352 : :
353 : 2 : const char *arguments = "--update --db-drop-ignored"
354 : : " --ignore=\"^diff1/1/.*\""
355 : : " --ignore=\"^diff2/1/.*\" tests/fixtures/diffs";
356 : :
357 : 2 : const char *filename = "templates/0011_007.txt";
358 : :
359 : 2 : const char *template = "%DB_NAME%";
360 : :
361 : 2 : const char *replacement = getenv("DBNAME"); // Database name
362 : :
363 [ + - + - ]: 2 : ASSERT(replacement != NULL);
364 : :
365 [ + - + - ]: 2 : ASSERT(SUCCESS == match_app_output(arguments,filename,template,replacement,COMPLETED));
366 : :
367 : 2 : const char *command = "rm \"${TMPDIR}/${DBNAME}\"";
368 : :
369 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
370 : :
371 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
372 : : }
373 : :
374 : : /**
375 : : *
376 : : * The Example 8 from README
377 : : * Using the --ignore options together with --include
378 : : *
379 : : *
380 : : */
381 : 2 : static Return test0011_8(void)
382 : : {
383 : 2 : INITTEST;
384 : :
385 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
386 : :
387 : 2 : const char *arguments = "tests/fixtures/diffs";
388 : :
389 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,NULL,NULL,COMPLETED,ALLOW_BOTH));
390 : :
391 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","false"));
392 : :
393 : 2 : arguments = "--update"
394 : : " --progress"
395 : : " --ignore=\"^.*/path2/.*\""
396 : : " --ignore=\"^diff2/.*\""
397 : : " --include=\"^diff2/1/AAA/ZAW/A/b/c/.*\""
398 : : " --include=\"^diff2/path1/AAA/ZAW/.*\""
399 : : " --include=\"^diff1/path2/AAA/ZAW/A/b/c/a_file\\..*\""
400 : : " --db-drop-ignored"
401 : : " tests/fixtures/diffs";
402 : :
403 : 2 : const char *filename = "templates/0011_008.txt";
404 : :
405 : 2 : const char *template = "%DB_NAME%";
406 : :
407 : 2 : const char *replacement = getenv("DBNAME"); // Database name
408 : :
409 [ + - + - ]: 2 : ASSERT(replacement != NULL);
410 : :
411 [ + - + - ]: 2 : ASSERT(SUCCESS == match_app_output(arguments,filename,template,replacement,COMPLETED));
412 : :
413 : 2 : const char *command = "rm \"${TMPDIR}/${DBNAME}\"";
414 : :
415 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
416 : :
417 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
418 : : }
419 : :
420 : : /**
421 : : *
422 : : * User's Manual and examples from README test set
423 : : *
424 : : */
425 : 2 : Return test0011(void)
426 : : {
427 : : /// The status that will be passed to return() before exiting.
428 : : /// By default, the function worked without errors.
429 : 2 : INITTEST;
430 : :
431 [ + - ]: 2 : TEST(test0011_1,"README Example 1 Adding and comparing…");
432 [ + - ]: 2 : TEST(test0011_2,"README Example 2 Updating the data in DB…");
433 [ + - ]: 2 : TEST(test0011_3,"README Example 3 --silent mode…");
434 [ + - ]: 2 : TEST(test0011_4,"README Example 4 --verbose mode…");
435 [ + - ]: 2 : TEST(test0011_5,"README Example 5 Disable recursion with --maxdepth…");
436 [ + - ]: 2 : TEST(test0011_6,"README Example 6 Relative path to ignore with --ignore…");
437 [ + - ]: 2 : TEST(test0011_7,"README Example 7 Multiple regexp for ignoring…");
438 [ + - ]: 2 : TEST(test0011_8,"README Example 8 The --ignore options together with --include…");
439 [ + - ]: 2 : SUTE(test0030,"README Examples 9 & 10: --lock-checksum with --rehash-locked and --watch-timestamps…");
440 [ + - ]: 2 : SUTE(test0029,"README Example 11: Testing how the application behaves with inaccessible files…");
441 : :
442 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
443 : : }
|