Skip to content

Commit ffc351b

Browse files
committed
Add clang-format check in CI/CD and format all files
1 parent 8bace31 commit ffc351b

18 files changed

+310
-286
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
libzmq: "4.3.5"
4545
libzmqbuild: "cmake"
4646
coverage: "-DCOVERAGE=ON"
47-
aptinstall: "lcov"
47+
aptinstall: "lcov clang-format"
4848
# clang
4949
- os: "ubuntu-22.04"
5050
cppstd: "17"
@@ -61,7 +61,7 @@ jobs:
6161
drafts: "OFF"
6262
libzmq: "4.3.5"
6363
libzmqbuild: false
64-
brewinstall: "zeromq"
64+
brewinstall: "zeromq clang-format"
6565
# windows
6666
#- os: "windows-2019"
6767
# cppstd: "14"
@@ -132,6 +132,10 @@ jobs:
132132
make install
133133
echo "LIBZMQ=${PWD}/libzmq-build" >> ${GITHUB_ENV}
134134
135+
- name: format
136+
run: |
137+
find . -regex '.*\.\(cpp\|hpp\)' | xargs clang-format --dry-run --Werror
138+
135139
- name: build
136140
env:
137141
CMAKE_PREFIX_PATH: ${{ env.LIBZMQ }}

examples/multipart_messages.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,19 @@ int main()
77
zmq::socket_t sock1(ctx, zmq::socket_type::push);
88
zmq::socket_t sock2(ctx, zmq::socket_type::pull);
99
sock1.bind("tcp://127.0.0.1:*");
10-
const std::string last_endpoint =
11-
sock1.get(zmq::sockopt::last_endpoint);
12-
std::cout << "Connecting to "
13-
<< last_endpoint << std::endl;
10+
const std::string last_endpoint = sock1.get(zmq::sockopt::last_endpoint);
11+
std::cout << "Connecting to " << last_endpoint << std::endl;
1412
sock2.connect(last_endpoint);
1513

16-
std::array<zmq::const_buffer, 2> send_msgs = {
17-
zmq::str_buffer("foo"),
18-
zmq::str_buffer("bar!")
19-
};
14+
std::array<zmq::const_buffer, 2> send_msgs = {zmq::str_buffer("foo"),
15+
zmq::str_buffer("bar!")};
2016
if (!zmq::send_multipart(sock1, send_msgs))
2117
return 1;
2218

2319
std::vector<zmq::message_t> recv_msgs;
24-
const auto ret = zmq::recv_multipart(
25-
sock2, std::back_inserter(recv_msgs));
20+
const auto ret = zmq::recv_multipart(sock2, std::back_inserter(recv_msgs));
2621
if (!ret)
2722
return 1;
28-
std::cout << "Got " << *ret
29-
<< " messages" << std::endl;
23+
std::cout << "Got " << *ret << " messages" << std::endl;
3024
return 0;
3125
}

examples/pubsub_multithread_inproc.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
#include "zmq.hpp"
77
#include "zmq_addon.hpp"
88

