MCPcopy Create free account
hub / github.com/catchorg/Catch2 / getContents

Method getContents

extras/catch_amalgamated.cpp:5182–5201  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5180
5181 std::FILE* getFile() { return m_file; }
5182 std::string getContents() {
5183 ReusableStringStream sstr;
5184 constexpr long buffer_size = 100;
5185 char buffer[buffer_size + 1] = {};
5186 long current_pos = ftell( m_file );
5187 CATCH_ENFORCE( current_pos >= 0,
5188 "ftell failed, errno: " << errno );
5189 std::rewind( m_file );
5190 while ( current_pos > 0 ) {
5191 auto read_characters =
5192 std::fread( buffer,
5193 1,
5194 std::min( buffer_size, current_pos ),
5195 m_file );
5196 buffer[read_characters] = '\0';
5197 sstr << buffer;
5198 current_pos -= static_cast<long>( read_characters );
5199 }
5200 return sstr.str();
5201 }
5202
5203 void clear() { std::rewind( m_file ); }
5204

Callers 2

getStdoutMethod · 0.45
getStderrMethod · 0.45

Calls 1

strMethod · 0.45

Tested by

no test coverage detected