LCOV - code coverage report
Current view: top level - tests/src - test0003.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 97.8 % 93 91
Test Date: 2026-07-12 01:01:34 Functions: 100.0 % 6 6
Branches: 50.0 % 6 3

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

Generated by: LCOV version 2.0-1