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

Generated by: LCOV version 2.0-1