From 3e09d7c065b5dcce6cec629897f026b348f11a8f Mon Sep 17 00:00:00 2001 From: Vladislav Nepogodin Date: Fri, 9 Aug 2024 15:12:19 +0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20gucc:=20replace=20all=20ofstream?= =?UTF-8?q?=20with=20helper=20function=20in=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gucc/tests/unit-initcpio.cpp | 1 - gucc/tests/unit-locale.cpp | 1 - gucc/tests/unit-mtab.cpp | 18 +++--------------- gucc/tests/unit-package_profiles.cpp | 1 - gucc/tests/unit-pacmanconf.cpp | 1 - gucc/tests/unit-refind_extra_kern_strings.cpp | 1 - 6 files changed, 3 insertions(+), 20 deletions(-) diff --git a/gucc/tests/unit-initcpio.cpp b/gucc/tests/unit-initcpio.cpp index 35cbff6..e4515bd 100644 --- a/gucc/tests/unit-initcpio.cpp +++ b/gucc/tests/unit-initcpio.cpp @@ -5,7 +5,6 @@ #include "gucc/logger.hpp" #include -#include #include #include #include diff --git a/gucc/tests/unit-locale.cpp b/gucc/tests/unit-locale.cpp index 642c158..2399a33 100644 --- a/gucc/tests/unit-locale.cpp +++ b/gucc/tests/unit-locale.cpp @@ -5,7 +5,6 @@ #include "gucc/logger.hpp" #include -#include #include #include diff --git a/gucc/tests/unit-mtab.cpp b/gucc/tests/unit-mtab.cpp index 1d1bc93..13d89e1 100644 --- a/gucc/tests/unit-mtab.cpp +++ b/gucc/tests/unit-mtab.cpp @@ -1,9 +1,9 @@ #include "doctest_compatibility.h" +#include "gucc/file_utils.hpp" #include "gucc/mtab.hpp" #include -#include #include #include @@ -121,13 +121,7 @@ TEST_CASE("mtab test") SECTION("live iso system") { static constexpr std::string_view filename{"/tmp/mtab.conf"}; - // Open mtab file for writing. - std::ofstream mtab_file{filename.data()}; - REQUIRE(mtab_file.is_open()); - - // Setup mtab file. - mtab_file << MTAB_LIVE_ISO_TEST; - mtab_file.close(); + REQUIRE(file_utils::create_file_for_overwrite(filename, MTAB_LIVE_ISO_TEST)); const auto& mtab_entries = gucc::mtab::parse_mtab("/tmp/calamares-root-q_z5rdlx"sv, filename); REQUIRE(mtab_entries.has_value()); @@ -170,13 +164,7 @@ TEST_CASE("mtab test") SECTION("empty file") { static constexpr std::string_view filename{"/tmp/mtab.conf"}; - // Open mtab file for writing. - std::ofstream mtab_file{filename.data()}; - REQUIRE(mtab_file.is_open()); - - // Setup mtab file. - mtab_file << ""; - mtab_file.close(); + REQUIRE(file_utils::create_file_for_overwrite(filename, "")); const auto& mtab_entries = gucc::mtab::parse_mtab("/tmp/calamares-root-q_z5rdlx"sv, filename); REQUIRE(!mtab_entries.has_value()); diff --git a/gucc/tests/unit-package_profiles.cpp b/gucc/tests/unit-package_profiles.cpp index 591d560..4d7e008 100644 --- a/gucc/tests/unit-package_profiles.cpp +++ b/gucc/tests/unit-package_profiles.cpp @@ -5,7 +5,6 @@ #include "gucc/package_profiles.hpp" #include -#include #include #include diff --git a/gucc/tests/unit-pacmanconf.cpp b/gucc/tests/unit-pacmanconf.cpp index 26ad6f5..af943f0 100644 --- a/gucc/tests/unit-pacmanconf.cpp +++ b/gucc/tests/unit-pacmanconf.cpp @@ -4,7 +4,6 @@ #include "gucc/pacmanconf_repo.hpp" #include -#include #include #include #include diff --git a/gucc/tests/unit-refind_extra_kern_strings.cpp b/gucc/tests/unit-refind_extra_kern_strings.cpp index ff57ced..390210b 100644 --- a/gucc/tests/unit-refind_extra_kern_strings.cpp +++ b/gucc/tests/unit-refind_extra_kern_strings.cpp @@ -5,7 +5,6 @@ #include "gucc/logger.hpp" #include -#include #include #include