Branch data Line data Source code
1 : : // *****************************************************************************
2 : : /*!
3 : : \file src/UnitTest/Assessment.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 Unit test suite assessment
9 : : \details Unit test suite assessment.
10 : : */
11 : : // *****************************************************************************
12 : :
13 : : #include <string>
14 : :
15 : : #include "NoWarning/format.hpp"
16 : :
17 : : #include "Print.hpp"
18 : : #include "Assessment.hpp"
19 : :
20 : : namespace unittest {
21 : :
22 : : void
23 : 2497 : evaluate( std::vector< std::string > status,
24 : : std::size_t& ncomplete,
25 : : std::size_t& nwarn,
26 : : std::size_t& nskip,
27 : : std::size_t& nexcp,
28 : : std::size_t& nfail )
29 : : // *****************************************************************************
30 : : // Evaluate a single unit test
31 : : //! \param[in] status Vector of strings containing the test results. See
32 : : //! unittest::TUTTest constructor for the expected structure of status.
33 : : //! \param[inout] ncomplete Number of completed tests
34 : : //! \param[inout] nwarn Number of tests with a warning
35 : : //! \param[inout] nskip Number of skipped tests
36 : : //! \param[inout] nexcp Number of tests with an exception
37 : : //! \param[inout] nfail Number of failed tests
38 : : // *****************************************************************************
39 : : {
40 [ + + ]: 2497 : if (status[2] != "8") { // only care about non-dummy tests
41 : 400 : ++ncomplete; // count number of tests completed
42 [ - + ]: 400 : if (status[2] == "3") // count number of tests with a warning
43 : 0 : ++nwarn;
44 [ - + ]: 400 : else if (status[2] == "7") // count number of skipped tests
45 : 0 : ++nskip;
46 [ - + ]: 400 : else if (status[2] == "2") // count number of tests throwing
47 : 0 : ++nexcp;
48 [ - + ]: 400 : else if (status[2] != "0") // count number of failed tests
49 : 0 : ++nfail;
50 : : }
51 : 2497 : }
52 : :
53 : : bool
54 : 1 : assess( const tk::Print& print,
55 : : std::size_t nfail,
56 : : std::size_t nwarn,
57 : : std::size_t nskip,
58 : : std::size_t nexcp,
59 : : std::size_t ncomplete )
60 : : // *****************************************************************************
61 : : // Echo final assessment after the full unit test suite has finished
62 : : //! \param[in] print Pretty printer
63 : : //! \param[in] nfail Number of failed tests
64 : : //! \param[in] nwarn Number of tests with a warning
65 : : //! \param[in] nskip Number of skipped tests
66 : : //! \param[in] nexcp Number of tests with an exception
67 : : //! \param[in] ncomplete Number of completed tests
68 : : //! \return True of all tests passed, false if there was at least a failure or
69 : : //! an exception
70 : : // *****************************************************************************
71 : : {
72 [ + - ][ + - ]: 1 : if (!nfail && !nwarn && !nskip && !nexcp) {
[ + - ][ + - ]
73 [ + - ][ + - ]: 1 : print.note( "All " + std::to_string(ncomplete) + " tests passed" );
[ + - ]
74 : : } else {
75 : 0 : std::string skip, warn, fail, excp;
76 [ - - ][ - - ]: 0 : if (nwarn) warn = "finished with a warning: " + std::to_string(nwarn);
[ - - ]
77 [ - - ][ - - ]: 0 : if (nskip) skip = std::string(nwarn ? ", " : "") +
[ - - ]
78 [ - - ][ - - ]: 0 : "(fully or partially) skipped: " + std::to_string(nskip);
[ - - ]
79 [ - - ][ - - ]: 0 : if (nexcp) excp = std::string(nskip || nwarn ? ", " : "") +
[ - - ][ - - ]
80 [ - - ][ - - ]: 0 : "threw exception: " + std::to_string(nexcp);
[ - - ]
81 [ - - ][ - - ]: 0 : if (nfail) fail = std::string(nexcp || nskip || nwarn ?
[ - - ]
82 [ - - ][ - - ]: 0 : ", " : "") + "failed: " + std::to_string(nfail);
[ - - ][ - - ]
[ - - ]
83 [ - - ][ - - ]: 0 : print.note( "Of " + std::to_string(ncomplete) + " tests total: "
[ - - ][ - - ]
84 [ - - ][ - - ]: 0 : + warn + skip + excp + fail );
[ - - ][ - - ]
85 : : }
86 : :
87 [ + - ][ + - ]: 1 : return (nfail || nexcp) ? false : true;
88 : : }
89 : :
90 : : } // unittest::
|