diff --git a/tests/file_helper.cpp b/tests/file_helper.cpp index 37dc0f6f..f82e6758 100644 --- a/tests/file_helper.cpp +++ b/tests/file_helper.cpp @@ -7,15 +7,6 @@ using namespace spdlog::details; static const std::string filename = "logs/file_helper_test.txt"; -size_t filesize2(const std::string& filename) -{ - std::ifstream ifs(filename, std::ifstream::ate | std::ifstream::binary); - if (!ifs) - throw std::runtime_error("Failed open file "); - - return (size_t)ifs.tellg(); -} - static void write_with_helper(file_helper &helper, size_t howmany) { log_msg msg; @@ -45,7 +36,7 @@ TEST_CASE("file_helper_size", "[file_helper::size()]]") write_with_helper(helper, expected_size); REQUIRE(helper.size() == expected_size); } - REQUIRE(filesize2(filename) == expected_size); + REQUIRE(filesize(filename) == expected_size); } diff --git a/tests/file_log.cpp b/tests/file_log.cpp index 40e967cd..e728a963 100644 --- a/tests/file_log.cpp +++ b/tests/file_log.cpp @@ -3,39 +3,6 @@ */ #include "includes.h" -static std::string file_contents(const std::string& filename) -{ - std::ifstream ifs(filename); - if (!ifs) - throw std::runtime_error("Failed open file "); - return std::string((std::istreambuf_iterator(ifs)), - (std::istreambuf_iterator())); - -} - -static std::size_t count_lines(const std::string& filename) -{ - std::ifstream ifs(filename); - if (!ifs) - throw std::runtime_error("Failed open file "); - - std::string line; - size_t counter = 0; - while(std::getline(ifs, line)) - counter++; - return counter; -} - -std::ifstream::pos_type filesize(const std::string& filename) -{ - std::ifstream ifs(filename, std::ifstream::ate | std::ifstream::binary); - if (!ifs) - throw std::runtime_error("Failed open file "); - - return ifs.tellg(); -} - - TEST_CASE("simple_file_logger", "[simple_logger]]") { diff --git a/tests/utils.cpp b/tests/utils.cpp index 5ae8ea8f..ef6018b6 100644 --- a/tests/utils.cpp +++ b/tests/utils.cpp @@ -9,3 +9,37 @@ void prepare_logdir() auto rv = system("rm -f logs/*"); #endif } + + +std::string file_contents(const std::string& filename) +{ + std::ifstream ifs(filename); + if (!ifs) + throw std::runtime_error("Failed open file "); + return std::string((std::istreambuf_iterator(ifs)), + (std::istreambuf_iterator())); + +} + +std::size_t count_lines(const std::string& filename) +{ + std::ifstream ifs(filename); + if (!ifs) + throw std::runtime_error("Failed open file "); + + std::string line; + size_t counter = 0; + while(std::getline(ifs, line)) + counter++; + return counter; +} + +std::ifstream::pos_type filesize(const std::string& filename) +{ + std::ifstream ifs(filename, std::ifstream::ate | std::ifstream::binary); + if (!ifs) + throw std::runtime_error("Failed open file "); + + return ifs.tellg(); +} + diff --git a/tests/utils.h b/tests/utils.h index 6701d6e7..eea5d6c5 100644 --- a/tests/utils.h +++ b/tests/utils.h @@ -1,4 +1,15 @@ #pragma once +#include +#include + +std::size_t count_lines(const std::string& filename); + void prepare_logdir(); +std::string file_contents(const std::string& filename); + +std::size_t count_lines(const std::string& filename); + +std::ifstream::pos_type filesize(const std::string& filename); +