From 26757c94294bbfab88ebfa2cdff9a14c44408fe4 Mon Sep 17 00:00:00 2001 From: Krzysiek Karbowiak Date: Fri, 3 Oct 2025 18:03:25 +0200 Subject: [PATCH 1/2] Remove duplicate definition of custom class --- test/unittest/CMakeLists.txt | 1 - test/unittest/custom_b.h | 48 ----------------------- test/unittest/test_parsing_optional.cpp | 28 +++++-------- test/unittest/test_parsing_positional.cpp | 14 ++----- 4 files changed, 13 insertions(+), 78 deletions(-) delete mode 100644 test/unittest/custom_b.h diff --git a/test/unittest/CMakeLists.txt b/test/unittest/CMakeLists.txt index 2f1026b..f8b4317 100644 --- a/test/unittest/CMakeLists.txt +++ b/test/unittest/CMakeLists.txt @@ -7,7 +7,6 @@ target_sources(unittest PRIVATE cstring_array.h custom_a.h - custom_b.h main.cpp test_argument_parser.cpp test_error_message.cpp diff --git a/test/unittest/custom_b.h b/test/unittest/custom_b.h deleted file mode 100644 index 7e51aef..0000000 --- a/test/unittest/custom_b.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef CUSTOMB_H -#define CUSTOMB_H - -#include "argparse.hpp" -#include - - -namespace bar -{ - class Custom - { - public: - Custom() = default; - explicit Custom(std::string const & text) - : m_text(text) - { - } - - public: - std::string m_text; - }; -} - -namespace argparse -{ -template<> -class Converter -{ - public: - auto from_string(std::string const & s, bar::Custom & t) const -> bool - { - t = bar::Custom(s); - return true; - } - - auto to_string(bar::Custom const & t) const -> std::string - { - return ""; - } - - auto are_equal(bar::Custom const & lhs, bar::Custom const & rhs) const -> bool - { - return lhs.m_text == rhs.m_text; - } -}; -} - -#endif /* CUSTOMB_H */ diff --git a/test/unittest/test_parsing_optional.cpp b/test/unittest/test_parsing_optional.cpp index fa7e701..1c39d21 100644 --- a/test/unittest/test_parsing_optional.cpp +++ b/test/unittest/test_parsing_optional.cpp @@ -2,7 +2,6 @@ #include "cstring_array.h" #include "custom_a.h" -#include "custom_b.h" #include "doctest.h" @@ -19,13 +18,6 @@ inline auto operator==(Custom const & lhs, Custom const & rhs) -> bool return lhs.m_text == rhs.m_text; } } -namespace bar -{ -inline auto operator==(Custom const & lhs, Custom const & rhs) -> bool -{ - return lhs.m_text == rhs.m_text; -} -} TEST_CASE("Parsing an optional argument yields false when it's missing") { @@ -95,7 +87,7 @@ TEST_CASE("Parsing an optional argument with store false action yields false whe CHECK(args.get_value("o") == false); } -TEST_CASE_TEMPLATE("Parsing an optional argument with store const action yields false when it's missing", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, std::string, foo::Custom, bar::Custom) +TEST_CASE_TEMPLATE("Parsing an optional argument with store const action yields false when it's missing", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, std::string, foo::Custom) { auto parser = argparse::ArgumentParser(); @@ -117,7 +109,7 @@ TEST_CASE_TEMPLATE("Parsing an optional argument with store const action yields CHECK(!args.get("o")); } -TEST_CASE_TEMPLATE("Parsing an optional argument with store const action yields const value", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, std::string, foo::Custom, bar::Custom) +TEST_CASE_TEMPLATE("Parsing an optional argument with store const action yields const value", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, std::string, foo::Custom) { auto parser = argparse::ArgumentParser(); @@ -248,7 +240,7 @@ TEST_CASE("Parsing an optional argument with append action yields a list of argu CHECK(args.get_value>("a") == std::vector{"one", "two", "three"}); } -TEST_CASE_TEMPLATE("Parsing an optional argument with append action yields its requested type", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, foo::Custom, bar::Custom) +TEST_CASE_TEMPLATE("Parsing an optional argument with append action yields its requested type", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, foo::Custom) { auto parser = argparse::ArgumentParser(); parser.add_argument("-a").action(argparse::append).type(); @@ -339,7 +331,7 @@ TEST_CASE("Optional argument can be used with its long name") CHECK(args.get_value("option") == "val"); } -TEST_CASE_TEMPLATE("Parsing an optional argument yields its requested type", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, foo::Custom, bar::Custom) +TEST_CASE_TEMPLATE("Parsing an optional argument yields its requested type", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, foo::Custom) { auto parser = argparse::ArgumentParser(); parser.add_argument("-o").type(); @@ -379,7 +371,7 @@ TEST_CASE("Parsing an optional argument with invalid value throws an exception") CHECK_THROWS_WITH_AS(parser.parse_args(3, cstr_arr{"prog", "-o", "10gibberish"}), "argument -o: invalid value: '10gibberish'", argparse::parsing_error); } -TEST_CASE_TEMPLATE("Parsing an optional argument with default value yields the default value when it's missing", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, std::string, foo::Custom, bar::Custom) +TEST_CASE_TEMPLATE("Parsing an optional argument with default value yields the default value when it's missing", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, std::string, foo::Custom) { auto parser = argparse::ArgumentParser(); @@ -412,7 +404,7 @@ TEST_CASE_TEMPLATE("Parsing an optional argument with default value yields the d } } -TEST_CASE_TEMPLATE("Parsing an optional argument with default value yields value of the argument's type", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, std::string, foo::Custom, bar::Custom) +TEST_CASE_TEMPLATE("Parsing an optional argument with default value yields value of the argument's type", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, std::string, foo::Custom) { auto parser = argparse::ArgumentParser(); @@ -525,7 +517,7 @@ TEST_CASE("Parsing a missing optional argument with required false does not thro CHECK_NOTHROW(parser.parse_args(1, cstr_arr{"prog"})); } -TEST_CASE_TEMPLATE("Parsing an optional argument with choices set accepts one of the values", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, std::string, foo::Custom, bar::Custom) +TEST_CASE_TEMPLATE("Parsing an optional argument with choices set accepts one of the values", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, std::string, foo::Custom) { auto parser = argparse::ArgumentParser().handle(argparse::Handle::none); @@ -559,7 +551,7 @@ TEST_CASE_TEMPLATE("Parsing an optional argument with choices set accepts one of } } -TEST_CASE_TEMPLATE("Parsing an optional argument with choices set throws an exception on incorrect value", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, std::string, foo::Custom, bar::Custom) +TEST_CASE_TEMPLATE("Parsing an optional argument with choices set throws an exception on incorrect value", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, std::string, foo::Custom) { auto parser = argparse::ArgumentParser().handle(argparse::Handle::none); @@ -2568,7 +2560,7 @@ TEST_CASE("Parsing long option with joined argument yields its value") CHECK(args.get_value("long") == "value"); } -TEST_CASE_TEMPLATE("Parsing long option with joined argument yields its value", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, foo::Custom, bar::Custom) +TEST_CASE_TEMPLATE("Parsing long option with joined argument yields its value", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, foo::Custom) { auto parser = argparse::ArgumentParser(); parser.add_argument("--long").type(); @@ -2639,7 +2631,7 @@ TEST_CASE("Parsing short option with joined argument yields its value") CHECK(args.get_value("o") == "value"); } -TEST_CASE_TEMPLATE("Parsing short option with joined argument yields its value", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, foo::Custom, bar::Custom) +TEST_CASE_TEMPLATE("Parsing short option with joined argument yields its value", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, foo::Custom) { auto parser = argparse::ArgumentParser(); parser.add_argument("-o").type(); diff --git a/test/unittest/test_parsing_positional.cpp b/test/unittest/test_parsing_positional.cpp index 8da177e..1e3a3a7 100644 --- a/test/unittest/test_parsing_positional.cpp +++ b/test/unittest/test_parsing_positional.cpp @@ -2,7 +2,6 @@ #include "cstring_array.h" #include "custom_a.h" -#include "custom_b.h" #include "doctest.h" @@ -19,13 +18,6 @@ inline auto operator==(Custom const & lhs, Custom const & rhs) -> bool return lhs.m_text == rhs.m_text; } } -namespace bar -{ -inline auto operator==(Custom const & lhs, Custom const & rhs) -> bool -{ - return lhs.m_text == rhs.m_text; -} -} TEST_CASE("Parsing a positional argument yields its value") { @@ -37,7 +29,7 @@ TEST_CASE("Parsing a positional argument yields its value") CHECK(args.get_value("p1") == "v1"); } -TEST_CASE_TEMPLATE("Parsing a positional argument yields its requested type", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, foo::Custom, bar::Custom) +TEST_CASE_TEMPLATE("Parsing a positional argument yields its requested type", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, foo::Custom) { auto parser = argparse::ArgumentParser(); parser.add_argument("pos").type(); @@ -147,7 +139,7 @@ TEST_CASE("The resulting attribute name for positional argument is based on dest CHECK(args.get("bar")); } -TEST_CASE_TEMPLATE("Parsing a positional argument with choices set accepts one of the values", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, std::string, foo::Custom, bar::Custom) +TEST_CASE_TEMPLATE("Parsing a positional argument with choices set accepts one of the values", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, std::string, foo::Custom) { auto parser = argparse::ArgumentParser().handle(argparse::Handle::none); @@ -181,7 +173,7 @@ TEST_CASE_TEMPLATE("Parsing a positional argument with choices set accepts one o } } -TEST_CASE_TEMPLATE("Parsing a positional argument with choices set throws an exception on incorrect value", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, std::string, foo::Custom, bar::Custom) +TEST_CASE_TEMPLATE("Parsing a positional argument with choices set throws an exception on incorrect value", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, std::string, foo::Custom) { auto parser = argparse::ArgumentParser().handle(argparse::Handle::none); From e85fe86d2f56426aa15ca61c79d45c3e373bab2c Mon Sep 17 00:00:00 2001 From: Krzysiek Karbowiak Date: Fri, 3 Oct 2025 18:06:29 +0200 Subject: [PATCH 2/2] Rename file --- test/unittest/CMakeLists.txt | 2 +- test/unittest/{custom_a.h => custom.h} | 6 +++--- test/unittest/test_parsing_optional.cpp | 2 +- test/unittest/test_parsing_positional.cpp | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) rename test/unittest/{custom_a.h => custom.h} (93%) diff --git a/test/unittest/CMakeLists.txt b/test/unittest/CMakeLists.txt index f8b4317..d4fff1b 100644 --- a/test/unittest/CMakeLists.txt +++ b/test/unittest/CMakeLists.txt @@ -6,7 +6,7 @@ add_executable(unittest) target_sources(unittest PRIVATE cstring_array.h - custom_a.h + custom.h main.cpp test_argument_parser.cpp test_error_message.cpp diff --git a/test/unittest/custom_a.h b/test/unittest/custom.h similarity index 93% rename from test/unittest/custom_a.h rename to test/unittest/custom.h index 600884d..1218888 100644 --- a/test/unittest/custom_a.h +++ b/test/unittest/custom.h @@ -1,5 +1,5 @@ -#ifndef CUSTOMA_H -#define CUSTOMA_H +#ifndef CUSTOM_H +#define CUSTOM_H #include "argparse.hpp" #include @@ -45,4 +45,4 @@ class Converter }; } -#endif /* CUSTOMA_H */ +#endif /* CUSTOM_H */ diff --git a/test/unittest/test_parsing_optional.cpp b/test/unittest/test_parsing_optional.cpp index 1c39d21..743ac8a 100644 --- a/test/unittest/test_parsing_optional.cpp +++ b/test/unittest/test_parsing_optional.cpp @@ -1,7 +1,7 @@ #include "argparse.hpp" #include "cstring_array.h" -#include "custom_a.h" +#include "custom.h" #include "doctest.h" diff --git a/test/unittest/test_parsing_positional.cpp b/test/unittest/test_parsing_positional.cpp index 1e3a3a7..a797ef3 100644 --- a/test/unittest/test_parsing_positional.cpp +++ b/test/unittest/test_parsing_positional.cpp @@ -1,7 +1,7 @@ #include "argparse.hpp" #include "cstring_array.h" -#include "custom_a.h" +#include "custom.h" #include "doctest.h"