Skip to content

Commit

Permalink
refactor(test): combine Monotonic_Allocator-s; simplify API
Browse files Browse the repository at this point in the history
Make fs_take_watch_errors() use
Change_Detecting_Configuration_Loader::allocator instead of
Test_Configuration_Loader::allocator, removing the need for either a
parameter or Test_Configuration_Loader::allocator.
  • Loading branch information
strager committed Nov 7, 2023
1 parent 498e59d commit d9fbd5b
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions test/test-configuration-loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ class Change_Detecting_Configuration_Loader {
return this->loader_.unwatch_all_files();
}

auto fs_take_watch_errors(Monotonic_Allocator* allocator) {
auto fs_take_watch_errors() {
#if defined(_WIN32)
std::lock_guard<Mutex> lock(this->mutex_);
#endif
return this->fs_.take_watch_errors(allocator);
return this->fs_.take_watch_errors(&this->allocator);
}

Span<Configuration_Change> detect_changes_and_refresh();
Expand Down Expand Up @@ -191,10 +191,7 @@ class Change_Detecting_Configuration_Loader {
};

class Test_Configuration_Loader : public ::testing::Test,
protected Filesystem_Test {
public:
Monotonic_Allocator allocator{"Test_Configuration_Loader"};
};
protected Filesystem_Test {};

TEST_F(Test_Configuration_Loader,
file_with_no_config_file_gets_default_config) {
Expand Down Expand Up @@ -2056,7 +2053,7 @@ TEST_F(Test_Configuration_Loader,
loader.watch_and_load_config_file(config_file, /*token=*/nullptr);
EXPECT_TRUE(loaded_config.ok()) << loaded_config.error_to_string();

Span<Watch_IO_Error> errors = loader.fs_take_watch_errors(&this->allocator);
Span<Watch_IO_Error> errors = loader.fs_take_watch_errors();
ASSERT_THAT(errors, ElementsAreArray({::testing::_}));
const Watch_IO_Error& error = errors[0];
EXPECT_EQ(error.io_error.error, EMFILE) << error.to_string();
Expand All @@ -2078,7 +2075,7 @@ TEST_F(Test_Configuration_Loader,
loader.watch_and_load_config_file(config_file, /*token=*/nullptr);
EXPECT_TRUE(loaded_config.ok()) << loaded_config.error_to_string();

Span<Watch_IO_Error> errors = loader.fs_take_watch_errors(&this->allocator);
Span<Watch_IO_Error> errors = loader.fs_take_watch_errors();
std::vector<std::string> error_paths;
for (Watch_IO_Error& error : errors) {
EXPECT_EQ(error.io_error.error, ENOSPC) << error.to_string();
Expand Down Expand Up @@ -2107,7 +2104,7 @@ TEST_F(Test_Configuration_Loader,
loader.watch_and_load_config_file(config_file, /*token=*/nullptr);
EXPECT_TRUE(loaded_config.ok()) << loaded_config.error_to_string();

Span<Watch_IO_Error> errors = loader.fs_take_watch_errors(&this->allocator);
Span<Watch_IO_Error> errors = loader.fs_take_watch_errors();
std::vector<std::string> error_paths;
for (Watch_IO_Error& error : errors) {
EXPECT_EQ(error.io_error.error, EMFILE) << error.to_string();
Expand Down Expand Up @@ -2148,7 +2145,7 @@ TEST_F(Test_Configuration_Loader,
loader.watch_and_load_config_file(config_file, /*token=*/nullptr);
EXPECT_TRUE(loaded_config.ok()) << loaded_config.error_to_string();

Span<Watch_IO_Error> errors = loader.fs_take_watch_errors(&this->allocator);
Span<Watch_IO_Error> errors = loader.fs_take_watch_errors();
std::vector<std::string> error_paths;
for (Watch_IO_Error& error : errors) {
EXPECT_EQ(error.io_error.error, mock_error) << error.to_string();
Expand Down

0 comments on commit d9fbd5b

Please sign in to comment.