9-
void PublisherThread(zmq::context_t *ctx) {
9+
void PublisherThread(zmq::context_t *ctx)
10+
{
1011
// Prepare publisher
1112
zmq::socket_t publisher(*ctx, zmq::socket_type::pub);
1213
publisher.bind("inproc://#1");
@@ -26,7 +27,8 @@ void PublisherThread(zmq::context_t *ctx) {
2627
}
2728
}
2829

29-
void SubscriberThread1(zmq::context_t *ctx) {
30+
void SubscriberThread1(zmq::context_t *ctx)
31+
{
3032
// Prepare subscriber
3133
zmq::socket_t subscriber(*ctx, zmq::socket_type::sub);
3234
subscriber.connect("inproc://#1");
@@ -48,7 +50,8 @@ void SubscriberThread1(zmq::context_t *ctx) {
4850
}
4951
}
5052

51-
void SubscriberThread2(zmq::context_t *ctx) {
53+
void SubscriberThread2(zmq::context_t *ctx)
54+
{
5255
// Prepare our context and subscriber
5356
zmq::socket_t subscriber(*ctx, zmq::socket_type::sub);
5457
subscriber.connect("inproc://#1");
@@ -69,7 +72,8 @@ void SubscriberThread2(zmq::context_t *ctx) {
6972
}
7073
}
7174

72-
int main() {
75+
int main()
76+
{
7377
/*
7478
* No I/O threads are involved in passing messages using the inproc transport.
7579
* Therefore, if you are using a ØMQ context for in-process messaging only you

tests/active_poller.cpp

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <cstring>
1010

1111
#if !defined(_WIN32)
12-
#include <unistd.h>
12+
#include <unistd.h>
1313
#endif // !_WIN32
1414

1515
TEST_CASE("create destroy", "[active_poller]")
@@ -95,18 +95,15 @@ TEST_CASE("add fd handler", "[active_poller]")
9595
{
9696
int fd = 1;
9797
zmq::active_poller_t active_poller;
98-
CHECK_NOTHROW(
99-
active_poller.add(fd, zmq::event_flags::pollin, no_op_handler));
98+
CHECK_NOTHROW(active_poller.add(fd, zmq::event_flags::pollin, no_op_handler));
10099
}
101100

102101
TEST_CASE("remove fd handler", "[active_poller]")
103102
{
104103
int fd = 1;
105104
zmq::active_poller_t active_poller;
106-
CHECK_NOTHROW(
107-
active_poller.add(fd, zmq::event_flags::pollin, no_op_handler));
108-
CHECK_NOTHROW(
109-
active_poller.remove(fd));
105+
CHECK_NOTHROW(active_poller.add(fd, zmq::event_flags::pollin, no_op_handler));
106+
CHECK_NOTHROW(active_poller.remove(fd));
110107
CHECK_THROWS_ZMQ_ERROR(EINVAL, active_poller.remove(100));
111108
}
112109

@@ -117,7 +114,7 @@ TEST_CASE("mixed socket and fd handlers", "[active_poller]")
117114
{
118115
int pipefd[2];
119116
::pipe(pipefd);
120-
117+
121118
zmq::context_t context;
122119
constexpr char inprocSocketAddress[] = "inproc://mixed-handlers";
123120
zmq::socket_t socket_rcv{context, zmq::socket_type::pair};
@@ -128,31 +125,29 @@ TEST_CASE("mixed socket and fd handlers", "[active_poller]")
128125
unsigned eventsFd = 0;
129126
unsigned eventsSocket = 0;
130127

131-
constexpr char messageText[] = "message";
132-
constexpr size_t messageSize = sizeof(messageText);
128+
constexpr char messageText[] = "message";
129+
constexpr size_t messageSize = sizeof(messageText);
133130

134131
zmq::active_poller_t active_poller;
135-
CHECK_NOTHROW(
136-
active_poller.add(pipefd[0], zmq::event_flags::pollin, [&](zmq::event_flags flags) {
137-
if (flags == zmq::event_flags::pollin)
138-
{
139-
char buffer[256];
140-
CHECK(messageSize == ::read(pipefd[0], buffer, messageSize));
141-
CHECK(0 == std::strcmp(buffer, messageText));
142-
++eventsFd;
143-
}
144-
}));
145-
CHECK_NOTHROW(
146-
active_poller.add(socket_rcv, zmq::event_flags::pollin, [&](zmq::event_flags flags) {
147-
if (flags == zmq::event_flags::pollin)
148-
{
149-
zmq::message_t msg;
150-
CHECK(socket_rcv.recv(msg, zmq::recv_flags::dontwait).has_value());
151-
CHECK(messageSize == msg.size());
152-
CHECK(0 == std::strcmp(messageText, msg.data<const char>()));
153-
++eventsSocket;
154-
}
155-
}));
132+
CHECK_NOTHROW(active_poller.add(
133+
pipefd[0], zmq::event_flags::pollin, [&](zmq::event_flags flags) {
134+
if (flags == zmq::event_flags::pollin) {
135+
char buffer[256];
136+
CHECK(messageSize == ::read(pipefd[0], buffer, messageSize));
137+
CHECK(0 == std::strcmp(buffer, messageText));
138+
++eventsFd;
139+
}
140+
}));
141+
CHECK_NOTHROW(active_poller.add(
142+
socket_rcv, zmq::event_flags::pollin, [&](zmq::event_flags flags) {
143+
if (flags == zmq::event_flags::pollin) {
144+
zmq::message_t msg;
145+
CHECK(socket_rcv.recv(msg, zmq::recv_flags::dontwait).has_value());
146+
CHECK(messageSize == msg.size());
147+
CHECK(0 == std::strcmp(messageText, msg.data<const char>()));
148+
++eventsSocket;
149+
}
150+
}));
156151

157152
// send/rcv socket pair
158153
zmq::message_t msg{messageText, messageSize};
@@ -369,8 +364,7 @@ TEST_CASE("modify invalid socket throws", "[active_poller]")
369364
zmq::socket_t a{context, zmq::socket_type::push};
370365
zmq::socket_t b{std::move(a)};
371366
zmq::active_poller_t active_poller;
372-
CHECK_THROWS_AS(active_poller.modify(a, zmq::event_flags::pollin),
373-
zmq::error_t);
367+
CHECK_THROWS_AS(active_poller.modify(a, zmq::event_flags::pollin), zmq::error_t);
374368
}
375369

376370
TEST_CASE("modify not added throws", "[active_poller]")
@@ -380,8 +374,7 @@ TEST_CASE("modify not added throws", "[active_poller]")
380374
zmq::socket_t b{context, zmq::socket_type::push};
381375
zmq::active_poller_t active_poller;
382376
CHECK_NOTHROW(active_poller.add(a, zmq::event_flags::pollin, no_op_handler));
383-
CHECK_THROWS_AS(active_poller.modify(b, zmq::event_flags::pollin),
384-
zmq::error_t);
377+
CHECK_THROWS_AS(active_poller.modify(b, zmq::event_flags::pollin), zmq::error_t);
385378
}
386379

387380
TEST_CASE("modify simple", "[active_poller]")

tests/buffer.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,21 +120,21 @@ TEST_CASE("mutable_buffer creation C array", "[buffer]")
120120
BT d[10] = {};
121121
zmq::mutable_buffer b = zmq::buffer(d);
122122
CHECK(b.size() == 10 * sizeof(BT));
123-
CHECK(b.data() == static_cast<BT*>(d));
123+
CHECK(b.data() == static_cast<BT *>(d));
124124
zmq::const_buffer b2 = zmq::buffer(d, 4);
125125
CHECK(b2.size() == 4);
126-
CHECK(b2.data() == static_cast<BT*>(d));
126+
CHECK(b2.data() == static_cast<BT *>(d));
127127
}
128128

129129
TEST_CASE("const_buffer creation C array", "[buffer]")
130130
{
131131
const BT d[10] = {};
132132
zmq::const_buffer b = zmq::buffer(d);
133133
CHECK(b.size() == 10 * sizeof(BT));
134-
CHECK(b.data() == static_cast<const BT*>(d));
134+
CHECK(b.data() == static_cast<const BT *>(d));
135135
zmq::const_buffer b2 = zmq::buffer(d, 4);
136136
CHECK(b2.size() == 4);
137-
CHECK(b2.data() == static_cast<const BT*>(d));
137+
CHECK(b2.data() == static_cast<const BT *>(d));
138138
}
139139

140140
TEST_CASE("mutable_buffer creation array", "[buffer]")
@@ -241,13 +241,13 @@ TEST_CASE("const_buffer creation with str_buffer", "[buffer]")
241241
const wchar_t wd[10] = {};
242242
zmq::const_buffer b = zmq::str_buffer(wd);
243243
CHECK(b.size() == 9 * sizeof(wchar_t));
244-
CHECK(b.data() == static_cast<const wchar_t*>(wd));
244+
CHECK(b.data() == static_cast<const wchar_t *>(wd));
245245

246246
zmq::const_buffer b2_null = zmq::buffer("hello");
247247
constexpr zmq::const_buffer b2 = zmq::str_buffer("hello");
248248
CHECK(b2_null.size() == 6);
249249
CHECK(b2.size() == 5);
250-
CHECK(std::string(static_cast<const char*>(b2.data()), b2.size()) == "hello");
250+
CHECK(std::string(static_cast<const char *>(b2.data()), b2.size()) == "hello");
251251
}
252252

253253
TEST_CASE("const_buffer creation with zbuf string literal char", "[buffer]")

tests/codec_multipart.cpp

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ TEST_CASE("multipart codec empty", "[codec_multipart]")
1010
multipart_t mmsg;
1111
message_t msg = mmsg.encode();
1212
CHECK(msg.size() == 0);
13-
13+
1414
multipart_t mmsg2;
1515
mmsg2.decode_append(msg);
1616
CHECK(mmsg2.size() == 0);
17-
1817
}
1918

2019
TEST_CASE("multipart codec small", "[codec_multipart]")
@@ -42,7 +41,7 @@ TEST_CASE("multipart codec big", "[codec_multipart]")
4241
{
4342
using namespace zmq;
4443

45-
message_t big(495); // large size packing
44+
message_t big(495); // large size packing
4645
big.data<char>()[0] = 'X';
4746

4847
multipart_t mmsg;
@@ -66,10 +65,8 @@ TEST_CASE("multipart codec decode bad data overflow", "[codec_multipart]")
6665
message_t wrong_size(bad_data, 3);
6766
CHECK(wrong_size.size() == 3);
6867
CHECK(wrong_size.data<char>()[0] == 5);
69-
70-
CHECK_THROWS_AS(
71-
multipart_t::decode(wrong_size),
72-
std::out_of_range);
68+
69+
CHECK_THROWS_AS(multipart_t::decode(wrong_size), std::out_of_range);
7370
}
7471

7572
TEST_CASE("multipart codec decode bad data extra data", "[codec_multipart]")
@@ -80,10 +77,8 @@ TEST_CASE("multipart codec decode bad data extra data", "[codec_multipart]")
8077
message_t wrong_size(bad_data, 3);
8178
CHECK(wrong_size.size() == 3);
8279
CHECK(wrong_size.data<char>()[0] == 1);
83-
84-
CHECK_THROWS_AS(
85-
multipart_t::decode(wrong_size),
86-
std::out_of_range);
80+
81+
CHECK_THROWS_AS(multipart_t::decode(wrong_size), std::out_of_range);
8782
}
8883

8984

@@ -110,14 +105,15 @@ TEST_CASE("multipart codec encode too big", "[codec_multipart]")
110105
}
111106
#endif
112107

113-
TEST_CASE("multipart codec free function with vector of message_t", "[codec_multipart]")
108+
TEST_CASE("multipart codec free function with vector of message_t",
109+
"[codec_multipart]")
114110
{
115111
using namespace zmq;
116112
std::vector<message_t> parts;
117113
parts.emplace_back("Hello", 5);
118-
parts.emplace_back("World",5);
114+
parts.emplace_back("World", 5);
119115
auto msg = encode(parts);
120-
CHECK(msg.size() == 1 + 5 + 1 + 5 );
116+
CHECK(msg.size() == 1 + 5 + 1 + 5);
121117
CHECK(msg.data<unsigned char>()[0] == 5);
122118
CHECK(msg.data<unsigned char>()[1] == 'H');
123119
CHECK(msg.data<unsigned char>()[6] == 5);
@@ -130,14 +126,15 @@ TEST_CASE("multipart codec free function with vector of message_t", "[codec_mult
130126
CHECK(parts[1].size() == 5);
131127
}
132128

133-
TEST_CASE("multipart codec free function with vector of const_buffer", "[codec_multipart]")
129+
TEST_CASE("multipart codec free function with vector of const_buffer",
130+
"[codec_multipart]")
134131
{
135132
using namespace zmq;
136133
std::vector<const_buffer> parts;
137134
parts.emplace_back("Hello", 5);
138-
parts.emplace_back("World",5);
135+
parts.emplace_back("World", 5);
139136
auto msg = encode(parts);
140-
CHECK(msg.size() == 1 + 5 + 1 + 5 );
137+
CHECK(msg.size() == 1 + 5 + 1 + 5);
141138
CHECK(msg.data<unsigned char>()[0] == 5);
142139
CHECK(msg.data<unsigned char>()[1] == 'H');
143140
CHECK(msg.data<unsigned char>()[6] == 5);
@@ -150,16 +147,17 @@ TEST_CASE("multipart codec free function with vector of const_buffer", "[codec_m
150147
CHECK(parts[1].size() == 5);
151148
}
152149

153-
TEST_CASE("multipart codec free function with vector of mutable_buffer", "[codec_multipart]")
150+
TEST_CASE("multipart codec free function with vector of mutable_buffer",
151+
"[codec_multipart]")
154152
{
155153
using namespace zmq;
156154
std::vector<mutable_buffer> parts;
157155
char hello[6] = "Hello";
158156
parts.emplace_back(hello, 5);
159157
char world[6] = "World";
160-
parts.emplace_back(world,5);
158+
parts.emplace_back(world, 5);
161159
auto msg = encode(parts);
162-
CHECK(msg.size() == 1 + 5 + 1 + 5 );
160+
CHECK(msg.size() == 1 + 5 + 1 + 5);
163161
CHECK(msg.data<unsigned char>()[0] == 5);
164162
CHECK(msg.data<unsigned char>()[1] == 'H');
165163
CHECK(msg.data<unsigned char>()[6] == 5);

tests/context.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,13 @@ TEST_CASE("context - use socket after shutdown", "[context]")
5151
zmq::context_t context;
5252
zmq::socket_t sock(context, zmq::socket_type::rep);
5353
context.shutdown();
54-
try
55-
{
54+
try {
5655
sock.connect("inproc://test");
5756
zmq::message_t msg;
58-
(void)sock.recv(msg, zmq::recv_flags::dontwait);
57+
(void) sock.recv(msg, zmq::recv_flags::dontwait);
5958
REQUIRE(false);
6059
}
61-
catch (const zmq::error_t& e)
62-
{
60+
catch (const zmq::error_t &e) {
6361
REQUIRE(e.num() == ETERM);
6462
}
6563
}
@@ -73,12 +71,8 @@ TEST_CASE("context set/get options", "[context]")
7371
CHECK(context.get(zmq::ctxopt::io_threads) == 5);
7472
#endif
7573

76-
CHECK_THROWS_AS(
77-
context.set(static_cast<zmq::ctxopt>(-42), 5),
78-
zmq::error_t);
74+
CHECK_THROWS_AS(context.set(static_cast<zmq::ctxopt>(-42), 5), zmq::error_t);
7975

80-
CHECK_THROWS_AS(
81-
context.get(static_cast<zmq::ctxopt>(-42)),
82-
zmq::error_t);
76+
CHECK_THROWS_AS(context.get(static_cast<zmq::ctxopt>(-42)), zmq::error_t);
8377
}
8478
#endif

0 commit comments

Comments
 (0)