From a95b4e61c57bf40fbf5a20cb3c3d4eef9a0e8b1c Mon Sep 17 00:00:00 2001 From: a4z Date: Thu, 18 Jun 2026 20:23:49 +0200 Subject: [PATCH 1/6] Update testing --- cmake/testing.cmake | 2 +- include/a4z/filename.hpp | 20 +++++++++++++------- tests/base/filename_test.cpp | 31 +++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/cmake/testing.cmake b/cmake/testing.cmake index b5d16ae..8a2a27d 100644 --- a/cmake/testing.cmake +++ b/cmake/testing.cmake @@ -9,7 +9,7 @@ if (FETCH_DOCTEST) FetchContent_Declare( doctest GIT_REPOSITORY https://github.com/onqtam/doctest - GIT_TAG v2.4.12 + GIT_TAG v2.5.2 OVERRIDE_FIND_PACKAGE ) endif() diff --git a/include/a4z/filename.hpp b/include/a4z/filename.hpp index 77d159b..30a8119 100644 --- a/include/a4z/filename.hpp +++ b/include/a4z/filename.hpp @@ -13,20 +13,26 @@ namespace a4z { constexpr char slash = on_windows() && !using_clang() ? '\\' : '/'; -#define a4z_file_name \ +#define a4z_file_name_from(filename) \ []() constexpr { \ - constexpr const char* str = __FILE__; \ + constexpr const char* str = filename; \ constexpr auto len = a4z::cstr_len(str); \ - constexpr auto start{a4z::find_nth_r_occurrence(__FILE__, a4z::slash, 2)}; \ - static_assert(start != a4z::npos); \ - constexpr std::size_t astr_len = len - start; \ + constexpr auto start{a4z::find_nth_r_occurrence(filename, a4z::slash, 2)}; \ + constexpr std::size_t offset = (start == a4z::npos ? 0 : start); \ + constexpr std::size_t offset_add = (start == a4z::npos ? 0 : 1); \ + constexpr std::size_t astr_len = \ + (start == a4z::npos ? len + 1 : len - start); \ char data[astr_len] = {0}; \ for (std::size_t i = 0; i < astr_len; ++i) { \ - data[i] = *(str + start + i + 1); \ + data[i] = *(str + offset + offset_add + i); \ } \ return a4z::astr{data}; \ - } + }() + +#define a4z_file_name() a4z_file_name_from(__FILE__) } // namespace a4z + + #endif // A4Z_FILENAME_HPP diff --git a/tests/base/filename_test.cpp b/tests/base/filename_test.cpp index c59bc7b..77de486 100644 --- a/tests/base/filename_test.cpp +++ b/tests/base/filename_test.cpp @@ -1,6 +1,7 @@ #include #include +#include #include #include @@ -77,6 +78,33 @@ SCENARIO("Truncate a astr") { } } +SCENARIO("Test a4z_file_name_from with path delimiter") { + GIVEN("a path string with two delimiters") { + static constexpr char path[] = {'a', a4z::slash, 'b', a4z::slash, 'c', '\0'}; + constexpr auto fn = a4z_file_name_from(path); + WHEN("requesting the result") { + static constexpr char expected[] = {'b', a4z::slash, 'c', '\0'}; + const auto matches = a4z::equal(expected, fn.c_str()); + THEN("it contains the segment after the second-to-last delimiter") { + CHECK(matches); + } + } + } +} + +SCENARIO("Test a4z_file_name_from without path delimiter") { + GIVEN("a path string with no delimiter") { + static constexpr char path[] = {'a', 'b', 'c', '\0'}; + constexpr auto fn = a4z_file_name_from(path); + WHEN("requesting the result") { + const auto matches = a4z::equal("abc", fn.c_str()); + THEN("it returns the whole string") { + CHECK(matches); + } + } + } +} + SCENARIO("Test with filename macro") { GIVEN("the current filename") { constexpr auto fn = a4z_file_name(); @@ -99,7 +127,10 @@ SCENARIO("Test with filename macro") { // cpp20 // std::string(fn.c_str()).ends_with("filename_test.cpp"); THEN("we find it at the expected position") { + // MESSAGE(fn.c_str()); + std::cout << fn.c_str() << std::endl; CHECK(ends_with_filename); + } } } From 94bdd4467da0c43c5f1ce052e92cdca31e5d6698 Mon Sep 17 00:00:00 2001 From: a4z Date: Thu, 18 Jun 2026 20:55:28 +0200 Subject: [PATCH 2/6] Adopt to IDEs --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 722d5e7..41caa40 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ .vscode +.idea +.cache +compile_commands.json From b2012f2a83f05fb6ec8d4f201381d37d6a0dc00a Mon Sep 17 00:00:00 2001 From: a4z Date: Thu, 18 Jun 2026 20:55:42 +0200 Subject: [PATCH 3/6] format files --- include/a4z/filename.hpp | 4 +--- tests/base/filename_test.cpp | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/include/a4z/filename.hpp b/include/a4z/filename.hpp index 30a8119..5b3f473 100644 --- a/include/a4z/filename.hpp +++ b/include/a4z/filename.hpp @@ -21,7 +21,7 @@ namespace a4z { constexpr std::size_t offset = (start == a4z::npos ? 0 : start); \ constexpr std::size_t offset_add = (start == a4z::npos ? 0 : 1); \ constexpr std::size_t astr_len = \ - (start == a4z::npos ? len + 1 : len - start); \ + (start == a4z::npos ? len + 1 : len - start); \ char data[astr_len] = {0}; \ for (std::size_t i = 0; i < astr_len; ++i) { \ data[i] = *(str + offset + offset_add + i); \ @@ -33,6 +33,4 @@ namespace a4z { } // namespace a4z - - #endif // A4Z_FILENAME_HPP diff --git a/tests/base/filename_test.cpp b/tests/base/filename_test.cpp index 77de486..8ca662a 100644 --- a/tests/base/filename_test.cpp +++ b/tests/base/filename_test.cpp @@ -80,7 +80,8 @@ SCENARIO("Truncate a astr") { SCENARIO("Test a4z_file_name_from with path delimiter") { GIVEN("a path string with two delimiters") { - static constexpr char path[] = {'a', a4z::slash, 'b', a4z::slash, 'c', '\0'}; + using a4z::slash; + static constexpr char path[] = {'a', slash, 'b', slash, 'c', '\0'}; constexpr auto fn = a4z_file_name_from(path); WHEN("requesting the result") { static constexpr char expected[] = {'b', a4z::slash, 'c', '\0'}; @@ -130,7 +131,6 @@ SCENARIO("Test with filename macro") { // MESSAGE(fn.c_str()); std::cout << fn.c_str() << std::endl; CHECK(ends_with_filename); - } } } From 4e1791fabd1b650bee0b3aa9c535996af454deaf Mon Sep 17 00:00:00 2001 From: a4z Date: Thu, 18 Jun 2026 20:57:16 +0200 Subject: [PATCH 4/6] Remove debug prints --- tests/base/filename_test.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/base/filename_test.cpp b/tests/base/filename_test.cpp index 8ca662a..0cd9c98 100644 --- a/tests/base/filename_test.cpp +++ b/tests/base/filename_test.cpp @@ -1,7 +1,6 @@ #include #include -#include #include #include @@ -128,8 +127,6 @@ SCENARIO("Test with filename macro") { // cpp20 // std::string(fn.c_str()).ends_with("filename_test.cpp"); THEN("we find it at the expected position") { - // MESSAGE(fn.c_str()); - std::cout << fn.c_str() << std::endl; CHECK(ends_with_filename); } } From 6174e143745a929154a84b875ed7dad88360d5e1 Mon Sep 17 00:00:00 2001 From: a4z Date: Thu, 18 Jun 2026 21:00:50 +0200 Subject: [PATCH 5/6] Use latest msvc --- .github/workflows/cmake.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index b1d6cf9..a8a0082 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -35,7 +35,7 @@ jobs: - os: ubuntu-latest cmake_preset: ninja - os: windows-latest - cmake_preset: msvc22 + cmake_preset: msvc26 - os: macos-latest cmake_preset: xcode From 63cbf9a96157da070aaddf68377b8fb617618d92 Mon Sep 17 00:00:00 2001 From: a4z Date: Thu, 18 Jun 2026 21:16:16 +0200 Subject: [PATCH 6/6] Use stock Ubuntu --- .github/workflows/cmake.yml | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index a8a0082..d396fcc 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -13,12 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v4 - - - name: Install dependencies - run: | - sudo apt-get update - sudo apt-get install -y cmake ninja-build clang-format + uses: actions/checkout@v7 - name: Configure CMake run: cmake --preset ninja @@ -41,13 +36,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v4 - - - name: Install dependencies on Ubuntu - if: matrix.os == 'ubuntu-latest' - run: | - sudo apt-get update - sudo apt-get install -y cmake ninja-build + uses: actions/checkout@v7 - name: Configure CMake run: |