catch_totals.cpp
1 2 // Copyright Catch2 Authors 3 // Distributed under the Boost Software License, Version 1.0. 4 // (See accompanying file LICENSE.txt or copy at 5 // https://www.boost.org/LICENSE_1_0.txt) 6 7 // SPDX-License-Identifier: BSL-1.0 8 #include <catch2/catch_totals.hpp> 9 10 namespace Catch { 11 12 Counts Counts::operator - ( Counts const& other ) const { 13 Counts diff; 14 diff.passed = passed - other.passed; 15 diff.failed = failed - other.failed; 16 diff.failedButOk = failedButOk - other.failedButOk; 17 diff.skipped = skipped - other.skipped; 18 return diff; 19 } 20 21 Counts& Counts::operator += ( Counts const& other ) { 22 passed += other.passed; 23 failed += other.failed; 24 failedButOk += other.failedButOk; 25 skipped += other.skipped; 26 return *this; 27 } 28 29 std::uint64_t Counts::total() const { 30 return passed + failed + failedButOk + skipped; 31 } 32 bool Counts::allPassed() const { 33 return failed == 0 && failedButOk == 0 && skipped == 0; 34 } 35 bool Counts::allOk() const { 36 return failed == 0; 37 } 38 39 Totals Totals::operator - ( Totals const& other ) const { 40 Totals diff; 41 diff.assertions = assertions - other.assertions; 42 diff.testCases = testCases - other.testCases; 43 return diff; 44 } 45 46 Totals& Totals::operator += ( Totals const& other ) { 47 assertions += other.assertions; 48 testCases += other.testCases; 49 return *this; 50 } 51 52 Totals Totals::delta( Totals const& prevTotals ) const { 53 Totals diff = *this - prevTotals; 54 if( diff.assertions.failed > 0 ) 55 ++diff.testCases.failed; 56 else if( diff.assertions.failedButOk > 0 ) 57 ++diff.testCases.failedButOk; 58 else if ( diff.assertions.skipped > 0 ) 59 ++ diff.testCases.skipped; 60 else 61 ++diff.testCases.passed; 62 return diff; 63 } 64 65 }