From b43c88c4ca9654b6819bdb571d4e63471f539fbd Mon Sep 17 00:00:00 2001 From: Anutosh Bhat Date: Tue, 17 Dec 2024 13:31:37 +0530 Subject: [PATCH] Fix extract_filename function (#409) Fix extract_filename function --- .github/workflows/main.yml | 4 ++-- include/xeus/xhelper.hpp | 11 ++++++++++- src/xhelper.cpp | 2 +- test/test_unit_kernel.cpp | 4 +++- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2c577598..e1ffe008 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -143,8 +143,8 @@ jobs: - name: Get number of CPU cores uses: SimenB/github-actions-cpu-cores@v2 - - name: Install mamba - uses: mamba-org/setup-micromamba@v1 + - name: Install micromamba + uses: mamba-org/setup-micromamba@v2 with: environment-file: environment-wasm-build.yml environment-name: xeus-wasm-build diff --git a/include/xeus/xhelper.hpp b/include/xeus/xhelper.hpp index 6ff3b692..af0379d9 100644 --- a/include/xeus/xhelper.hpp +++ b/include/xeus/xhelper.hpp @@ -24,7 +24,16 @@ namespace xeus { XEUS_API std::string get_start_message(const xconfiguration& config); - XEUS_API std::string extract_filename(int argc, char* argv[]); + /** + * @brief Extracts the filename from the command-line arguments and adjusts argc/argv. + * + * Searches for the "-f" flag in the arguments, extracts the following filename, and + * removes both from the argument list. `argc` is updated to reflect the changes. + * @param argc Reference to the argument count, modified if "-f" is found. + * @param argv Argument list, potentially modified. + * @return The extracted filename, or an empty string if not found. + */ + XEUS_API std::string extract_filename(int &argc, char* argv[]); XEUS_API bool should_print_version(int argc, char* argv[]); diff --git a/src/xhelper.cpp b/src/xhelper.cpp index 98d999f3..783cc6a4 100644 --- a/src/xhelper.cpp +++ b/src/xhelper.cpp @@ -30,7 +30,7 @@ namespace xeus return kernel_info; } - std::string extract_filename(int argc, char* argv[]) + std::string extract_filename(int &argc, char* argv[]) { std::string res = ""; for (int i = 0; i < argc; ++i) diff --git a/test/test_unit_kernel.cpp b/test/test_unit_kernel.cpp index 97a967ee..1acb78c5 100644 --- a/test/test_unit_kernel.cpp +++ b/test/test_unit_kernel.cpp @@ -55,11 +55,13 @@ namespace xeus TEST_CASE("extract_filename") { + int argc = 3; char* argv[2]; argv[0] = (char*)"-f"; argv[1] = (char*)"connection.json"; - std::string file_name = extract_filename(3, argv); + std::string file_name = extract_filename(argc, argv); REQUIRE_EQ(file_name, "connection.json"); + REQUIRE_EQ(argc, 1); } TEST_CASE("should_print_version")