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