Skip to content

Commit

Permalink
👷 gucc: improve test coverage for locale
Browse files Browse the repository at this point in the history
  • Loading branch information
vnepogodin committed Jul 5, 2024
1 parent f8fdeb2 commit 4b35d00
Show file tree
Hide file tree
Showing 6 changed files with 637 additions and 2 deletions.
4 changes: 4 additions & 0 deletions gucc/include/gucc/locale.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ namespace gucc::locale {
// Set system language
auto set_locale(std::string_view locale, std::string_view mountpoint) noexcept -> bool;

// Prepare system language.
// Sets without updating system locale
auto prepare_locale_set(std::string_view locale, std::string_view mountpoint) noexcept -> bool;

} // namespace gucc::locale

#endif // LOCALE_HPP
14 changes: 12 additions & 2 deletions gucc/src/locale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ using namespace std::string_view_literals;

namespace gucc::locale {

auto set_locale(std::string_view locale, std::string_view mountpoint) noexcept -> bool {
auto prepare_locale_set(std::string_view locale, std::string_view mountpoint) noexcept -> bool {

Check failure on line 15 in gucc/src/locale.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

/gucc/src/locale.cpp:15:25 [bugprone-easily-swappable-parameters

2 adjacent parameters of 'prepare_locale_set' of similar type ('std::string_view') are easily swapped by mistake
const auto& locale_config_path = fmt::format(FMT_COMPILE("{}/etc/locale.conf"), mountpoint);
const auto& locale_gen_path = fmt::format(FMT_COMPILE("{}/etc/locale.gen"), mountpoint);

Expand Down Expand Up @@ -40,13 +40,23 @@ LC_MESSAGES="{0}"
// TODO(vnepogodin): refactor and make backups of locale config and locale gen
utils::exec(fmt::format(FMT_COMPILE("sed -i \"s/#{0}/{0}/\" {1}"), locale, locale_gen_path));

// NOTE: maybe we should also write into /etc/default/locale if /etc/default exists and is a dir?
return true;
}

auto set_locale(std::string_view locale, std::string_view mountpoint) noexcept -> bool {
// Prepare locale
if (!locale::prepare_locale_set(locale, mountpoint)) {
spdlog::error("Failed to prepare locale files for '{}'", locale);
return false;
}

// Generate locales
if (!utils::arch_chroot_checked("locale-gen", mountpoint)) {
spdlog::error("Failed to run locale-gen with locale '{}'", locale);
return false;
}

// NOTE: maybe we should also write into /etc/default/locale if /etc/default exists and is a dir?
return true;
}

Expand Down
3 changes: 3 additions & 0 deletions gucc/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

file(GLOB files unit-*.cpp)

set(GUCC_TEST_DIR "${CMAKE_CURRENT_SOURCE_DIR}/")

foreach(file ${files})
get_filename_component(file_basename ${file} NAME_WE)
string(REGEX REPLACE "unit-([^$]+)" "test-\\1" testcase ${file_basename})
Expand All @@ -13,5 +15,6 @@ foreach(file ${files})
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-deprecated;-Wno-float-equal>
$<$<CXX_COMPILER_ID:GNU>:-Wno-deprecated-declarations>
)
add_definitions(-DGUCC_TEST_DIR="${GUCC_TEST_DIR}")
target_link_libraries(${testcase} PRIVATE project_warnings project_options gucc::gucc)
endforeach()
Loading

0 comments on commit 4b35d00

Please sign in to comment.