Counts internally use uint64_t instead of size_t

This ensures that even for 32 bit platforms, the assertion count
should not plausibly overflow.
This commit is contained in:
Martin Hořeňovský 2021-12-02 16:25:11 +01:00
parent c49faa62dd
commit dcf9479c85
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
5 changed files with 14 additions and 13 deletions

View File

@ -24,7 +24,7 @@ namespace Catch {
return *this;
}
std::size_t Counts::total() const {
std::uint64_t Counts::total() const {
return passed + failed + failedButOk;
}
bool Counts::allPassed() const {

View File

@ -9,6 +9,7 @@
#define CATCH_TOTALS_HPP_INCLUDED
#include <cstddef>
#include <cstdint>
namespace Catch {
@ -16,13 +17,13 @@ namespace Catch {
Counts operator - ( Counts const& other ) const;
Counts& operator += ( Counts const& other );
std::size_t total() const;
std::uint64_t total() const;
bool allPassed() const;
bool allOk() const;
std::size_t passed = 0;
std::size_t failed = 0;
std::size_t failedButOk = 0;
std::uint64_t passed = 0;
std::uint64_t failed = 0;
std::uint64_t failedButOk = 0;
};
struct Totals {

View File

@ -44,14 +44,14 @@ namespace Catch {
* **Important:** The provided string must outlive the instance
*/
struct pluralise {
pluralise(std::size_t count, StringRef label):
pluralise(std::uint64_t count, StringRef label):
m_count(count),
m_label(label)
{}
friend std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser );
std::size_t m_count;
std::uint64_t m_count;
StringRef m_label;
};
}

View File

@ -21,7 +21,7 @@ namespace {
// Colour::LightGrey
constexpr Catch::Colour::Code dimColour() { return Catch::Colour::FileName; }
constexpr Catch::StringRef bothOrAll( std::size_t count ) {
constexpr Catch::StringRef bothOrAll( std::uint64_t count ) {
switch (count) {
case 1:
return Catch::StringRef{};

View File

@ -178,9 +178,9 @@ private:
bool printInfoMessages;
};
std::size_t makeRatio(std::size_t number, std::size_t total) {
std::size_t ratio = total > 0 ? CATCH_CONFIG_CONSOLE_WIDTH * number / total : 0;
return (ratio == 0 && number > 0) ? 1 : ratio;
std::size_t makeRatio( std::uint64_t number, std::uint64_t total ) {
const auto ratio = total > 0 ? CATCH_CONFIG_CONSOLE_WIDTH * number / total : 0;
return (ratio == 0 && number > 0) ? 1 : static_cast<std::size_t>(ratio);
}
std::size_t& findMax( std::size_t& i, std::size_t& j, std::size_t& k ) {
@ -597,7 +597,7 @@ struct SummaryColumn {
SummaryColumn( std::string _label, Colour::Code _colour )
: label( CATCH_MOVE( _label ) ),
colour( _colour ) {}
SummaryColumn addRow( std::size_t count ) {
SummaryColumn addRow( std::uint64_t count ) {
ReusableStringStream rss;
rss << count;
std::string row = rss.str();