Skip to content

Commit 5b1a0fa

Browse files
authored
Replace boost testing framework with doctest (#7)
* Add doctest 2.4.11 * Switch from boost to doctest
1 parent fda73b5 commit 5b1a0fa

File tree

7 files changed

+7197
-92
lines changed

7 files changed

+7197
-92
lines changed

test/unit/CMakeLists.txt

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,32 @@
11
project(InotifyUnitTest)
22

33
find_package(Threads REQUIRED)
4-
find_package(Boost REQUIRED COMPONENTS system unit_test_framework)
5-
6-
if (NOT DEFINED Boost_INCLUDE_DIRS OR NOT Boost_LIBRARIES)
7-
message(FATAL_ERROR "Missing boost feature")
8-
endif()
94

105
add_executable(event_handler_unit_test main.cpp event_handler_test.cpp)
116
target_link_libraries(
127
event_handler_unit_test
13-
PUBLIC notify-cpp-shared stdc++fs Threads::Threads ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
8+
PUBLIC notify-cpp-shared stdc++fs Threads::Threads ${CMAKE_THREAD_LIBS_INIT}
149
)
10+
target_compile_definitions(event_handler_unit_test PRIVATE DOCTEST_CONFIG_DOUBLE_STRINGIFY=1)
1511
target_include_directories(event_handler_unit_test PUBLIC
1612
"${CMAKE_CURRENT_SOURCE_DIR}/../../include/"
1713
"${Boost_INCLUDE_DIRS}")
1814

1915
add_executable(inotify_unit_test main.cpp inotify_controller_test.cpp)
2016
target_link_libraries(
2117
inotify_unit_test
22-
PUBLIC notify-cpp-shared stdc++fs Threads::Threads ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
18+
PUBLIC notify-cpp-shared stdc++fs Threads::Threads ${CMAKE_THREAD_LIBS_INIT}
2319
)
20+
target_compile_definitions(inotify_unit_test PRIVATE DOCTEST_CONFIG_DOUBLE_STRINGIFY=1)
2421
target_include_directories(inotify_unit_test PUBLIC
25-
"${CMAKE_CURRENT_SOURCE_DIR}/../../include/"
26-
"${Boost_INCLUDE_DIRS}")
22+
"${CMAKE_CURRENT_SOURCE_DIR}/../../include/")
2723

2824
add_executable(fanotify_unit_test main.cpp fanotify_controller_test.cpp)
2925
target_link_libraries(
3026
fanotify_unit_test
31-
PUBLIC notify-cpp-shared stdc++fs Threads::Threads ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
27+
PUBLIC notify-cpp-shared stdc++fs Threads::Threads ${CMAKE_THREAD_LIBS_INIT}
3228
)
29+
target_compile_definitions(fanotify_unit_test PRIVATE DOCTEST_CONFIG_DOUBLE_STRINGIFY=1)
3330
target_include_directories(fanotify_unit_test PUBLIC
3431
"${CMAKE_CURRENT_SOURCE_DIR}/../../include/"
3532
"${Boost_INCLUDE_DIRS}")

test/unit/doctest.h

Lines changed: 7106 additions & 0 deletions
Large diffs are not rendered by default.

test/unit/event_handler_test.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,26 @@
2121
*/
2222
#include <notify-cpp/event.h>
2323

24-
#include <boost/test/unit_test.hpp>
24+
#include "doctest.h"
2525

2626
using namespace notifycpp;
2727

28-
BOOST_AUTO_TEST_CASE(EventOperatorTest)
28+
TEST_CASE("EventOperatorTest")
2929
{
30-
BOOST_CHECK_EQUAL((Event::all & Event::close_write), Event::close_write);
31-
BOOST_CHECK_EQUAL((Event::close & Event::close_write), Event::close_write);
32-
BOOST_CHECK_EQUAL((Event::all & Event::close), Event::close);
33-
BOOST_CHECK_EQUAL((Event::all & Event::access | Event::modify), Event::access | Event::modify);
34-
BOOST_CHECK_EQUAL((Event::all & Event::moved_from), Event::moved_from);
35-
BOOST_CHECK_EQUAL((Event::move & Event::moved_from), Event::moved_from);
36-
BOOST_CHECK(!((Event::move & Event::open) == Event::open));
30+
CHECK_EQ((Event::all & Event::close_write), Event::close_write);
31+
CHECK_EQ((Event::close & Event::close_write), Event::close_write);
32+
CHECK_EQ((Event::all & Event::close), Event::close);
33+
CHECK_EQ((Event::all & Event::access | Event::modify), Event::access | Event::modify);
34+
CHECK_EQ((Event::all & Event::moved_from), Event::moved_from);
35+
CHECK_EQ((Event::move & Event::moved_from), Event::moved_from);
36+
CHECK_FALSE((Event::move & Event::open) == Event::open);
3737
}
3838

