Quinoa all test code coverage report
Current view: top level - Control/UnitTest/CmdLine - Parser.cpp (source / functions) Hit Total Coverage
Commit: -128-NOTFOUND Lines: 23 36 63.9 %
Date: 2024-11-22 08:51:48 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 18 84 21.4 %

           Branch data     Line data    Source code
       1                 :            : // *****************************************************************************
       2                 :            : /*!
       3                 :            :   \file      src/Control/UnitTest/CmdLine/Parser.cpp
       4                 :            :   \copyright 2012-2015 J. Bakosi,
       5                 :            :              2016-2018 Los Alamos National Security, LLC.,
       6                 :            :              2019-2021 Triad National Security, LLC.
       7                 :            :              All rights reserved. See the LICENSE file for details.
       8                 :            :   \brief     UnitTest's command line parser
       9                 :            :   \details   This file defines the command-line argument parser for the unit
      10                 :            :      test suite, UnitTest.
      11                 :            : */
      12                 :            : // *****************************************************************************
      13                 :            : 
      14                 :            : #include "NoWarning/pegtl.hpp"
      15                 :            : 
      16                 :            : #include "Print.hpp"
      17                 :            : #include "UnitTest/Types.hpp"
      18                 :            : #include "UnitTest/CmdLine/Parser.hpp"
      19                 :            : #include "UnitTest/CmdLine/Grammar.hpp"
      20                 :            : #include "UnitTest/CmdLine/CmdLine.hpp"
      21                 :            : 
      22                 :            : namespace tk {
      23                 :            : namespace grm {
      24                 :            : 
      25                 :            : tk::Print g_print;
      26                 :            : 
      27                 :            : } // grm::
      28                 :            : } // tk::
      29                 :            : 
      30                 :            : using unittest::CmdLineParser;
      31                 :            : 
      32                 :          1 : CmdLineParser::CmdLineParser( int argc,
      33                 :            :                               char** argv,
      34                 :            :                               const tk::Print& print,
      35                 :            :                               ctr::CmdLine& cmdline,
      36                 :          1 :                               bool& helped ) :
      37                 :          1 :   StringParser( argc, argv )
      38                 :            : // *****************************************************************************
      39                 :            : //  Contructor: parse the command line for UnitTest
      40                 :            : //! \param[in] argc Number of C-style character arrays in argv
      41                 :            : //! \param[in] argv C-style character array of character arrays
      42                 :            : //! \param[in] print Pretty printer
      43                 :            : //! \param[inout] cmdline Command-line stack where data is stored from parsing
      44                 :            : //! \param[inout] helped Boolean indicating if command-line help was requested
      45                 :            : // *****************************************************************************
      46                 :            : {
      47                 :            :   // Create CmdLine (a tagged tuple) to store parsed input
      48         [ +  - ]:          2 :   ctr::CmdLine cmd;
      49                 :            : 
      50                 :            :   // Reset parser's output stream to that of print's. This is so that mild
      51                 :            :   // warnings emitted during parsing can be output using the pretty printer.
      52                 :            :   // Usually, errors and warnings are simply accumulated during parsing and
      53                 :            :   // printed during diagnostics after the parser has finished. However, in some
      54                 :            :   // special cases we can provide a more user-friendly message right during
      55                 :            :   // parsing since there is more information available to construct a more
      56                 :            :   // sensible message. This is done in e.g., tk::grm::store_option. Resetting
      57                 :            :   // the global g_print, to that of passed in as the constructor argument allows
      58                 :            :   // not to have to create a new pretty printer, but use the existing one.
      59 [ +  - ][ +  - ]:          1 :   tk::grm::g_print.reset( print.save() );
      60                 :            : 
      61                 :            :   // Parse command line string by populating the underlying tagged tuple
      62         [ +  - ]:          2 :   tao::pegtl::memory_input<> in( m_string, "command line" );
      63         [ +  - ]:          1 :   tao::pegtl::parse< cmd::read_string, tk::grm::action >( in, cmd );
      64                 :            : 
      65                 :            :   // Echo errors and warnings accumulated during parsing
      66         [ +  - ]:          1 :   diagnostics( print, cmd.get< tag::error >() );
      67                 :            : 
      68                 :            :   // Strip command line (and its underlying tagged tuple) from PEGTL instruments
      69                 :            :   // and transfer it out
      70                 :          1 :   cmdline = std::move( cmd );
      71                 :            : 
      72                 :            :   // If we got here, the parser has succeeded
      73 [ +  - ][ +  - ]:          1 :   print.item("Parsed command line", "success");
      74                 :            : 
      75                 :            :   // Print out help on all command-line arguments if requested
      76                 :          1 :   const auto helpcmd = cmdline.get< tag::help >();
      77         [ -  + ]:          1 :   if (helpcmd) {
      78 [ -  - ][ -  - ]:          0 :     print.help< tk::QUIET >( tk::unittest_executable(),
         [ -  - ][ -  - ]
      79                 :          0 :                              cmdline.get< tag::cmdinfo >(),
      80                 :            :                              "Command-line Parameters:", "-" );
      81 [ -  - ][ -  - ]:          0 :    print.mandatory< tk::QUIET >( "None of the arguments are mandatory." );
      82 [ -  - ][ -  - ]:          0 :     print.usage< tk::QUIET >(
      83         [ -  - ]:          0 :       tk::unittest_executable(),
      84 [ -  - ][ -  - ]:          0 :       "charmrun +p4 " + tk::unittest_executable() + " -" +
         [ -  - ][ -  - ]
                 [ -  - ]
      85                 :            :         *kw::verbose().alias(),
      86                 :            :       "will execute all unit tests on 4 CPUs producing verbose screen output" );
      87                 :            :   }
      88                 :            : 
      89                 :            :   // Print out verbose help for a single keyword if requested
      90         [ +  - ]:          2 :   const auto helpkw = cmdline.get< tag::helpkw >();
      91         [ -  + ]:          1 :   if (!helpkw.keyword.empty())
      92 [ -  - ][ -  - ]:          0 :     print.helpkw< tk::QUIET >( tk::unittest_executable(), helpkw );
      93                 :            : 
      94                 :            :   // Print out version information if it was requested
      95                 :          1 :   const auto version = cmdline.get< tag::version >();
      96         [ -  + ]:          1 :   if (version)
      97 [ -  - ][ -  - ]:          0 :     print.version< tk::QUIET >( tk::unittest_executable(),
      98         [ -  - ]:          0 :                                 tk::quinoa_version(),
      99         [ -  - ]:          0 :                                 tk::git_commit(),
     100         [ -  - ]:          0 :                                 tk::copyright() );
     101                 :            : 
     102                 :            :   // Print out license information if it was requested
     103                 :          1 :   const auto license = cmdline.get< tag::license >();
     104         [ -  + ]:          1 :   if (license)
     105 [ -  - ][ -  - ]:          0 :     print.license< tk::QUIET >( tk::unittest_executable(), tk::license() );
                 [ -  - ]
     106                 :            : 
     107                 :            :   // Will exit in main chare constructor if any help was output
     108                 :          1 :   if (cmdline.get< tag::help >() ||           // help on all cmdline args
     109 [ +  - ][ +  - ]:          1 :       !cmdline.get< tag::helpkw >().keyword.empty() || // help on a keyword
     110 [ +  - ][ -  + ]:          2 :       version || license)                     // version or license output
                 [ -  + ]
     111                 :          0 :     helped = true;
     112                 :            :   else
     113                 :          1 :     helped = false;
     114                 :          1 : }

Generated by: LCOV version 1.14