Quinoa all test code coverage report
Current view: top level - Main - UnitTestPrint.hpp (source / functions) Hit Total Coverage
Commit: -128-NOTFOUND Lines: 32 34 94.1 %
Date: 2024-04-29 14:42:33 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 37 100 37.0 %

           Branch data     Line data    Source code
       1                 :            : // *****************************************************************************
       2                 :            : /*!
       3                 :            :   \file      src/Main/UnitTestPrint.hpp
       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 printer
       9                 :            :   \details   UnitTest's printer
      10                 :            : */
      11                 :            : // *****************************************************************************
      12                 :            : #ifndef UnitTestPrint_h
      13                 :            : #define UnitTestPrint_h
      14                 :            : 
      15                 :            : #include <sstream>
      16                 :            : 
      17                 :            : #include "Types.hpp"
      18                 :            : #include "Print.hpp"
      19                 :            : #include "Exception.hpp"
      20                 :            : 
      21                 :            : namespace unittest {
      22                 :            : 
      23                 :            : //! UnitTestPrint : tk::Print
      24                 :       2595 : class UnitTestPrint : public tk::Print {
      25                 :            : 
      26                 :            :   public:
      27                 :            :     //! Constructor
      28                 :            :     //! \param[in] screen Screen output filename
      29                 :            :     //! \param[in,out] str Verbose stream
      30                 :            :     //! \param[in] mode Open mode for screen output file, see
      31                 :            :     //!   http://en.cppreference.com/w/cpp/io/ios_base/openmode
      32                 :            :     //! \param[in,out] qstr Quiet stream
      33                 :            :     //! \see tk::Print::Print
      34                 :            :     explicit UnitTestPrint( const std::string& screen = {},
      35                 :            :                             std::ostream& str = std::clog,
      36                 :            :                             std::ios_base::openmode mode = std::ios_base::out,
      37                 :            :                             std::ostream& qstr = std::cout ) :
      38         [ +  - ]:       2595 :       Print( screen, str, mode, qstr ) {}
      39                 :            : 
      40                 :            :     //! Print unit tests header (with legend)
      41                 :            :     //! \param[in] t Section title
      42                 :            :     //! \param[in] group String attempting to match unit test groups
      43         [ +  - ]:          1 :     void unithead( const std::string& t, const std::string& group ) const {
      44 [ +  - ][ +  - ]:          1 :       std::string g = group.empty() ? "all" : group;
      45                 :          1 :       m_stream << m_section_title_fmt % m_section_indent
      46         [ +  - ]:          1 :                                       % m_section_bullet
      47         [ +  - ]:          1 :                                       % t;
      48                 :          1 :       m_stream << m_section_underline_fmt
      49         [ +  - ]:          1 :                   % m_section_indent
      50         [ +  - ]:          1 :                   % std::string( m_section_indent.size() + 2 + t.size(),
      51         [ +  - ]:          1 :                                 '-' );
      52 [ +  - ][ +  - ]:          2 :       raw( m_item_indent + "Groups: " + g + " (use -g str to match groups)\n" +
         [ +  - ][ -  + ]
         [ -  + ][ -  + ]
         [ -  + ][ -  - ]
         [ -  - ][ -  - ]
                 [ -  - ]
      53 [ +  - ][ +  - ]:          3 :            m_item_indent + "Legend: [done/failed] group:test : result\n\n" );
         [ -  + ][ -  - ]
      54                 :          1 :     }
      55                 :            : 
      56                 :            :     //! Print one-liner info for test
      57                 :            :     //! \details Columns:
      58                 :            :     //!   [done/failed]
      59                 :            :     //!   - done: number of tests completed so far
      60                 :            :     //!   - failed: number of failed tests so far
      61                 :            :     //!   name of the test group
      62                 :            :     //!   name of the test
      63                 :            :     //!   result (with additional info if failed)
      64                 :            :     //!   Assumed fields for status:
      65                 :            :     //!   - status[0]: test group name
      66                 :            :     //!   - status[1]: test name
      67                 :            :     //!   - status[2]: result (tut::test_result::result_type as string)
      68                 :            :     //!   - status[3]: exception message for failed test
      69                 :            :     //!   - status[4]: exception type id for failed test
      70                 :       2593 :     void test( std::size_t ncomplete,
      71                 :            :                std::size_t nfail,
      72                 :            :                const std::vector< std::string >& status )
      73                 :            :     {
      74         [ +  + ]:       2593 :       if (status[2] != "8") {             // if not dummy
      75                 :        376 :         std::stringstream ss;
      76         [ +  - ]:        376 :         ss << "[" << ncomplete << "/" << nfail << "] " << status[0] << ":"
      77         [ +  - ]:        376 :            << status[1];
      78                 :        376 :         m_stream <<
      79 [ +  - ][ +  + ]:        752 :           m_item_widename_value_fmt % m_item_indent % ss.str()
                 [ -  - ]
      80 [ +  - ][ +  - ]:       1128 :                                     % result( status[2], status[3], status[4] )
      81                 :            :           << std::flush;
      82                 :            :       }
      83                 :       2593 :     }
      84                 :            : 
      85                 :            :   private:
      86                 :            :     //! Return human-readable test result based on result code
      87                 :            :     //! \param[in] code Result code
      88                 :            :     //! \param[in] msg Message to append
      89                 :            :     //! \param[in] ex Expection message to attach to exceptions cases
      90                 :        376 :     std::string result( const std::string& code,
      91                 :            :                         const std::string& msg,
      92                 :            :                         const std::string& ex ) const
      93                 :            :     {
      94         [ +  + ]:        376 :       if (code == "0") return "ok";
      95         [ -  + ]:         56 :       else if (code == "1") return "fail: " + msg;
      96 [ -  + ][ -  - ]:         56 :       else if (code == "2") return "except: " + msg + ex;
      97         [ -  + ]:         56 :       else if (code == "3") return "warning: " + msg;
      98         [ -  + ]:         56 :       else if (code == "4") return "terminate: " + msg;
      99 [ -  + ][ -  - ]:         56 :       else if (code == "5") return "ex_ctor: " + msg + ex;
     100 [ -  + ][ -  - ]:         56 :       else if (code == "6") return "rethrown: " + msg + ex;
     101         [ +  - ]:         56 :       else if (code == "7") return "skipped: " + msg;
     102         [ -  - ]:          0 :       else if (code == "8") return "dummy";
     103 [ -  - ][ -  - ]:          0 :       else Throw( "No such unit test result code found" );
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
     104                 :            :     }
     105                 :            : };
     106                 :            : 
     107                 :            : } // unittest::
     108                 :            : 
     109                 :            : #endif // UnitTestPrint_h

Generated by: LCOV version 1.14