39-
BOOST_AUTO_TEST_CASE(EventToStringTest)
39+
TEST_CASE("EventToStringTest")
4040
{
41-
BOOST_CHECK_EQUAL(toString(Event::all), std::string("access,modify,attrib,close_write,close_nowrite,open,moved_from,moved_to,create,delete,delete_self,move_self,close,move,all"));
41+
CHECK_EQ(toString(Event::all), std::string("access,modify,attrib,close_write,close_nowrite,open,moved_from,moved_to,create,delete,delete_self,move_self,close,move,all"));
4242

43-
BOOST_CHECK_EQUAL(toString(Event::access), std::string("access"));
44-
BOOST_CHECK_EQUAL(toString(Event::access | Event::close_nowrite), std::string("access,close_nowrite"));
45-
BOOST_CHECK_EQUAL(toString(Event::close_nowrite| Event::access), std::string("access,close_nowrite"));
43+
CHECK_EQ(toString(Event::access), std::string("access"));
44+
CHECK_EQ(toString(Event::access | Event::close_nowrite), std::string("access,close_nowrite"));
45+
CHECK_EQ(toString(Event::close_nowrite| Event::access), std::string("access,close_nowrite"));
4646
}

test/unit/fanotify_controller_test.cpp

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
* SOFTWARE.
2121
*/
2222
#include <notify-cpp/fanotify.h>
23+
#include <notify-cpp/event.h>
2324
#include <notify-cpp/notify_controller.h>
2425

2526
#include "filesystem_event_helper.hpp"
2627

27-
#include <boost/test/unit_test.hpp>
28+
#include "doctest.h"
2829

30+
#include <thread>
2931
#include <chrono>
3032
#include <filesystem>
3133
#include <fstream>
@@ -35,7 +37,7 @@
3537
using namespace notifycpp;
3638

3739

38-
BOOST_FIXTURE_TEST_CASE(shouldNotifyOnMultipleEvents, FilesystemEventHelper)
40+
TEST_CASE_FIXTURE(FilesystemEventHelper, "shouldNotifyOnMultipleEvents")
3941
{
4042
FanotifyController notifier = FanotifyController();
4143

@@ -63,29 +65,29 @@ BOOST_FIXTURE_TEST_CASE(shouldNotifyOnMultipleEvents, FilesystemEventHelper)
6365

6466
auto futureOpen = promisedOpen_.get_future();
6567
auto futureCloseNoWrite = promisedCloseNoWrite_.get_future();
66-
BOOST_CHECK(futureOpen.wait_for(timeout_) == std::future_status::ready);
67-
BOOST_CHECK(futureOpen.get().getEvent() == Event::open);
68-
BOOST_CHECK(futureCloseNoWrite.wait_for(timeout_) == std::future_status::ready);
69-
BOOST_CHECK(futureCloseNoWrite.get().getEvent() == Event::close_write);
68+
CHECK(futureOpen.wait_for(timeout_) == std::future_status::ready);
69+
CHECK_EQ(futureOpen.get().getEvent(), Event::open);
70+
CHECK(futureCloseNoWrite.wait_for(timeout_) == std::future_status::ready);
71+
CHECK(futureCloseNoWrite.get().getEvent() == Event::close_write);
7072
thread.join();
7173
}
7274

73-
BOOST_AUTO_TEST_CASE(EventOperatorTest)
75+
TEST_CASE("EventOperatorTest")
7476
{
75-
BOOST_CHECK((Event::all & Event::close_write) == Event::close_write);
76-
BOOST_CHECK((Event::all & Event::moved_from) == Event::moved_from);
77-
BOOST_CHECK((Event::move & Event::moved_from) == Event::moved_from);
78-
BOOST_CHECK(!((Event::move & Event::open) == Event::open));
79-
BOOST_CHECK(toString(Event::access) == std::string("access"));
77+
CHECK_EQ((Event::all & Event::close_write), Event::close_write);
78+
CHECK_EQ((Event::all & Event::moved_from), Event::moved_from);
79+
CHECK_EQ((Event::move & Event::moved_from), Event::moved_from);
80+
CHECK(!((Event::move & Event::open) != Event::open));
81+
CHECK_EQ(toString(Event::access), std::string("access"));
8082
}
8183

