LCOV - code coverage report
Current view: top level - tests - main.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 30 35 85.7 %
Date: 2019-05-28 17:54:33 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * File:
       3             :  *    tests/main.cpp
       4             :  *
       5             :  * License:
       6             :  *    Copyright (c) 2006-2019  Made to Order Software Corp.  All Rights Reserved
       7             :  *
       8             :  *    https://snapwebsites.org/
       9             :  *    contact@m2osw.com
      10             :  *
      11             :  *    This program is free software; you can redistribute it and/or modify
      12             :  *    it under the terms of the GNU General Public License as published by
      13             :  *    the Free Software Foundation; either version 2 of the License, or
      14             :  *    (at your option) any later version.
      15             :  *
      16             :  *    This program is distributed in the hope that it will be useful,
      17             :  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
      18             :  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19             :  *    GNU General Public License for more details.
      20             :  *
      21             :  *    You should have received a copy of the GNU General Public License along
      22             :  *    with this program; if not, write to the Free Software Foundation, Inc.,
      23             :  *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      24             :  *
      25             :  * Authors:
      26             :  *    Alexis Wilke   alexis@m2osw.com
      27             :  */
      28             : 
      29             : // Tell catch we want it to add the runner code in this file.
      30             : #define CATCH_CONFIG_RUNNER
      31             : 
      32             : // self
      33             : //
      34             : #include "main.h"
      35             : 
      36             : // advgetopt lib
      37             : //
      38             : #include "libutf8/libutf8.h"
      39             : #include "libutf8/version.h"
      40             : 
      41             : // libexcept lib
      42             : //
      43             : #include "libexcept/exception.h"
      44             : 
      45             : // C++ lib
      46             : //
      47             : #include <sstream>
      48             : 
      49             : 
      50             : namespace unittest
      51             : {
      52             :     bool            g_verbose;
      53             : }
      54             : 
      55             : 
      56             : namespace
      57             : {
      58             :     struct UnitTestCLData
      59             :         //: public Catch::ConfigData
      60             :     {
      61             :         int         seed = 0;
      62             :         bool        progress = false;
      63             :         bool        version = false;
      64             :     };
      65             : }
      66             : // namespace
      67             : 
      68             : 
      69           2 : int unittest_main(int argc, char * argv[])
      70             : {
      71           2 :     UnitTestCLData configData;
      72             : 
      73           3 :     Catch::Session session;
      74             : 
      75           2 :     auto cli = session.cli()
      76           4 :              | Catch::clara::Opt(configData.seed, "seed")
      77           4 :                 ["-S"]["--seed"]
      78           6 :                 ("value to seed the randomizer, if not specified, randomize")
      79           4 :              | Catch::clara::Opt(configData.progress)
      80           4 :                 ["-p"]["--progress"]
      81           6 :                 ("print name of test section being run")
      82             :              | Catch::clara::Opt(configData.version)
      83           4 :                 ["-V"]["--version"]
      84           9 :                 ("print out the libutf8 library version these unit tests pertain to");
      85             : 
      86           2 :     session.cli(cli);
      87             : 
      88           2 :     auto result(session.applyCommandLine(argc, argv));
      89           2 :     if(result != 0)
      90             :     {
      91           0 :         std::cerr << "Error in command line." << std::endl;
      92           0 :         exit(1);
      93             :     }
      94             : 
      95             :     //if( configData.showHelp )
      96             :     //{
      97             :     //    session.showHelp();
      98             :     //    //std::cout << cli << std::endl;
      99             :     //    exit(1);
     100             :     //}
     101             : 
     102           2 :     if( configData.version )
     103             :     {
     104           1 :         std::cout << LIBUTF8_VERSION_STRING << std::endl;
     105           1 :         exit(0);
     106             :     }
     107             : 
     108           1 :     unittest::g_verbose = configData.progress;
     109             : 
     110             :     // by default we get a different seed each time; that really helps
     111             :     // in detecting errors! (I know, I wrote loads of tests before)
     112             :     //
     113           1 :     unsigned int seed(static_cast<unsigned int>(time(NULL)));
     114           1 :     if( configData.seed != 0 )
     115             :     {
     116           0 :         seed = static_cast<unsigned int>(configData.seed);
     117             :     }
     118           1 :     srand(seed);
     119           1 :     std::cout << "libutf8 v" << LIBUTF8_VERSION_STRING << " [" << getpid() << "]:unittest: seed is " << seed << std::endl;
     120             : 
     121           2 :     return session.run();
     122             : }
     123             : 
     124             : 
     125           2 : int main(int argc, char * argv[])
     126             : {
     127           2 :     int r(1);
     128             : 
     129             :     try
     130             :     {
     131           2 :         libexcept::set_collect_stack(false);
     132           2 :         r = unittest_main(argc, argv);
     133             :     }
     134           0 :     catch(std::logic_error const & e)
     135             :     {
     136           0 :         std::cerr << "fatal error: caught a logic error in libutf8 unit tests: " << e.what() << "\n";
     137             :     }
     138             : 
     139           1 :     return r;
     140           6 : }
     141             : 
     142             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.12