Skip to content

Commit c7e65a1

Browse files
committed
adjust test cases
1 parent c4cbc66 commit c7e65a1

File tree

1 file changed

+8
-31
lines changed

1 file changed

+8
-31
lines changed

tests/filewatcher/test_filewatcher.cpp

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <fstream>
55
#include <gtest/gtest.h>
66
#include <ios>
7+
#include <stdexcept>
78
#include <thread>
89

910
// Platform-specific headers for directory operations
@@ -123,22 +124,16 @@ TEST_F(FileWatcherTest, FileReplacedMultipleTimesCallbackCalled) {
123124
EXPECT_GE(callbackCount, 10); // Ensure callback was called at least once
124125
}
125126

126-
// Test creating a file after starting to watch it
127-
TEST_F(FileWatcherTest, FileCreatedAfterWatchingCallbackCalled) {
127+
// Test watching a non-existent file fails fast
128+
TEST_F(FileWatcherTest, WatchingMissingFileThrows) {
128129
bool callbackCalled = false;
129130
auto callback = [&callbackCalled]() { callbackCalled = true; };
130131

131-
// Start watching before file exists
132-
auto watcher = filewatcher_factory::createFileWatcher();
133-
watcher->startWatching(testFilePath, callback);
134-
std::this_thread::sleep_for(std::chrono::milliseconds(THREAD_WAIT_TIME_MS));
135-
136-
// Now create the file
137-
createFile(testFilePath, "Initial content");
138-
std::this_thread::sleep_for(std::chrono::milliseconds(THREAD_WAIT_TIME_MS));
139-
watcher->stopWatching();
132+
std::remove(testFilePath.c_str());
140133

141-
EXPECT_TRUE(callbackCalled);
134+
auto watcher = filewatcher_factory::createFileWatcher();
135+
EXPECT_THROW(watcher->startWatching(testFilePath, callback),
136+
std::runtime_error);
142137
}
143138

144139
// Test stopping watcher multiple times is safe (idempotent)
@@ -219,25 +214,7 @@ TEST_F(FileWatcherTest, FileInSubdirectoryWatched) {
219214
EXPECT_TRUE(callbackCalled);
220215
}
221216

222-
// Test file creation specifically (not modification or replacement)
223-
TEST_F(FileWatcherTest, NewFileCreationCallbackCalled) {
224-
bool callbackCalled = false;
225-
auto callback = [&callbackCalled]() { callbackCalled = true; };
226-
227-
// Ensure file doesn't exist
228-
std::remove(testFilePath.c_str());
229-
230-
auto watcher = filewatcher_factory::createFileWatcher();
231-
watcher->startWatching(testFilePath, callback);
232-
std::this_thread::sleep_for(std::chrono::milliseconds(THREAD_WAIT_TIME_MS));
233-
234-
// Create new file (not modifying existing)
235-
createFile(testFilePath, "Brand new file");
236-
std::this_thread::sleep_for(std::chrono::milliseconds(THREAD_WAIT_TIME_MS));
237-
watcher->stopWatching();
238-
239-
EXPECT_TRUE(callbackCalled);
240-
}
217+
241218

242219
// Test multiple separate modifications with proper spacing
243220
TEST_F(FileWatcherTest, MultipleModificationsWithSpacing) {

0 commit comments

Comments
 (0)