LCOV - code coverage report
Current view: top level - tests - catch_main.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 79.4 % 34 27
Test Date: 2026-01-18 09:38:57 Functions: 100.0 % 5 5
Legend: Lines: hit not hit

            Line data    Source code
       1              : // Copyright (c) 2006-2025  Made to Order Software Corp.  All Rights Reserved
       2              : //
       3              : // https://snapwebsites.org/project/advgetopt
       4              : // contact@m2osw.com
       5              : //
       6              : // This program is free software; you can redistribute it and/or modify
       7              : // it under the terms of the GNU General Public License as published by
       8              : // the Free Software Foundation; either version 2 of the License, or
       9              : // (at your option) any later version.
      10              : //
      11              : // This program is distributed in the hope that it will be useful,
      12              : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      13              : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14              : // GNU General Public License for more details.
      15              : //
      16              : // You should have received a copy of the GNU General Public License along
      17              : // with this program; if not, write to the Free Software Foundation, Inc.,
      18              : // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      19              : 
      20              : // Tell catch we want it to add the runner code in this file.
      21              : #define CATCH_CONFIG_RUNNER
      22              : 
      23              : // self
      24              : //
      25              : #include    "catch_main.h"
      26              : 
      27              : 
      28              : // advgetopt
      29              : //
      30              : #include    <advgetopt/advgetopt.h>
      31              : #include    <advgetopt/version.h>
      32              : 
      33              : 
      34              : // libexcept
      35              : //
      36              : #include    <libexcept/exception.h>
      37              : 
      38              : 
      39              : // snapdev
      40              : //
      41              : #include    <snapdev/not_used.h>
      42              : 
      43              : 
      44              : // C++
      45              : //
      46              : #include    <sstream>
      47              : 
      48              : 
      49              : // last include
      50              : //
      51              : #include    <snapdev/poison.h>
      52              : 
      53              : 
      54              : 
      55              : 
      56              : 
      57              : namespace SNAP_CATCH2_NAMESPACE
      58              : {
      59              : 
      60              : 
      61              : 
      62              : std::string                 g_config_filename;
      63              : std::string                 g_config_project_filename;
      64              : 
      65              : 
      66          190 : void init_tmp_dir(std::string const & project_name, std::string const & prefname, bool dir)
      67              : {
      68          190 :     std::string tmpdir(SNAP_CATCH2_NAMESPACE::g_tmp_dir());
      69          190 :     tmpdir += "/.config";
      70          190 :     std::stringstream ss;
      71          190 :     if(dir)
      72              :     {
      73            2 :         ss << "mkdir -p " << tmpdir << "/" << prefname << "/" << project_name << ".d";
      74              :     }
      75              :     else
      76              :     {
      77          188 :         ss << "mkdir -p " << tmpdir << "/" << project_name << ".d";
      78              :     }
      79          190 :     if(system(ss.str().c_str()) != 0)
      80              :     {
      81            0 :         std::cerr << "fatal error: creating sub-temporary directory \"" << ss.str() << "\" failed.\n";
      82            0 :         exit(1);
      83              :     }
      84          190 :     if(dir)
      85              :     {
      86            2 :         g_config_filename = tmpdir + "/" + prefname;
      87            2 :         g_config_project_filename = tmpdir + "/" + prefname + "/" + project_name + ".d";
      88              :     }
      89              :     else
      90              :     {
      91          188 :         g_config_filename = tmpdir + "/" + prefname + ".config";
      92          188 :         g_config_project_filename = tmpdir + "/" + project_name + ".d/50-" + prefname + ".config";
      93              :     }
      94          380 : }
      95              : 
      96              : 
      97              : 
      98              : }
      99              : // SNAP_CATCH2_NAMESPACE namespace
     100              : 
     101              : 
     102              : 
     103              : 
     104              : namespace
     105              : {
     106              : 
     107              : 
     108              : 
     109              : 
     110              : 
     111            1 : int finish_init(Catch::Session & session)
     112              : {
     113            1 :     snapdev::NOT_USED(session);
     114              : 
     115            1 :     cppthread::set_log_callback(SNAP_CATCH2_NAMESPACE::log_for_test);
     116              : 
     117            1 :     char const * options(getenv("ADVGETOPT_TEST_OPTIONS"));
     118            1 :     if(options != nullptr
     119            0 :     && *options != '\0')
     120              :     {
     121            0 :         std::cerr << std::endl
     122              :                   << "error:unittest: ADVGETOPT_TEST_OPTIONS already exists,"
     123              :                         " the advgetopt tests would not work as expected with such."
     124            0 :                      " Please unset that environment variable and try again."
     125            0 :                   << std::endl;
     126            0 :         throw std::runtime_error("ADVGETOPT_TEST_OPTIONS already exists");
     127              :     }
     128              : 
     129            1 :     return 0;
     130              : }
     131              : 
     132              : 
     133            1 : void tests_done()
     134              : {
     135            1 :     SNAP_CATCH2_NAMESPACE::expected_logs_stack_is_empty();
     136            1 : }
     137              : 
     138              : 
     139              : 
     140              : }
     141              : // no name namespace
     142              : 
     143              : 
     144              : 
     145              : 
     146              : 
     147              : 
     148            2 : int main(int argc, char * argv[])
     149              : {
     150            2 :     return SNAP_CATCH2_NAMESPACE::snap_catch2_main(
     151              :               "advgetopt"
     152              :             , LIBADVGETOPT_VERSION_STRING
     153              :             , argc
     154              :             , argv
     155            4 :             , []() { libexcept::set_collect_stack(libexcept::collect_stack_t::COLLECT_STACK_NO); }
     156              :             , nullptr
     157              :             , &finish_init
     158              :             , &tests_done
     159            2 :         );
     160              : }
     161              : 
     162              : 
     163              : // vim: ts=4 sw=4 et
        

Generated by: LCOV version 2.0-1

Snap C++ | List of projects | List of versions