82-
BOOST_FIXTURE_TEST_CASE(shouldNotAcceptNotExistingPaths, FilesystemEventHelper)
84+
TEST_CASE_FIXTURE(FilesystemEventHelper, "shouldNotAcceptNotExistingPaths")
8385
{
84-
BOOST_CHECK_THROW(FanotifyController().watchPathRecursively(std::filesystem::path("/not/existing/path/")), std::invalid_argument);
85-
BOOST_CHECK_THROW(FanotifyController().watchFile(std::filesystem::path("/not/existing/file")), std::invalid_argument);
86+
CHECK_THROWS_AS(FanotifyController().watchPathRecursively(std::filesystem::path("/not/existing/path/")), std::invalid_argument);
87+
CHECK_THROWS_AS(FanotifyController().watchFile(std::filesystem::path("/not/existing/file")), std::invalid_argument);
8688
}
8789

88-
BOOST_FIXTURE_TEST_CASE(shouldNotifyOnOpenEvent, FilesystemEventHelper)
90+
TEST_CASE_FIXTURE(FilesystemEventHelper, "shouldNotifyOnOpenEvent")
8991
{
9092
NotifyController notifier = FanotifyController().watchFile({testFileOne_, Event::close}).onEvent(Event::close, [&](Notification notification) {
9193
promisedOpen_.set_value(notification);
@@ -96,16 +98,16 @@ BOOST_FIXTURE_TEST_CASE(shouldNotifyOnOpenEvent, FilesystemEventHelper)
9698
openFile(testFileOne_);
9799

98100
auto futureOpenEvent = promisedOpen_.get_future();
99-
BOOST_CHECK(futureOpenEvent.wait_for(timeout_) == std::future_status::ready);
101+
CHECK(futureOpenEvent.wait_for(timeout_) == std::future_status::ready);
100102
const auto notify = futureOpenEvent.get();
101-
BOOST_CHECK_EQUAL(notify.getEvent(), Event::close);
103+
CHECK_EQ(notify.getEvent(), Event::close);
102104
auto fullpath = std::filesystem::current_path();
103105
fullpath /= testFileOne_;
104-
BOOST_CHECK_EQUAL(notify.getPath(), fullpath);
106+
CHECK_EQ(notify.getPath(), fullpath);
105107
thread.join();
106108
}
107109

108-
BOOST_FIXTURE_TEST_CASE(shouldStopRunOnce, FilesystemEventHelper)
110+
TEST_CASE_FIXTURE(FilesystemEventHelper, "shouldStopRunOnce")
109111
{
110112
NotifyController notifier = FanotifyController().watchFile(testFileOne_);
111113

@@ -116,7 +118,7 @@ BOOST_FIXTURE_TEST_CASE(shouldStopRunOnce, FilesystemEventHelper)
116118
thread.join();
117119
}
118120

119-
BOOST_FIXTURE_TEST_CASE(shouldStopRun, FilesystemEventHelper)
121+
TEST_CASE_FIXTURE(FilesystemEventHelper, "shouldStopRun")
120122
{
121123
FanotifyController notifier = FanotifyController();
122124
notifier.watchFile(testFileOne_);
@@ -128,7 +130,7 @@ BOOST_FIXTURE_TEST_CASE(shouldStopRun, FilesystemEventHelper)
128130
thread.join();
129131
}
130132

131-
BOOST_FIXTURE_TEST_CASE(shouldIgnoreFile, FilesystemEventHelper)
133+
TEST_CASE_FIXTURE(FilesystemEventHelper, "shouldIgnoreFile")
132134
{
133135
NotifyController notifier = FanotifyController().ignore(testFileOne_).watchFile({testFileOne_, Event::close}).onEvent(Event::close, [&](Notification notification) {
134136
promisedOpen_.set_value(notification);
@@ -139,12 +141,12 @@ BOOST_FIXTURE_TEST_CASE(shouldIgnoreFile, FilesystemEventHelper)
139141
openFile(testFileOne_);
140142

141143
auto futureOpenEvent = promisedOpen_.get_future();
142-
BOOST_CHECK(futureOpenEvent.wait_for(timeout_) == std::future_status::timeout);
144+
CHECK(futureOpenEvent.wait_for(timeout_) == std::future_status::timeout);
143145
notifier.stop();
144146
thread.join();
145147
}
146148

147-
BOOST_FIXTURE_TEST_CASE(shouldUnwatchPath, FilesystemEventHelper)
149+
TEST_CASE_FIXTURE(FilesystemEventHelper, "shouldUnwatchPath")
148150
{
149151
std::promise<Notification> timeoutObserved;
150152
std::chrono::milliseconds timeout(100);
@@ -155,12 +157,12 @@ BOOST_FIXTURE_TEST_CASE(shouldUnwatchPath, FilesystemEventHelper)
155157
std::thread thread([&notifier]() { notifier.runOnce(); });
156158

157159
openFile(testFileOne_);
158-
BOOST_CHECK(promisedOpen_.get_future().wait_for(timeout_) != std::future_status::ready);
160+
CHECK(promisedOpen_.get_future().wait_for(timeout_) != std::future_status::ready);
159161
notifier.stop();
160162
thread.join();
161163
}
162164

163-
BOOST_FIXTURE_TEST_CASE(shouldCallUserDefinedUnexpectedExceptionObserver, FilesystemEventHelper)
165+
TEST_CASE_FIXTURE(FilesystemEventHelper, "shouldCallUserDefinedUnexpectedExceptionObserver")
164166
{
165167
std::promise<void> observerCalled;
166168

@@ -173,11 +175,11 @@ BOOST_FIXTURE_TEST_CASE(shouldCallUserDefinedUnexpectedExceptionObserver, Filesy
173175

174176
openFile(testFileOne_);
175177

176-
BOOST_CHECK(observerCalled.get_future().wait_for(timeout_) == std::future_status::ready);
178+
CHECK(observerCalled.get_future().wait_for(timeout_) == std::future_status::ready);
177179
thread.join();
178180
}
179181

180-
BOOST_FIXTURE_TEST_CASE(shouldWatchPathRecursively, FilesystemEventHelper)
182+
TEST_CASE_FIXTURE(FilesystemEventHelper, "shouldWatchPathRecursively")
181183
{
182184
FanotifyController notifier = FanotifyController();
183185
notifier.watchPathRecursively(testDirectory_)
@@ -195,13 +197,13 @@ BOOST_FIXTURE_TEST_CASE(shouldWatchPathRecursively, FilesystemEventHelper)
195197
openFile(testFileOne_);
196198

197199
auto futureOpen = promisedOpen_.get_future();
198-
BOOST_CHECK(futureOpen.wait_for(timeout_) == std::future_status::ready);
200+
CHECK(futureOpen.wait_for(timeout_) == std::future_status::ready);
199201

200202
notifier.stop();
201203
thread.join();
202204
}
203205

204-
BOOST_FIXTURE_TEST_CASE(shouldIgnoreFileOnce, FilesystemEventHelper)
206+
TEST_CASE_FIXTURE(FilesystemEventHelper, "shouldIgnoreFileOnce")
205207
{
206208
size_t counter = 0;
207209
FanotifyController notifier = FanotifyController();
@@ -220,7 +222,7 @@ BOOST_FIXTURE_TEST_CASE(shouldIgnoreFileOnce, FilesystemEventHelper)
220222
openFile(testFileOne_);
221223

222224
auto futureOpen = _promisedCounter.get_future();
223-
BOOST_CHECK(futureOpen.wait_for(std::chrono::seconds(1)) == std::future_status::ready);
225+
CHECK(futureOpen.wait_for(std::chrono::seconds(1)) == std::future_status::ready);
224226
notifier.stop();
225227
thread.join();
226228
}

test/unit/filesystem_event_helper.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
#include <notify-cpp/notify_controller.h>
2525

26-
#include <boost/test/unit_test.hpp>
26+
#include "doctest.h"
2727

2828
#include <chrono>
2929
#include <filesystem>
@@ -36,7 +36,7 @@ void openFile(const std::filesystem::path& file)
3636
{
3737
std::ofstream stream;
3838
stream.open(file.string(), std::ifstream::out);
39-
BOOST_CHECK(stream.is_open());
39+
CHECK(stream.is_open());
4040
stream << "Writing this to a file.\n";
4141
stream.close();
4242
}

0 commit comments

Comments
 (0)