Skip to content

Commit 6aa8be8

Browse files
author
davidmatson
committed
Update per contributing docs.
1 parent ac345f8 commit 6aa8be8

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

src/catch2/internal/catch_enforce.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <catch2/internal/catch_stdstreams.hpp>
1010

1111
#include <stdexcept>
12+
#include <system_error>
1213

1314

1415
namespace Catch {
@@ -36,6 +37,11 @@ namespace Catch {
3637
throw_exception(std::runtime_error(msg));
3738
}
3839

40+
[[noreturn]]
41+
void throw_system_error(int ev, const std::error_category& ecat) {
42+
throw_exception(std::system_error(ev, ecat));
43+
}
44+
3945

4046

4147
} // namespace Catch;

src/catch2/internal/catch_enforce.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ namespace Catch {
3232
void throw_domain_error(std::string const& msg);
3333
[[noreturn]]
3434
void throw_runtime_error(std::string const& msg);
35+
[[noreturn]]
36+
void throw_system_error(int ev, const std::error_category& ecat);
3537

3638
} // namespace Catch;
3739

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

52+
#define CATCH_SYSTEM_ERROR(ev, ecat) \
53+
Catch::throw_system_error((ev), (ecat))
54+
5055
#define CATCH_ENFORCE( condition, ... ) \
5156
do{ if( !(condition) ) CATCH_ERROR( __VA_ARGS__ ); } while(false)
5257

src/catch2/internal/catch_output_redirect.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <sstream>
1515

1616
#if defined(CATCH_CONFIG_NEW_CAPTURE)
17+
#include <catch2/internal/catch_move_and_forward.hpp>
1718
#include <system_error>
1819
#if defined(_MSC_VER)
1920
#include <fcntl.h> // _O_TEXT
@@ -67,7 +68,7 @@ inline void close_or_throw(int descriptor)
6768
{
6869
if (close(descriptor))
6970
{
70-
throw std::system_error{ errno, std::generic_category() };
71+
CATCH_SYSTEM_ERROR(errno, std::generic_category());
7172
}
7273
}
7374

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

7879
if (result == -1)
7980
{
80-
throw std::system_error{ errno, std::generic_category() };
81+
CATCH_SYSTEM_ERROR(errno, std::generic_category());
8182
}
8283

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

9091
if (result == -1)
9192
{
92-
throw std::system_error{ errno, std::generic_category() };
93+
CATCH_SYSTEM_ERROR(errno, std::generic_category());
9394
}
9495

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

102103
if (result == -1)
103104
{
104-
throw std::system_error{ errno, std::generic_category() };
105+
CATCH_SYSTEM_ERROR(errno, std::generic_category());
105106
}
106107

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

120121
if (result)
121122
{
122-
throw std::system_error{ errno, std::generic_category() };
123+
CATCH_SYSTEM_ERROR(errno, std::generic_category());
123124
}
124125
}
125126

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

134135
if (result == -1)
135136
{
136-
throw std::system_error{ errno, std::generic_category() };
137+
CATCH_SYSTEM_ERROR(errno, std::generic_category());
137138
}
138139

139140
return static_cast<size_t>(result);
@@ -143,14 +144,14 @@ inline void fflush_or_throw(std::FILE* file)
143144
{
144145
if (std::fflush(file))
145146
{
146-
throw std::system_error{ errno, std::generic_category() };
147+
CATCH_SYSTEM_ERROR(errno, std::generic_category());
147148
}
148149
}
149150

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

152153
template <typename F, typename... Args>
153-
jthread::jthread(F&& f, Args&&... args) : m_thread{ std::forward<F>(f), std::forward<Args>(args)... } {}
154+
jthread::jthread(F&& f, Args&&... args) : m_thread{ CATCH_FORWARD<F>(f), CATCH_FORWARD<Args>(args)... } {}
154155

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

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

243244
dup2_or_throw(writeDescriptor.get(), m_fd);
244245
}

0 commit comments

Comments
 (0)