Skip to content

Commit

Permalink
Update per contributing docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmatson committed Jul 14, 2022
1 parent ac345f8 commit 713e31c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/catch2/internal/catch_enforce.cpp
Expand Up @@ -9,6 +9,7 @@
#include <catch2/internal/catch_stdstreams.hpp>

#include <stdexcept>
#include <system_error>


namespace Catch {
Expand Down Expand Up @@ -36,6 +37,11 @@ namespace Catch {
throw_exception(std::runtime_error(msg));
}

[[noreturn]]
void throw_system_error(int ev, const std::error_category& ecat) {
throw_exception(std::system_error(ev, ecat));
}



} // namespace Catch;
5 changes: 5 additions & 0 deletions src/catch2/internal/catch_enforce.hpp
Expand Up @@ -32,6 +32,8 @@ namespace Catch {
void throw_domain_error(std::string const& msg);
[[noreturn]]
void throw_runtime_error(std::string const& msg);
[[noreturn]]
void throw_system_error(int ev, const std::error_category& ecat);

} // namespace Catch;

Expand All @@ -47,6 +49,9 @@ namespace Catch {
#define CATCH_RUNTIME_ERROR(...) \
Catch::throw_runtime_error(CATCH_MAKE_MSG( __VA_ARGS__ ))

#define CATCH_SYSTEM_ERROR(ev, ecat) \
Catch::throw_system_error((ev), (ecat))

#define CATCH_ENFORCE( condition, ... ) \
do{ if( !(condition) ) CATCH_ERROR( __VA_ARGS__ ); } while(false)

Expand Down
21 changes: 11 additions & 10 deletions src/catch2/internal/catch_output_redirect.cpp
Expand Up @@ -14,6 +14,7 @@
#include <sstream>

#if defined(CATCH_CONFIG_NEW_CAPTURE)
#include <catch2/internal/catch_move_and_forward.hpp>
#include <system_error>
#if defined(_MSC_VER)
#include <fcntl.h> // _O_TEXT
Expand Down Expand Up @@ -67,7 +68,7 @@ inline void close_or_throw(int descriptor)
{
if (close(descriptor))
{
throw std::system_error{ errno, std::generic_category() };
CATCH_SYSTEM_ERROR(errno, std::generic_category());
}
}

Expand All @@ -77,7 +78,7 @@ inline int dup_or_throw(int descriptor)

if (result == -1)
{
throw std::system_error{ errno, std::generic_category() };
CATCH_SYSTEM_ERROR(errno, std::generic_category());
}

return result;
Expand All @@ -89,7 +90,7 @@ inline int dup2_or_throw(int sourceDescriptor, int destinationDescriptor)

if (result == -1)
{
throw std::system_error{ errno, std::generic_category() };
CATCH_SYSTEM_ERROR(errno, std::generic_category());
}

return result;
Expand All @@ -101,7 +102,7 @@ inline int fileno_or_throw(std::FILE* file)

if (result == -1)
{
throw std::system_error{ errno, std::generic_category() };
CATCH_SYSTEM_ERROR(errno, std::generic_category());
}

return result;
Expand All @@ -119,7 +120,7 @@ inline void pipe_or_throw(int descriptors[2])

if (result)
{
throw std::system_error{ errno, std::generic_category() };
CATCH_SYSTEM_ERROR(errno, std::generic_category());
}
}

Expand All @@ -133,7 +134,7 @@ inline size_t read_or_throw(int descriptor, void* buffer, size_t size)

if (result == -1)
{
throw std::system_error{ errno, std::generic_category() };
CATCH_SYSTEM_ERROR(errno, std::generic_category());
}

return static_cast<size_t>(result);
Expand All @@ -143,14 +144,14 @@ inline void fflush_or_throw(std::FILE* file)
{
if (std::fflush(file))
{
throw std::system_error{ errno, std::generic_category() };
CATCH_SYSTEM_ERROR(errno, std::generic_category());
}
}

jthread::jthread() noexcept : m_thread{} {}

template <typename F, typename... Args>
jthread::jthread(F&& f, Args&&... args) : m_thread{ std::forward<F>(f), std::forward<Args>(args)... } {}
jthread::jthread(F&& f, Args&&... args) : m_thread{ CATCH_FORWARD(f), CATCH_FORWARD(args)... } {}

// Not exactly like std::jthread, but close enough for the code below.
jthread::~jthread() noexcept
Expand Down Expand Up @@ -237,8 +238,8 @@ OutputFileRedirector::OutputFileRedirector(FILE* file, std::string& result) :

// Anonymous pipes have a limited buffer and require an active reader to ensure the writer does not become blocked.
// Use a separate thread to ensure the buffer does not get stuck full.
m_readThread = jthread{ [readDescriptor{ std::move(readDescriptor) }, &result] () mutable {
read_thread(std::move(readDescriptor), result); } };
m_readThread = jthread{ [readDescriptor{ CATCH_MOVE(readDescriptor) }, &result] () mutable {
read_thread(CATCH_MOVE(readDescriptor), result); } };

dup2_or_throw(writeDescriptor.get(), m_fd);
}
Expand Down

0 comments on commit 713e31c

Please sign in to comment.