From 37cbab363eb8fd967f8952894db86d02fb018972 Mon Sep 17 00:00:00 2001 From: gabime Date: Fri, 10 Dec 2021 00:28:25 +0200 Subject: [PATCH] updated file_event_handlers tests --- tests/test_file_helper.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/test_file_helper.cpp b/tests/test_file_helper.cpp index b4791b03..861f6210 100644 --- a/tests/test_file_helper.cpp +++ b/tests/test_file_helper.cpp @@ -121,11 +121,14 @@ TEST_CASE("file_event_handlers", "[file_helper]") handlers.after_open = [&](spdlog::filename_t filename, std::FILE *fstream) { REQUIRE(filename == TEST_FILENAME); REQUIRE(fstream); + fputs("after_open\n", fstream); events.push_back(flags::after_open); }; handlers.before_close = [&](spdlog::filename_t filename, std::FILE *fstream) { REQUIRE(filename == TEST_FILENAME); REQUIRE(fstream); + fputs("before_close\n", fstream); + fflush(fstream); events.push_back(flags::before_close); }; handlers.after_close = [&](spdlog::filename_t filename) { @@ -138,19 +141,17 @@ TEST_CASE("file_event_handlers", "[file_helper]") helper.open(TEST_FILENAME); REQUIRE(events == std::vector{flags::before_open, flags::after_open}); - - events.clear(); - helper.reopen(true); - REQUIRE(events == std::vector{flags::before_close, flags::after_close, flags::before_open, flags::after_open}); - + events.clear(); helper.close(); REQUIRE(events == std::vector{flags::before_close, flags::after_close}); + REQUIRE(file_contents(TEST_FILENAME) == "after_open\nbefore_close\n"); helper.reopen(true); events.clear(); } // make sure that the file_helper destrcutor calls the close callbacks if needed REQUIRE(events == std::vector{flags::before_close, flags::after_close}); + REQUIRE(file_contents(TEST_FILENAME) == "after_open\nbefore_close\n"); }