From 39294a9fde0107f64c8dfb4e2c0b4e9df3e7bf6d Mon Sep 17 00:00:00 2001 From: "Matthew \"strager\" Glazar" Date: Tue, 7 Nov 2023 14:06:49 -0500 Subject: [PATCH] refactor(test): combine Monotonic_Allocator-s; simplify API 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. --- test/test-configuration-loader.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/test/test-configuration-loader.cpp b/test/test-configuration-loader.cpp index 0e6d136547..e3283e072c 100644 --- a/test/test-configuration-loader.cpp +++ b/test/test-configuration-loader.cpp @@ -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 lock(this->mutex_); #endif - return this->fs_.take_watch_errors(allocator); + return this->fs_.take_watch_errors(&this->allocator); } Span detect_changes_and_refresh(); @@ -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) { @@ -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 errors = loader.fs_take_watch_errors(&this->allocator); + Span 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(); @@ -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 errors = loader.fs_take_watch_errors(&this->allocator); + Span errors = loader.fs_take_watch_errors(); std::vector error_paths; for (Watch_IO_Error& error : errors) { EXPECT_EQ(error.io_error.error, ENOSPC) << error.to_string(); @@ -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 errors = loader.fs_take_watch_errors(&this->allocator); + Span errors = loader.fs_take_watch_errors(); std::vector error_paths; for (Watch_IO_Error& error : errors) { EXPECT_EQ(error.io_error.error, EMFILE) << error.to_string(); @@ -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 errors = loader.fs_take_watch_errors(&this->allocator); + Span errors = loader.fs_take_watch_errors(); std::vector error_paths; for (Watch_IO_Error& error : errors) { EXPECT_EQ(error.io_error.error, mock_error) << error.to_string();