LCOV - code coverage report
Current view: top level - tests/src - test0003.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 97.8 % 91 89
Test Date: 2026-03-31 13:51:38 Functions: 100.0 % 6 6
Branches: 48.2 % 56 27

             Branch data     Line data    Source code
       1                 :             : #include "sute.h"
       2                 :             : 
       3                 :             : /**
       4                 :             :  * @brief Verify informational-mode output against the expected stdout template
       5                 :             :  *
       6                 :             :  * @param[in] arguments CLI arguments to pass to the application
       7                 :             :  * @param[in] stdout_pattern_file Template file for expected stdout
       8                 :             :  * @return Return status code
       9                 :             :  */
      10                 :          28 : static Return assert_information_mode_output(
      11                 :             :         const char *arguments,
      12                 :             :         const char *stdout_pattern_file)
      13                 :             : {
      14                 :             :         /* The status that will be returned before exiting */
      15                 :             :         /* By default, assumes the function ran without errors */
      16                 :          28 :         Return status = SUCCESS;
      17                 :             : 
      18                 :          28 :         create(char,stdout_result);
      19                 :          28 :         create(char,stderr_result);
      20                 :          28 :         create(char,stdout_pattern);
      21                 :          28 :         create(char,stderr_pattern);
      22                 :             : 
      23   [ +  -  -  + ]:          28 :         if((SUCCESS & status) && arguments == NULL)
      24                 :             :         {
      25                 :           0 :                 status = FAILURE;
      26                 :             :         }
      27   [ +  -  -  + ]:          28 :         if((SUCCESS & status) && stdout_pattern_file == NULL)
      28                 :             :         {
      29                 :           0 :                 status = FAILURE;
      30                 :             :         }
      31                 :             : 
      32   [ +  -  -  + ]:          28 :         run(set_environment_variable("TESTING","true"));
      33                 :             : 
      34   [ +  -  -  + ]:          28 :         run(runit(arguments,stdout_result,stderr_result,COMPLETED,STDERR_ALLOW));
      35                 :             : 
      36   [ +  -  -  + ]:          28 :         run(get_file_content(stdout_pattern_file,stdout_pattern));
      37   [ +  -  -  + ]:          28 :         run(match_pattern(stdout_result,stdout_pattern,stdout_pattern_file));
      38                 :             : 
      39   [ +  -  -  + ]:          28 :         run(copy_literal(stderr_pattern,"\\A\\Z"));
      40   [ +  -  -  + ]:          28 :         run(match_pattern(stderr_result,stderr_pattern));
      41                 :             : 
      42   [ -  +  -  + ]:          28 :         call(del(stderr_pattern));
      43   [ -  +  -  + ]:          28 :         call(del(stdout_pattern));
      44   [ -  +  -  + ]:          28 :         call(del(stderr_result));
      45   [ -  +  -  + ]:          28 :         call(del(stdout_result));
      46                 :             : 
      47   [ -  +  -  -  :          28 :         deliver(status);
             -  +  +  - ]
      48                 :             : }
      49                 :             : 
      50                 :             : /**
      51                 :             :  *
      52                 :             :  * Check the name of the database created by default.
      53                 :             :  * Does it really comply with to the "hostname.db" template
      54                 :             :  *
      55                 :             :  */
      56                 :           2 : Return test0003_1(void)
      57                 :             : {
      58                 :           2 :         INITTEST;
      59                 :             : 
      60                 :           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
      61                 :             : 
      62                 :           2 :         const char *arguments = "--progress tests/fixtures/diffs/diff1";
      63                 :             : 
      64                 :           2 :         ASSERT(SUCCESS == runit(arguments,NULL,NULL,COMPLETED,ALLOW_BOTH));
      65                 :             : 
      66                 :           2 :         arguments = "--progress --database=database2.db "
      67                 :             :                 "tests/fixtures/diffs/diff2";
      68                 :             : 
      69                 :           2 :         ASSERT(SUCCESS == runit(arguments,NULL,NULL,COMPLETED,ALLOW_BOTH));
      70                 :             : 
      71                 :             :         // Get the output of the application
      72                 :           2 :         arguments = "--compare $DBNAME database2.db";
      73                 :             : 
      74                 :           2 :         const char *filename = "templates/0003_001.txt";  // File name
      75                 :           2 :         const char *template = "%DB_NAME%";
      76                 :             : 
      77                 :           2 :         const char *replacement = getenv("DBNAME");  // Database name
      78                 :             : 
      79                 :           2 :         ASSERT(replacement != NULL);
      80                 :             : 
      81                 :           2 :         ASSERT(SUCCESS == match_app_output(arguments,filename,template,replacement,COMPLETED));
      82                 :             : 
      83                 :             :         // Clean up test results
      84                 :           2 :         ASSERT(SUCCESS == delete_path(replacement));
      85                 :           2 :         ASSERT(SUCCESS == delete_path("database2.db"));
      86                 :             : 
      87                 :           2 :         RETURN_STATUS;
      88                 :             : }
      89                 :             : 
      90                 :             : /**
      91                 :             :  *
      92                 :             :  * Running the application with no arguments at all
      93                 :             :  *
      94                 :             :  */
      95                 :           2 : Return test0003_2(void)
      96                 :             : {
      97                 :           2 :         INITTEST;
      98                 :             : 
      99                 :           2 :         const char *arguments = "";
     100                 :             : 
     101                 :           2 :         create(char,stdout_result);
     102                 :           2 :         create(char,stderr_result);
     103                 :           2 :         create(char,stdout_pattern);
     104                 :           2 :         create(char,stderr_pattern);
     105                 :             : 
     106                 :           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     107                 :             : 
     108                 :           2 :         ASSERT(SUCCESS == runit(arguments,stdout_result,stderr_result,COMPLETED,STDERR_ALLOW));
     109                 :             : 
     110                 :           2 :         const char *filename = "templates/0003_002.txt";
     111                 :             : 
     112                 :           2 :         ASSERT(SUCCESS == get_file_content(filename,stderr_pattern));
     113                 :             : 
     114                 :             :         // Match stderr against the pattern
     115                 :           2 :         ASSERT(SUCCESS == match_pattern(stderr_result,stderr_pattern,filename));
     116                 :             : 
     117                 :           2 :         filename = "templates/0003_003.txt";
     118                 :             : 
     119                 :           2 :         ASSERT(SUCCESS == get_file_content(filename,stdout_pattern));
     120                 :             : 
     121                 :             :         // Match stdout against the pattern
     122                 :           2 :         ASSERT(SUCCESS == match_pattern(stdout_result,stdout_pattern,filename));
     123                 :             : 
     124                 :             :         // Clean to use it iteratively
     125                 :           2 :         del(stderr_pattern);
     126                 :           2 :         del(stdout_pattern);
     127                 :           2 :         del(stderr_result);
     128                 :           2 :         del(stdout_result);
     129                 :             : 
     130                 :           2 :         RETURN_STATUS;
     131                 :             : 
     132                 :             : }
     133                 :             : 
     134                 :             : /**
     135                 :             :  *
     136                 :             :  * Information modes should complete successfully without PATH
     137                 :             :  *
     138                 :             :  */
     139                 :           2 : Return test0003_3(void)
     140                 :             : {
     141                 :           2 :         INITTEST;
     142                 :           2 :         const char *help_template = "templates/0003_004.txt";
     143                 :           2 :         const char *usage_template = "templates/0003_005.txt";
     144                 :           2 :         const char *version_template = "templates/0003_006.txt";
     145                 :             : 
     146                 :           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     147                 :           2 :         ASSERT(SUCCESS & assert_information_mode_output("--help",help_template));
     148                 :           2 :         ASSERT(SUCCESS & assert_information_mode_output("-h",help_template));
     149                 :           2 :         ASSERT(SUCCESS & assert_information_mode_output("--usage",usage_template));
     150                 :           2 :         ASSERT(SUCCESS & assert_information_mode_output("-z",usage_template));
     151                 :           2 :         ASSERT(SUCCESS & assert_information_mode_output("--version",version_template));
     152                 :             : 
     153                 :           2 :         RETURN_STATUS;
     154                 :             : }
     155                 :             : 
     156                 :             : /**
     157                 :             :  *
     158                 :             :  * Information modes should ignore PATH and not run the main workflow
     159                 :             :  *
     160                 :             :  */
     161                 :           2 : Return test0003_4(void)
     162                 :             : {
     163                 :           2 :         INITTEST;
     164                 :           2 :         const char *help_template = "templates/0003_004.txt";
     165                 :           2 :         const char *usage_template = "templates/0003_005.txt";
     166                 :           2 :         const char *version_template = "templates/0003_006.txt";
     167                 :             : 
     168                 :           2 :         ASSERT(SUCCESS & assert_information_mode_output("--help /definitely/nonexistent/path",help_template));
     169                 :           2 :         ASSERT(SUCCESS & assert_information_mode_output("-h /definitely/nonexistent/path",help_template));
     170                 :           2 :         ASSERT(SUCCESS & assert_information_mode_output("--usage /definitely/nonexistent/path",usage_template));
     171                 :           2 :         ASSERT(SUCCESS & assert_information_mode_output("-z /definitely/nonexistent/path",usage_template));
     172                 :           2 :         ASSERT(SUCCESS & assert_information_mode_output("--version /definitely/nonexistent/path",version_template));
     173                 :           2 :         ASSERT(SUCCESS & assert_information_mode_output("--compare --help",help_template));
     174                 :           2 :         ASSERT(SUCCESS & assert_information_mode_output("--compare --usage",usage_template));
     175                 :           2 :         ASSERT(SUCCESS & assert_information_mode_output("--compare -z",usage_template));
     176                 :           2 :         ASSERT(SUCCESS & assert_information_mode_output("--compare --version",version_template));
     177                 :             : 
     178                 :           2 :         RETURN_STATUS;
     179                 :             : }
     180                 :             : 
     181                 :           2 : Return test0003(void)
     182                 :             : {
     183                 :           2 :         INITTEST;
     184                 :             : 
     185                 :           2 :         TEST(test0003_1,"Comply default DB name to \"hostname.db\" template…");
     186                 :           2 :         TEST(test0003_2,"Running the application with no arguments at all…");
     187                 :           2 :         TEST(test0003_3,"Information modes without PATH return success…");
     188                 :           2 :         TEST(test0003_4,"Information modes ignore PATH and stop early…");
     189                 :             : 
     190                 :           2 :         RETURN_STATUS;
     191                 :             : }
        

Generated by: LCOV version 2.0-1