mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-31 20:27:11 +01:00 
			
		
		
		
	patched >2-digit tag-count padding in base reporter
Passing the CLI argument '--list-tags' outputs a list like:
```
All available tags:
  11  [mytag]
   4  [myothertag]
2 tags
```
However, the width of the tag-count column was previously hardcoded to 2, such that the formatting broke (with the tag names awkwardly misaligned/displaced) for 3+ digit tag counts. This occurred whenever a tag contains one hundred or more tests, and would result in formatting like:
```
All available tags:
  11  [mytag]
  100  [myjumbotag]
   4  [myothertag]
3 tags
```
This patch pre-computes the maximum number of digits among the tag counts, expanding the padding when there are more than 100 tests in a tag (and handling when tags are empty). It now outputs e.g.
```
All available tags:
   11  [mytag]
  100  [myjumbotag]
    4  [myothertag]
3 tags
```
			
			
This commit is contained in:
		 Tyson Jones
					Tyson Jones
				
			
				
					committed by
					
						 Martin Hořeňovský
						Martin Hořeňovský
					
				
			
			
				
	
			
			
			 Martin Hořeňovský
						Martin Hořeňovský
					
				
			
						parent
						
							d134b0cae3
						
					
				
				
					commit
					bd2d918f32
				
			| @@ -19,6 +19,7 @@ | ||||
|  | ||||
| #include <algorithm> | ||||
| #include <cfloat> | ||||
| #include <cmath> | ||||
| #include <cstdio> | ||||
| #include <ostream> | ||||
| #include <iomanip> | ||||
| @@ -182,9 +183,29 @@ namespace Catch { | ||||
|             out << "All available tags:\n"; | ||||
|         } | ||||
|  | ||||
|         // minimum whitespace to pad tag counts, possibly overwritten below | ||||
|         size_t maxTagCountLen = 2; | ||||
|  | ||||
|         // determine necessary padding for tag count column | ||||
|         if ( ! tags.empty() ) { | ||||
|             const auto maxTagCount = | ||||
|                 std::max_element( tags.begin(), | ||||
|                                   tags.end(), | ||||
|                                   []( auto const& lhs, auto const& rhs ) { | ||||
|                                       return lhs.count < rhs.count; | ||||
|                                   } ) | ||||
|                     ->count; | ||||
|              | ||||
|             // more padding necessary for 3+ digits | ||||
|             if (maxTagCount >= 100) { | ||||
|                 auto numDigits = 1 + std::floor( std::log10( maxTagCount ) ); | ||||
|                 maxTagCountLen = static_cast<size_t>( numDigits ); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         for ( auto const& tagCount : tags ) { | ||||
|             ReusableStringStream rss; | ||||
|             rss << "  " << std::setw( 2 ) << tagCount.count << "  "; | ||||
|             rss << "  " << std::setw( maxTagCountLen ) << tagCount.count << "  "; | ||||
|             auto str = rss.str(); | ||||
|             auto wrapper = TextFlow::Column( tagCount.all() ) | ||||
|                                .initialIndent( 0 ) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user