diff options
| author | Leitwolf11 | 2026-09-24 23:05:47 +0300 |
|---|---|---|
| committer | Leitwolf11 | 2026-09-24 23:05:47 +0300 |
| commit | d79b294903e4d0f4b24fdf1cc50be4b0fec7f745 (patch) | |
| tree | 64f0c7c3dfbc08bfb70d9a37df5cccae3d52b526 /src/Progmasoft/Results.cpp | |
| parent | 9ad804cedf4cc4a85ef89fe097f97a3b44654360 (diff) | |
| download | catch3-0.2.0.tar.gz | |
Add snapshots and JUnit result serialization0.2.0
Diffstat (limited to 'src/Progmasoft/Results.cpp')
| -rw-r--r-- | src/Progmasoft/Results.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/Progmasoft/Results.cpp b/src/Progmasoft/Results.cpp new file mode 100644 index 00000000..69a819a7 --- /dev/null +++ b/src/Progmasoft/Results.cpp @@ -0,0 +1,73 @@ +// Copyright (c) 2026 Progmasoft. +// SPDX-License-Identifier: MPL-2.0 WITH AdditionRef-Progmasoft-Exception-1.1 +#include <Progmasoft/Catch3/Results.hpp> + +#include <cmath> +#include <limits> +#include <stdexcept> + +namespace Progmasoft::Catch3 { + + namespace { + + void AccumulateCases( TestRunSummary& summary, + const std::vector<TestCaseResult>& testCases ) { + for ( const TestCaseResult& testCase : testCases ) { + if ( !std::isfinite( testCase.DurationSeconds ) || + testCase.DurationSeconds < 0.0 ) { + throw std::invalid_argument( + "test duration must be finite and non-negative" ); + } + if ( summary.Tests == + std::numeric_limits<std::size_t>::max() ) { + throw std::overflow_error( "test count overflow" ); + } + + ++summary.Tests; + summary.DurationSeconds += testCase.DurationSeconds; + if ( !std::isfinite( summary.DurationSeconds ) ) { + throw std::overflow_error( "test duration total overflow" ); + } + + switch ( testCase.Status ) { + case TestCaseStatus::kPassed: + break; + case TestCaseStatus::kFailed: + ++summary.Failures; + break; + case TestCaseStatus::kErrored: + ++summary.Errors; + break; + case TestCaseStatus::kSkipped: + ++summary.Skipped; + break; + default: + throw std::invalid_argument( "unknown test case status" ); + } + } + } + + } // namespace + + std::size_t TestRunSummary::Passed() const noexcept { + if ( Failures > Tests || Errors > Tests - Failures ) { return 0; } + const std::size_t failuresAndErrors = Failures + Errors; + if ( Skipped > Tests - failuresAndErrors ) { return 0; } + return Tests - failuresAndErrors - Skipped; + } + + TestRunSummary SummarizeTestSuite( const TestSuiteResult& result ) { + TestRunSummary summary; + AccumulateCases( summary, result.TestCases ); + return summary; + } + + TestRunSummary SummarizeTestRun( const TestRunResult& result ) { + TestRunSummary summary; + for ( const TestSuiteResult& suite : result.TestSuites ) { + AccumulateCases( summary, suite.TestCases ); + } + return summary; + } + +} // namespace Progmasoft::Catch3 |