LCOV - code coverage report
Current view: top level - tests/src - test0013.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 283 283
Test Date: 2026-03-31 13:51:38 Functions: 100.0 % 9 9
Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : #include "sute.h"
       2                 :             : 
       3                 :             : /**
       4                 :             :  * The db file should not be created in the Dry Run mode
       5                 :             :  */
       6                 :           2 : static Return test0013_1(void)
       7                 :             : {
       8                 :           2 :         INITTEST;
       9                 :             : 
      10                 :           2 :         create(char,result);
      11                 :             : 
      12                 :           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
      13                 :             : 
      14                 :           2 :         const char *arguments = "--dry-run --database=database1.db tests/fixtures/diffs/diff1";
      15                 :             : 
      16                 :           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
      17                 :             : 
      18                 :             :         #if 0
      19                 :             :         echo(STDOUT,"%s\n",getcstring(result));
      20                 :             :         #endif
      21                 :             : 
      22                 :           2 :         del(result);
      23                 :             : 
      24                 :             :         // Does file exists or not
      25                 :           2 :         const char *db_filename = "database1.db";
      26                 :           2 :         create(char,path);
      27                 :           2 :         bool file_exists = false;
      28                 :             : 
      29                 :           2 :         ASSERT(SUCCESS == construct_path(db_filename,path));
      30                 :             : 
      31                 :           2 :         ASSERT(SUCCESS == check_file_exists(&file_exists,getcstring(path)));
      32                 :             : 
      33                 :           2 :         del(path);
      34                 :             : 
      35                 :             :         // Should not be exists
      36                 :           2 :         ASSERT(file_exists == false);
      37                 :             : 
      38                 :           2 :         RETURN_STATUS;
      39                 :             : }
      40                 :             : 
      41                 :             : /**
      42                 :             :  * In dry-run mode with checksums, files are hashed but DB is still not modified
      43                 :             :  */
      44                 :           2 : static Return test0013_2(void)
      45                 :             : {
      46                 :           2 :         INITTEST;
      47                 :             : 
      48                 :           2 :         create(char,result);
      49                 :           2 :         create(char,pattern);
      50                 :           2 :         create(char,path);
      51                 :           2 :         bool file_exists = false;
      52                 :             : 
      53                 :           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
      54                 :             : 
      55                 :           2 :         const char *arguments = "--dry-run --database=dry_run_regular.db tests/fixtures/diffs/diff1";
      56                 :           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
      57                 :             : 
      58                 :           2 :         const char *filename = "templates/0013_001_1.txt";
      59                 :           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
      60                 :           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
      61                 :             : 
      62                 :           2 :         del(pattern);
      63                 :           2 :         del(result);
      64                 :             : 
      65                 :           2 :         arguments = "--dry-run=with-checksums --database=dry_run_with_checksums.db tests/fixtures/diffs/diff1";
      66                 :           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
      67                 :             : 
      68                 :           2 :         filename = "templates/0013_001_2.txt";
      69                 :           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
      70                 :           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
      71                 :             : 
      72                 :           2 :         del(pattern);
      73                 :           2 :         del(result);
      74                 :           2 :         del(path);
      75                 :             : 
      76                 :             :         /* Dry-run should not create either DB file. */
      77                 :           2 :         ASSERT(SUCCESS == construct_path("dry_run_regular.db",path));
      78                 :           2 :         ASSERT(SUCCESS == check_file_exists(&file_exists,getcstring(path)));
      79                 :           2 :         ASSERT(file_exists == false);
      80                 :             : 
      81                 :           2 :         del(path);
      82                 :           2 :         ASSERT(SUCCESS == construct_path("dry_run_with_checksums.db",path));
      83                 :           2 :         ASSERT(SUCCESS == check_file_exists(&file_exists,getcstring(path)));
      84                 :           2 :         ASSERT(file_exists == false);
      85                 :             : 
      86                 :           2 :         del(path);
      87                 :             : 
      88                 :           2 :         RETURN_STATUS;
      89                 :             : }
      90                 :             : 
      91                 :             : /**
      92                 :             :  * Invalid dry-run mode should fail with error in stderr
      93                 :             :  */
      94                 :           2 : static Return test0013_3(void)
      95                 :             : {
      96                 :           2 :         INITTEST;
      97                 :             : 
      98                 :           2 :         create(char,result);
      99                 :           2 :         create(char,pattern);
     100                 :             : 
     101                 :           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     102                 :             : 
     103                 :           2 :         const char *arguments = "--dry-run=bad-mode --database=dry_run_invalid.db tests/fixtures/diffs/diff1";
     104                 :             : 
     105                 :           2 :         ASSERT(SUCCESS == runit(arguments,NULL,result,FAILURE,STDERR_ALLOW));
     106                 :             : 
     107                 :           2 :         const char *filename = "templates/0013_001_3.txt";
     108                 :             : 
     109                 :           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     110                 :           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     111                 :             : 
     112                 :           2 :         del(pattern);
     113                 :           2 :         del(result);
     114                 :             : 
     115                 :           2 :         RETURN_STATUS;
     116                 :             : }
     117                 :             : 
     118                 :             : /**
     119                 :             :  * The db file should not be updated in the Dry Run mode
     120                 :             :  */
     121                 :           2 : static Return test0013_4(void)
     122                 :             : {
     123                 :           2 :         INITTEST;
     124                 :             : 
     125                 :             :         // Create memory for the result
     126                 :           2 :         create(char,result);
     127                 :             :         struct stat stat1;
     128                 :             :         struct stat stat2;
     129                 :           2 :         create(char,pattern);
     130                 :           2 :         create(char,chunk);
     131                 :             : 
     132                 :             :         // Preparation for tests
     133                 :           2 :         ASSERT(SUCCESS == move_path("tests/fixtures/diffs/diff1","tests/fixtures/diff1_backup"));
     134                 :           2 :         ASSERT(SUCCESS == copy_path("tests/fixtures/diff1_backup","tests/fixtures/diffs/diff1"));
     135                 :             : 
     136                 :           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     137                 :             : 
     138                 :           2 :         const char *arguments = "--database=database1.db tests/fixtures/diffs/diff1";
     139                 :             : 
     140                 :           2 :         ASSERT(SUCCESS == runit(arguments,NULL,NULL,COMPLETED,ALLOW_BOTH));
     141                 :             : 
     142                 :             :         #if 0
     143                 :             :         printf("Path: %s\n",path);
     144                 :             :         echo(STDOUT,"Path: %s\n",path);
     145                 :             :         #endif
     146                 :             : 
     147                 :           2 :         create(char,path);
     148                 :             : 
     149                 :           2 :         const char *db_filename = "database1.db";
     150                 :             : 
     151                 :           2 :         ASSERT(SUCCESS == construct_path(db_filename,path));
     152                 :             : 
     153                 :           2 :         ASSERT(SUCCESS == get_file_stat(getcstring(path),&stat1));
     154                 :             : 
     155                 :           2 :         ASSERT(SUCCESS == delete_path("tests/fixtures/diffs/diff1/2/AAA/BBB/CZC/a.txt")); // Remove
     156                 :           2 :         ASSERT(SUCCESS == add_string_to("AFAKDSJ","tests/fixtures/diffs/diff1/1/AAA/ZAW/D/e/f/b_file.txt")); // Modify
     157                 :           2 :         ASSERT(SUCCESS == replase_to_string("WNEURHGO","tests/fixtures/diffs/diff1/2/AAA/BBB/CZC/b.txt")); // New file
     158                 :             : 
     159                 :           2 :         arguments = "--dry-run --update --database=database1.db"
     160                 :             :                 " tests/fixtures/diffs/diff1";
     161                 :             : 
     162                 :           2 :         ASSERT(SUCCESS == runit(arguments,chunk,NULL,COMPLETED,ALLOW_BOTH));
     163                 :           2 :         ASSERT(SUCCESS == copy(result,chunk));
     164                 :             : 
     165                 :             :         #if 0
     166                 :             :         printf("%s\n",getcstring(result));
     167                 :             :         echo(STDOUT,"%s\n",getcstring(result));
     168                 :             :         #endif
     169                 :             : 
     170                 :           2 :         del(result);
     171                 :           2 :         del(chunk);
     172                 :             : 
     173                 :           2 :         ASSERT(SUCCESS == get_file_stat(getcstring(path),&stat2));
     174                 :             : 
     175                 :           2 :         ASSERT(SUCCESS == check_file_identity(&stat1,&stat2));
     176                 :             : 
     177                 :             :         // Compare against the sample. A message should be displayed indicating
     178                 :             :         // that the --db-drop-ignored option must be specified for permanent
     179                 :             :         // removal of ignored files from the database
     180                 :           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     181                 :             : 
     182                 :           2 :         arguments = "--dry-run --ignore=\"^1/AAA/ZAW/.*\" --update "
     183                 :             :                 "--database=database1.db tests/fixtures/diffs/diff1";
     184                 :             : 
     185                 :           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
     186                 :             : 
     187                 :             :         #if 0
     188                 :             :         echo(STDOUT,"%s\n",getcstring(result));
     189                 :             :         #endif
     190                 :             : 
     191                 :           2 :         const char *filename = "templates/0013_002_1.txt";
     192                 :             : 
     193                 :           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     194                 :           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     195                 :             : 
     196                 :           2 :         del(pattern);
     197                 :             : 
     198                 :           2 :         del(result);
     199                 :             : 
     200                 :           2 :         ASSERT(SUCCESS == get_file_stat(getcstring(path),&stat2));
     201                 :             : 
     202                 :           2 :         ASSERT(SUCCESS == check_file_identity(&stat1,&stat2));
     203                 :             : 
     204                 :             :         // Dry Run mode permanent deletion of all ignored file
     205                 :             :         // references from the database
     206                 :           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     207                 :             : 
     208                 :           2 :         arguments = "--dry-run --db-drop-ignored --update"
     209                 :             :                 " --ignore=\"^1/AAA/ZAW/D/e/f/b_file\\..*\""
     210                 :             :                 " --database=database1.db tests/fixtures/diffs/diff1";
     211                 :             : 
     212                 :           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
     213                 :             : 
     214                 :             :         #if 0
     215                 :             :         echo(STDOUT,"%s\n",getcstring(result));
     216                 :             :         #endif
     217                 :             : 
     218                 :           2 :         filename = "templates/0013_002_2.txt";
     219                 :             : 
     220                 :           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     221                 :             : 
     222                 :           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     223                 :             : 
     224                 :           2 :         del(pattern);
     225                 :             : 
     226                 :           2 :         del(result);
     227                 :             : 
     228                 :           2 :         ASSERT(SUCCESS == get_file_stat(getcstring(path),&stat2));
     229                 :             : 
     230                 :           2 :         ASSERT(SUCCESS == check_file_identity(&stat1,&stat2));
     231                 :             : 
     232                 :           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     233                 :             : 
     234                 :           2 :         arguments = "--dry-run --db-drop-ignored --update --watch-timestamps"
     235                 :             :                 " --ignore=\"^path2/AAA/ZAW/.*\""
     236                 :             :                 " --database=database1.db tests/fixtures/diffs/diff1";
     237                 :             : 
     238                 :           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
     239                 :             : 
     240                 :             :         #if 0
     241                 :             :         echo(STDOUT,"%s\n",getcstring(result));
     242                 :             :         #endif
     243                 :             : 
     244                 :           2 :         filename = "templates/0013_002_3.txt";
     245                 :             : 
     246                 :           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     247                 :             : 
     248                 :           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     249                 :             : 
     250                 :           2 :         del(pattern);
     251                 :             : 
     252                 :           2 :         del(result);
     253                 :             : 
     254                 :           2 :         ASSERT(SUCCESS == get_file_stat(getcstring(path),&stat2));
     255                 :             : 
     256                 :           2 :         ASSERT(SUCCESS == check_file_identity(&stat1,&stat2));
     257                 :             : 
     258                 :           2 :         del(path);
     259                 :             : 
     260                 :             :         // Clean up test results
     261                 :           2 :         ASSERT(SUCCESS == delete_path("database1.db"));
     262                 :           2 :         ASSERT(SUCCESS == delete_path("tests/fixtures/diffs/diff1"));
     263                 :             : 
     264                 :           2 :         ASSERT(SUCCESS == move_path("tests/fixtures/diff1_backup","tests/fixtures/diffs/diff1"));
     265                 :             : 
     266                 :           2 :         RETURN_STATUS;
     267                 :             : }
     268                 :             : 
     269                 :             : /**
     270                 :             :  * Everything that was previously executed in Dry Run mode
     271                 :             :  * will now be tested in live mode without simulation, and
     272                 :             :  * the results will be compared against each other
     273                 :             :  */
     274                 :           2 : static Return test0013_5(void)
     275                 :             : {
     276                 :           2 :         INITTEST;
     277                 :             :         // Create memory for the result
     278                 :           2 :         create(char,result);
     279                 :           2 :         create(char,path);
     280                 :           2 :         create(char,pattern);
     281                 :           2 :         const char *db_file_name = "database1.db";
     282                 :           2 :         const char *arguments = NULL;
     283                 :             : 
     284                 :             :         // Preparation for tests
     285                 :           2 :         ASSERT(SUCCESS == move_path("tests/fixtures/diffs/diff1","tests/fixtures/diff1_backup"));
     286                 :           2 :         ASSERT(SUCCESS == copy_path("tests/fixtures/diff1_backup","tests/fixtures/diffs/diff1"));
     287                 :             : 
     288                 :           2 :         ASSERT(SUCCESS == construct_path(db_file_name,path));
     289                 :             : 
     290                 :           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     291                 :             : 
     292                 :           2 :         arguments = "--database=database1.db tests/fixtures/diffs/diff1";
     293                 :             : 
     294                 :           2 :         ASSERT(SUCCESS == runit(arguments,NULL,NULL,COMPLETED,ALLOW_BOTH));
     295                 :             : 
     296                 :             :         #if 0
     297                 :             :         echo(STDOUT,"Path: %s\n",path);
     298                 :             :         #endif
     299                 :             : 
     300                 :           2 :         ASSERT(SUCCESS == delete_path("tests/fixtures/diffs/diff1/2/AAA/BBB/CZC/a.txt"));
     301                 :           2 :         ASSERT(SUCCESS == add_string_to("AFAKDSJ","tests/fixtures/diffs/diff1/1/AAA/ZAW/D/e/f/b_file.txt"));
     302                 :           2 :         ASSERT(SUCCESS == replase_to_string("WNEURHGO","tests/fixtures/diffs/diff1/2/AAA/BBB/CZC/b.txt")); // New file
     303                 :             : 
     304                 :             :         #if 0
     305                 :             :         echo(STDOUT,"%s\n",getcstring(result));
     306                 :             :         #endif
     307                 :             : 
     308                 :           2 :         del(result);
     309                 :             : 
     310                 :             :         // Compare against the sample. A message should be displayed indicating
     311                 :             :         // that the --db-drop-ignored option must be specified for permanent
     312                 :             :         // removal of ignored files from the database
     313                 :           2 :         ASSERT(SUCCESS == copy_path("database1.db","database1.db.backup"));
     314                 :             : 
     315                 :           2 :         arguments = "--ignore=\"^1/AAA/ZAW/.*\" --update --database=database1.db "
     316                 :             :                 "tests/fixtures/diffs/diff1";
     317                 :             : 
     318                 :           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
     319                 :             : 
     320                 :             :         #if 0
     321                 :             :         echo(STDOUT,"%s\n",getcstring(result));
     322                 :             :         #endif
     323                 :             : 
     324                 :           2 :         const char *filename = "templates/0013_003_1.txt";
     325                 :             : 
     326                 :           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     327                 :           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     328                 :             : 
     329                 :           2 :         del(pattern);
     330                 :             : 
     331                 :           2 :         del(result);
     332                 :             : 
     333                 :             :         // Real live mode permanent deletion of all ignored file
     334                 :             :         // references from the database
     335                 :           2 :         ASSERT(SUCCESS == copy_path("database1.db.backup","database1.db"));
     336                 :             : 
     337                 :           2 :         arguments = "--db-drop-ignored --update"
     338                 :             :                 " --ignore=\"^1/AAA/ZAW/D/e/f/b_file\\..*\""
     339                 :             :                 " --database=database1.db tests/fixtures/diffs/diff1";
     340                 :             : 
     341                 :           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
     342                 :             : 
     343                 :             :         #if 0
     344                 :             :         echo(STDOUT,"%s\n",getcstring(result));
     345                 :             :         #endif
     346                 :             : 
     347                 :           2 :         filename = "templates/0013_003_2.txt";
     348                 :             : 
     349                 :           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     350                 :           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     351                 :             : 
     352                 :           2 :         del(pattern);
     353                 :             : 
     354                 :           2 :         del(result);
     355                 :             : 
     356                 :           2 :         ASSERT(SUCCESS == move_path("database1.db.backup","database1.db"));
     357                 :             : 
     358                 :           2 :         arguments = "--watch-timestamps --db-drop-ignored "
     359                 :             :                 "--ignore=\"^path2/AAA/ZAW/.*\" --update "
     360                 :             :                 "--database=database1.db tests/fixtures/diffs/diff1";
     361                 :             : 
     362                 :           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
     363                 :             : 
     364                 :             :         #if 0
     365                 :             :         echo(STDOUT,"%s\n",getcstring(result));
     366                 :             :         #endif
     367                 :             : 
     368                 :           2 :         filename = "templates/0013_003_3.txt";
     369                 :             : 
     370                 :           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     371                 :           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     372                 :             : 
     373                 :           2 :         del(pattern);
     374                 :             : 
     375                 :           2 :         del(result);
     376                 :             : 
     377                 :           2 :         del(path);
     378                 :             : 
     379                 :             :         // Clean up test results
     380                 :           2 :         ASSERT(SUCCESS == delete_path("database1.db"));
     381                 :           2 :         ASSERT(SUCCESS == delete_path("tests/fixtures/diffs/diff1"));
     382                 :             : 
     383                 :           2 :         ASSERT(SUCCESS == move_path("tests/fixtures/diff1_backup","tests/fixtures/diffs/diff1"));
     384                 :             : 
     385                 :           2 :         RETURN_STATUS;
     386                 :             : }
     387                 :             : 
     388                 :           2 : Return test0013_6(void)
     389                 :             : {
     390                 :           2 :         INITTEST;
     391                 :             : 
     392                 :           2 :         create(char,text1);
     393                 :           2 :         create(char,text2);
     394                 :           2 :         char *diff = NULL;
     395                 :           2 :         create(char,pattern);
     396                 :           2 :         const char *filename = NULL;
     397                 :             : 
     398                 :             :         /* 0013 002 1 */
     399                 :           2 :         ASSERT(SUCCESS == get_file_content("templates/0013_002_1.txt",text1));
     400                 :             : 
     401                 :           2 :         ASSERT(SUCCESS == get_file_content("templates/0013_003_1.txt",text2));
     402                 :             : 
     403                 :           2 :         ASSERT(SUCCESS == compare_strings(&diff,getcstring(text1),getcstring(text2)));
     404                 :             : 
     405                 :           2 :         filename = "templates/0013_004_1.txt";
     406                 :             : 
     407                 :           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     408                 :           2 :         create(char,diff_buffer);
     409                 :           2 :         ASSERT(SUCCESS == copy_literal(diff_buffer,diff));
     410                 :           2 :         ASSERT(SUCCESS == match_pattern(diff_buffer,pattern,filename));
     411                 :             : 
     412                 :           2 :         del(text1);
     413                 :           2 :         del(text2);
     414                 :           2 :         reset(&diff);
     415                 :           2 :         del(pattern);
     416                 :             : 
     417                 :             :         /* 0013 002 2 */
     418                 :           2 :         ASSERT(SUCCESS == get_file_content("templates/0013_002_2.txt",text1));
     419                 :             : 
     420                 :           2 :         ASSERT(SUCCESS == get_file_content("templates/0013_003_2.txt",text2));
     421                 :             : 
     422                 :           2 :         ASSERT(SUCCESS == compare_strings(&diff,getcstring(text1),getcstring(text2)));
     423                 :             : 
     424                 :           2 :         filename = "templates/0013_004_2.txt";
     425                 :             : 
     426                 :           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     427                 :           2 :         del(diff_buffer);
     428                 :           2 :         ASSERT(SUCCESS == copy_literal(diff_buffer,diff));
     429                 :           2 :         ASSERT(SUCCESS == match_pattern(diff_buffer,pattern,filename));
     430                 :             : 
     431                 :           2 :         del(text1);
     432                 :           2 :         del(text2);
     433                 :           2 :         reset(&diff);
     434                 :           2 :         del(pattern);
     435                 :             : 
     436                 :             :         /* 0013 002 3 */
     437                 :           2 :         ASSERT(SUCCESS == get_file_content("templates/0013_002_3.txt",text1));
     438                 :             : 
     439                 :           2 :         ASSERT(SUCCESS == get_file_content("templates/0013_003_3.txt",text2));
     440                 :             : 
     441                 :           2 :         ASSERT(SUCCESS == compare_strings(&diff,getcstring(text1),getcstring(text2)));
     442                 :             : 
     443                 :             :         // _2 is not a mistake. 2 and 3 are equals
     444                 :           2 :         filename = "templates/0013_004_2.txt";
     445                 :             : 
     446                 :           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     447                 :           2 :         del(diff_buffer);
     448                 :           2 :         ASSERT(SUCCESS == copy_literal(diff_buffer,diff));
     449                 :           2 :         ASSERT(SUCCESS == match_pattern(diff_buffer,pattern,filename));
     450                 :             : 
     451                 :           2 :         del(text1);
     452                 :           2 :         del(text2);
     453                 :           2 :         reset(&diff);
     454                 :           2 :         del(pattern);
     455                 :           2 :         del(diff_buffer);
     456                 :             : 
     457                 :           2 :         RETURN_STATUS;
     458                 :             : }
     459                 :             : 
     460                 :             : /**
     461                 :             :  * Verifies detection of unexpected database metadata drift in dry-run mode.
     462                 :             :  *
     463                 :             :  * The function performs two runs. First, it creates `database1.db` in normal
     464                 :             :  * mode. Then it enables the testing hook
     465                 :             :  * `PRECIZER_TEST_DB_FILE_TIMESTAMPS_WILL_BUMPED=true` and runs the application
     466                 :             :  * with `--dry-run --update`. In test-hook mode this forces a DB timestamp bump
     467                 :             :  * inside the process before `db_check_changes()` compares the saved and current
     468                 :             :  * file metadata.
     469                 :             :  *
     470                 :             :  * The expected outcome of the second run is `WARNING`
     471                 :             :  */
     472                 :           2 : static Return test0013_7(void)
     473                 :             : {
     474                 :           2 :         INITTEST;
     475                 :             : 
     476                 :           2 :         create(char,result);
     477                 :           2 :         create(char,pattern);
     478                 :           2 :         const char *arguments = NULL;
     479                 :             : 
     480                 :           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     481                 :           2 :         ASSERT(SUCCESS == set_environment_variable("PRECIZER_TEST_DB_FILE_TIMESTAMPS_WILL_BUMPED","false"));
     482                 :             : 
     483                 :             :         /* First run: create DB in normal mode. */
     484                 :           2 :         arguments = "--database=database1.db tests/fixtures/diffs/diff1";
     485                 :           2 :         ASSERT(SUCCESS == runit(arguments,NULL,NULL,COMPLETED,ALLOW_BOTH));
     486                 :             : 
     487                 :           2 :         ASSERT(SUCCESS == set_environment_variable("PRECIZER_TEST_DB_FILE_TIMESTAMPS_WILL_BUMPED","true"));
     488                 :           2 :         arguments = "--dry-run --update --database=database1.db tests/fixtures/diffs/diff1";
     489                 :           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,WARNING,ALLOW_BOTH));
     490                 :             : 
     491                 :           2 :         const char *filename = "templates/0013_005.txt";
     492                 :           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     493                 :           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     494                 :             : 
     495                 :           2 :         ASSERT(SUCCESS == set_environment_variable("PRECIZER_TEST_DB_FILE_TIMESTAMPS_WILL_BUMPED","false"));
     496                 :           2 :         ASSERT(SUCCESS == delete_path("database1.db"));
     497                 :             : 
     498                 :           2 :         del(pattern);
     499                 :           2 :         del(result);
     500                 :             : 
     501                 :           2 :         RETURN_STATUS;
     502                 :             : }
     503                 :             : 
     504                 :             : /**
     505                 :             :  * Verifies internal consistency check when DB should be modified but appears unchanged.
     506                 :             :  *
     507                 :             :  * The function first validates a real update path: it creates `database1.db`,
     508                 :             :  * modifies one sample file, runs `--update`, compares output with template,
     509                 :             :  * and verifies that DB file metadata has actually changed.
     510                 :             :  *
     511                 :             :  * After that, it restores the pre-update DB state, enables
     512                 :             :  * `PRECIZER_TEST_DB_FILE_STAT_WILL_BE_RESYNCED=true`, and runs `--update`
     513                 :             :  * again. The hook rewrites the saved baseline database stat to the current
     514                 :             :  * stat right before comparison in db_check_changes(). This simulates a faulty
     515                 :             :  * "no metadata drift" result after a real database update and must trigger
     516                 :             :  * WARNING.
     517                 :             :  */
     518                 :           2 : static Return test0013_8(void)
     519                 :             : {
     520                 :           2 :         INITTEST;
     521                 :             : 
     522                 :           2 :         create(char,result);
     523                 :           2 :         create(char,pattern);
     524                 :           2 :         create(char,path);
     525                 :             : 
     526                 :           2 :         struct stat stat_before_real_update = {0};
     527                 :           2 :         struct stat stat_after_real_update = {0};
     528                 :             : 
     529                 :           2 :         const char *arguments = NULL;
     530                 :             : 
     531                 :           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     532                 :           2 :         ASSERT(SUCCESS == set_environment_variable("PRECIZER_TEST_DB_FILE_TIMESTAMPS_WILL_BUMPED","false"));
     533                 :           2 :         ASSERT(SUCCESS == set_environment_variable("PRECIZER_TEST_DB_FILE_STAT_WILL_BE_RESYNCED","false"));
     534                 :             : 
     535                 :           2 :         ASSERT(SUCCESS == move_path("tests/fixtures/diffs/diff1","tests/fixtures/diff1_backup"));
     536                 :           2 :         ASSERT(SUCCESS == copy_path("tests/fixtures/diff1_backup","tests/fixtures/diffs/diff1"));
     537                 :             : 
     538                 :             :         /* First run: create DB in normal mode. */
     539                 :           2 :         arguments = "--database=database1.db tests/fixtures/diffs/diff1";
     540                 :           2 :         ASSERT(SUCCESS == runit(arguments,NULL,NULL,COMPLETED,ALLOW_BOTH));
     541                 :             : 
     542                 :             :         /* Make at least one real filesystem change so --update modifies DB. */
     543                 :           2 :         ASSERT(SUCCESS == add_string_to("AFAKDSJ","tests/fixtures/diffs/diff1/1/AAA/ZAW/D/e/f/b_file.txt"));
     544                 :             : 
     545                 :             :         /* Control check: real --update must modify database metadata. */
     546                 :           2 :         ASSERT(SUCCESS == construct_path("database1.db",path));
     547                 :           2 :         ASSERT(SUCCESS == get_file_stat(getcstring(path),&stat_before_real_update));
     548                 :             : 
     549                 :           2 :         ASSERT(SUCCESS == copy_path("database1.db","database1.db.backup"));
     550                 :             : 
     551                 :           2 :         arguments = "--update --database=database1.db tests/fixtures/diffs/diff1";
     552                 :           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
     553                 :             : 
     554                 :           2 :         const char *filename = "templates/0013_006_1.txt";
     555                 :           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     556                 :           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     557                 :             : 
     558                 :           2 :         ASSERT(SUCCESS == get_file_stat(getcstring(path),&stat_after_real_update));
     559                 :           2 :         ASSERT(FAILURE == check_file_identity(&stat_before_real_update,&stat_after_real_update));
     560                 :             : 
     561                 :             :         /*
     562                 :             :          * Restore pre-update DB snapshot so the next run starts from the same state
     563                 :             :          * and tests only the simulation hook behavior.
     564                 :             :          */
     565                 :           2 :         ASSERT(SUCCESS == move_path("database1.db.backup","database1.db"));
     566                 :             : 
     567                 :           2 :         del(result);
     568                 :           2 :         del(pattern);
     569                 :             : 
     570                 :           2 :         ASSERT(SUCCESS == set_environment_variable("PRECIZER_TEST_DB_FILE_STAT_WILL_BE_RESYNCED","true"));
     571                 :           2 :         arguments = "--update --database=database1.db tests/fixtures/diffs/diff1";
     572                 :           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,WARNING,ALLOW_BOTH));
     573                 :             : 
     574                 :           2 :         filename = "templates/0013_006_2.txt";
     575                 :           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     576                 :           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     577                 :             : 
     578                 :           2 :         ASSERT(SUCCESS == set_environment_variable("PRECIZER_TEST_DB_FILE_STAT_WILL_BE_RESYNCED","false"));
     579                 :           2 :         ASSERT(SUCCESS == delete_path("database1.db"));
     580                 :           2 :         ASSERT(SUCCESS == delete_path("tests/fixtures/diffs/diff1"));
     581                 :           2 :         ASSERT(SUCCESS == move_path("tests/fixtures/diff1_backup","tests/fixtures/diffs/diff1"));
     582                 :             : 
     583                 :           2 :         del(path);
     584                 :           2 :         del(pattern);
     585                 :           2 :         del(result);
     586                 :             : 
     587                 :           2 :         RETURN_STATUS;
     588                 :             : }
     589                 :             : 
     590                 :             : /**
     591                 :             :  *
     592                 :             :  * Dry Run mode testing
     593                 :             :  *
     594                 :             :  */
     595                 :           2 : Return test0013(void)
     596                 :             : {
     597                 :           2 :         INITTEST;
     598                 :             : 
     599                 :           2 :         TEST(test0013_1,"The DB file should not be created…");
     600                 :           2 :         TEST(test0013_2,"Dry run with checksums hashes files but keeps DB untouched…");
     601                 :           2 :         TEST(test0013_3,"Invalid dry-run mode should return failure and print stderr error…");
     602                 :           2 :         TEST(test0013_4,"The DB file should not be updated…");
     603                 :           2 :         TEST(test0013_5,"Now run the same without simulation…");
     604                 :           2 :         TEST(test0013_6,"Compare dry and real mode templates…");
     605                 :           2 :         TEST(test0013_7,"Dry-run DB metadata drift should trigger internal warning path…");
     606                 :           2 :         TEST(test0013_8,"Live update: force missing DB metadata drift and trigger warning…");
     607                 :             : 
     608                 :           2 :         RETURN_STATUS;
     609                 :             : }
        

Generated by: LCOV version 2.0-1