From e1750fc74d56abe3997faeadab6ecae3a71391c8 Mon Sep 17 00:00:00 2001 From: Lydia Buntrock Date: Wed, 5 Jan 2022 14:17:36 +0100 Subject: [PATCH] [MISC] Remove dependency of seqan3::io. Signed-off-by: Lydia Buntrock --- include/sharg/validators.hpp | 43 +------------------ .../validators_input_file_ext_from_file.cpp | 4 +- test/unit/format_parse_validators_test.cpp | 42 +++++++++++++----- 3 files changed, 34 insertions(+), 55 deletions(-) diff --git a/include/sharg/validators.hpp b/include/sharg/validators.hpp index 1101f261..5b078991 100644 --- a/include/sharg/validators.hpp +++ b/include/sharg/validators.hpp @@ -17,7 +17,6 @@ #include #include -#include #include #include @@ -260,7 +259,6 @@ value_list_validator(range_type && rng) -> value_list_validator class input_file_validator : public file_validator_base { public: - static_assert(std::same_as || seqan3::detail::has_type_valid_formats, - "Expected either a template type with a static member called valid_formats (a file type) or void."); - // Import from base class. using typename file_validator_base::option_value_type; @@ -474,20 +467,6 @@ class input_file_validator : public file_validator_base * \{ */ - /*!\brief Default constructor. - * - * \details - * - * If the class' template argument `file_t` names a valid seqan3 file type that contains a - * static member `valid_formats`, e.g. seqan3::sequence_input_file::valid_formats, then it generates the - * list of valid extensions from this file. Otherwise the extensions list is empty. - */ - input_file_validator() - { - if constexpr (!std::same_as) - file_validator_base::extensions = seqan3::detail::valid_file_extensions(); - } - input_file_validator(input_file_validator const &) = default; //!< Defaulted. input_file_validator(input_file_validator &&) = default; //!< Defaulted. input_file_validator & operator=(input_file_validator const &) = default; //!< Defaulted. @@ -496,17 +475,8 @@ class input_file_validator : public file_validator_base /*!\brief Constructs from a given collection of valid extensions. * \param[in] extensions The valid extensions to validate for. - * - * \details - * - * This constructor is only available if `file_t` does not name a valid seqan3 file type that contains a - * static member `valid_formats`. */ - explicit input_file_validator(std::vector extensions) - //!\cond - requires std::same_as - //!\endcond - : file_validator_base{} + explicit input_file_validator(std::vector extensions) : file_validator_base{} { file_validator_base::extensions = std::move(extensions); } @@ -568,7 +538,6 @@ enum class output_file_open_options /*!\brief A validator that checks if a given path is a valid output file. * \ingroup argument_parser * \implements sharg::validator - * \tparam file_t The type of the file to get the valid extensions for; `void` on default. * * \details * @@ -593,12 +562,9 @@ enum class output_file_open_options * * \remark For a complete overview, take a look at \ref argument_parser */ -template class output_file_validator : public file_validator_base { public: - static_assert(std::same_as || seqan3::detail::has_type_valid_formats, - "Expected either a template type with a static member called valid_formats (a file type) or void."); // Import from base class. using typename file_validator_base::option_value_type; @@ -636,16 +602,9 @@ class output_file_validator : public file_validator_base /*!\brief The default extensions of `file_t`. * \returns A list of default extensions for `file_t`, will be empty if `file_t` is `void`. - * - * \details - * - * If `file_t` does name a valid seqan3 file type that contains a static member `valid_formats` returns the - * extensions of that `file_t` type. Otherwise returns an empty list. */ static std::vector default_extensions() { - if constexpr (!std::same_as) - return seqan3::detail::valid_file_extensions(); return {}; } diff --git a/test/snippet/validators_input_file_ext_from_file.cpp b/test/snippet/validators_input_file_ext_from_file.cpp index cb534364..eb23d6e5 100644 --- a/test/snippet/validators_input_file_ext_from_file.cpp +++ b/test/snippet/validators_input_file_ext_from_file.cpp @@ -12,8 +12,8 @@ int main() sharg::input_file_validator validator2{std::vector{std::string{"exe"}, std::string{"fasta"}}}; std::cerr << validator2.get_help_page_message() << '\n'; - // Give the seqan3 file type as a template argument to get all valid extensions for this file. - sharg::input_file_validator> validator3{}; + // Give the sharg file type as a template argument to get all valid extensions for this file. + sharg::input_file_validator validator3{seqan3::sequence_file_input<>::valid_formats} std::cerr << validator3.get_help_page_message() << '\n'; return 0; diff --git a/test/unit/format_parse_validators_test.cpp b/test/unit/format_parse_validators_test.cpp index 4987680e..60409722 100644 --- a/test/unit/format_parse_validators_test.cpp +++ b/test/unit/format_parse_validators_test.cpp @@ -24,9 +24,14 @@ struct dummy_file static inline std::vector file_extensions{ {"sam"}, {"bam"}}; }; - using valid_formats = seqan3::type_list; }; +dummy_file::format1 f1; +dummy_file::format2 f2; +std::vector A = f1.file_extensions; +std::vector B = f2.file_extensions; +std::vector dummy_file_extensions; + std::string const basic_options_str = "OPTIONS\n" "\n" " Basic options:\n" @@ -73,8 +78,8 @@ TEST(validator_test, fullfill_concept) EXPECT_TRUE(sharg::validator>); EXPECT_TRUE(sharg::validator>); EXPECT_TRUE(sharg::validator>); - EXPECT_TRUE(sharg::validator>); - EXPECT_TRUE(sharg::validator>); + EXPECT_TRUE(sharg::validator); + EXPECT_TRUE(sharg::validator); EXPECT_TRUE(sharg::validator); EXPECT_TRUE(sharg::validator); EXPECT_TRUE(sharg::validator); @@ -133,7 +138,10 @@ TEST(validator_test, input_file) } { // read from file - sharg::input_file_validator my_validator{}; + dummy_file_extensions.reserve( A.size() + B.size() ); // preallocate memory + dummy_file_extensions.insert( dummy_file_extensions.end(), A.begin(), A.end() ); + dummy_file_extensions.insert( dummy_file_extensions.end(), B.begin(), B.end() ); + sharg::input_file_validator my_validator{dummy_file_extensions}; EXPECT_NO_THROW(my_validator(tmp_name.get_path())); } @@ -197,7 +205,10 @@ TEST(validator_test, input_file) TEST(validator_test, input_file_ext_from_file) { // Give as a template argument the seqan3 file type to get all valid extensions for this file. - sharg::input_file_validator validator{}; + dummy_file_extensions.reserve( A.size() + B.size() ); // preallocate memory + dummy_file_extensions.insert( dummy_file_extensions.end(), A.begin(), A.end() ); + dummy_file_extensions.insert( dummy_file_extensions.end(), B.begin(), B.end() ); + sharg::input_file_validator validator{dummy_file_extensions}; EXPECT_EQ(validator.get_help_page_message(), "The input file must exist and read permissions must be granted. " "Valid file extensions are: [fa, fasta, sam, bam]."); @@ -264,8 +275,16 @@ TEST(validator_test, output_file) } { // read from file - sharg::output_file_validator my_validator{}; + dummy_file_extensions.reserve( A.size() + B.size() ); // preallocate memory + dummy_file_extensions.insert( dummy_file_extensions.end(), A.begin(), A.end() ); + dummy_file_extensions.insert( dummy_file_extensions.end(), B.begin(), B.end() ); + sharg::output_file_validator my_validator{sharg::output_file_open_options::create_new, + dummy_file_extensions}; EXPECT_NO_THROW(my_validator(tmp_name.get_path())); + + sharg::output_file_validator my_validator2{sharg::output_file_open_options::open_or_create, + dummy_file_extensions}; + EXPECT_NO_THROW(my_validator2(tmp_name.get_path())); } std::filesystem::path file_out_path; @@ -360,15 +379,16 @@ TEST(validator_test, output_file) TEST(validator_test, output_file_ext_from_file) { // Give as a template argument the seqan3 file type to get all valid extensions for this file. - sharg::output_file_validator validator1{}; - EXPECT_EQ(validator1.get_help_page_message(), "The output file must not exist already and write permissions must " - "be granted. Valid file extensions are: [fa, fasta, sam, bam]."); - sharg::output_file_validator validator2{sharg::output_file_open_options::create_new}; + dummy_file_extensions.reserve( A.size() + B.size() ); // preallocate memory + dummy_file_extensions.insert( dummy_file_extensions.end(), A.begin(), A.end() ); + dummy_file_extensions.insert( dummy_file_extensions.end(), B.begin(), B.end() ); + + sharg::output_file_validator validator2{sharg::output_file_open_options::create_new, dummy_file_extensions}; EXPECT_EQ(validator2.get_help_page_message(), "The output file must not exist already and write permissions must " "be granted. Valid file extensions are: [fa, fasta, sam, bam]."); - sharg::output_file_validator validator3{sharg::output_file_open_options::open_or_create}; + sharg::output_file_validator validator3{sharg::output_file_open_options::open_or_create, dummy_file_extensions}; EXPECT_EQ(validator3.get_help_page_message(), "Write permissions must be granted. Valid file extensions are: [fa, " "fasta, sam, bam].");