From 21fa77e93ecc394fe1fffb7ec6c203c762270853 Mon Sep 17 00:00:00 2001 From: Lydia Buntrock Date: Mon, 24 Aug 2020 20:44:09 +0200 Subject: [PATCH] [FEATURE] Use enum `output_file_open_mode` to handle overwriting permission Signed-off-by: Lydia Buntrock --- .../read_mapper/read_mapper_indexer_step1.cpp | 2 +- .../read_mapper/read_mapper_indexer_step2.cpp | 2 +- .../read_mapper/read_mapper_indexer_step3.cpp | 2 +- .../read_mapper/read_mapper_step1.cpp | 2 +- .../read_mapper/read_mapper_step2.cpp | 2 +- .../read_mapper/read_mapper_step3.cpp | 2 +- .../read_mapper/read_mapper_step4.cpp | 2 +- include/seqan3/argument_parser/validators.hpp | 77 +++++++-------- .../validators_output_directory.cpp | 3 +- .../validators_output_file.cpp | 8 +- .../validators_output_file_ext_from_file.cpp | 7 +- .../format_parse_validators_test.cpp | 95 ++++++++++--------- 12 files changed, 105 insertions(+), 99 deletions(-) diff --git a/doc/tutorial/read_mapper/read_mapper_indexer_step1.cpp b/doc/tutorial/read_mapper/read_mapper_indexer_step1.cpp index 179d788723f..82ab675e01c 100644 --- a/doc/tutorial/read_mapper/read_mapper_indexer_step1.cpp +++ b/doc/tutorial/read_mapper/read_mapper_indexer_step1.cpp @@ -24,7 +24,7 @@ void initialise_argument_parser(seqan3::argument_parser & parser, cmd_arguments seqan3::input_file_validator{{"fa","fasta"}}); parser.add_option(args.index_path, 'o', "output", "The output index file path.", seqan3::option_spec::DEFAULT, - seqan3::output_file_validator{{"index"}}); + seqan3::output_file_validator{seqan3::output_file_open_mode::exclusive, {"index"}}); } //![main] diff --git a/doc/tutorial/read_mapper/read_mapper_indexer_step2.cpp b/doc/tutorial/read_mapper/read_mapper_indexer_step2.cpp index d46e06e9c72..87e825088d0 100644 --- a/doc/tutorial/read_mapper/read_mapper_indexer_step2.cpp +++ b/doc/tutorial/read_mapper/read_mapper_indexer_step2.cpp @@ -51,7 +51,7 @@ void initialise_argument_parser(seqan3::argument_parser & parser, cmd_arguments seqan3::input_file_validator{{"fa","fasta"}}); parser.add_option(args.index_path, 'o', "output", "The output index file path.", seqan3::option_spec::DEFAULT, - seqan3::output_file_validator{{"index"}}); + seqan3::output_file_validator{seqan3::output_file_open_mode::exclusive, {"index"}}); } int main(int argc, char const ** argv) diff --git a/doc/tutorial/read_mapper/read_mapper_indexer_step3.cpp b/doc/tutorial/read_mapper/read_mapper_indexer_step3.cpp index 055fe4d5ca8..630d00daf12 100644 --- a/doc/tutorial/read_mapper/read_mapper_indexer_step3.cpp +++ b/doc/tutorial/read_mapper/read_mapper_indexer_step3.cpp @@ -66,7 +66,7 @@ void initialise_argument_parser(seqan3::argument_parser & parser, cmd_arguments seqan3::input_file_validator{{"fa","fasta"}}); parser.add_option(args.index_path, 'o', "output", "The output index file path.", seqan3::option_spec::DEFAULT, - seqan3::output_file_validator{{"index"}}); + seqan3::output_file_validator{seqan3::output_file_open_mode::exclusive, {"index"}}); } int main(int argc, char const ** argv) diff --git a/doc/tutorial/read_mapper/read_mapper_step1.cpp b/doc/tutorial/read_mapper/read_mapper_step1.cpp index 3466c41a77f..497e6950257 100644 --- a/doc/tutorial/read_mapper/read_mapper_step1.cpp +++ b/doc/tutorial/read_mapper/read_mapper_step1.cpp @@ -39,7 +39,7 @@ void initialise_argument_parser(seqan3::argument_parser & parser, cmd_arguments seqan3::input_file_validator{{"index"}}); parser.add_option(args.sam_path, 'o', "output", "The output SAM file path.", seqan3::option_spec::DEFAULT, - seqan3::output_file_validator{{"sam"}}); + seqan3::output_file_validator{seqan3::output_file_open_mode::exclusive, {"sam"}}); parser.add_option(args.errors, 'e', "error", "Maximum allowed errors.", seqan3::option_spec::DEFAULT, seqan3::arithmetic_range_validator{0, 4}); diff --git a/doc/tutorial/read_mapper/read_mapper_step2.cpp b/doc/tutorial/read_mapper/read_mapper_step2.cpp index 1fbb8322260..c7499a6ccfd 100644 --- a/doc/tutorial/read_mapper/read_mapper_step2.cpp +++ b/doc/tutorial/read_mapper/read_mapper_step2.cpp @@ -103,7 +103,7 @@ void initialise_argument_parser(seqan3::argument_parser & parser, cmd_arguments seqan3::input_file_validator{{"index"}}); parser.add_option(args.sam_path, 'o', "output", "The output SAM file path.", seqan3::option_spec::DEFAULT, - seqan3::output_file_validator{{"sam"}}); + seqan3::output_file_validator{seqan3::output_file_open_mode::exclusive, {"sam"}}); parser.add_option(args.errors, 'e', "error", "Maximum allowed errors.", seqan3::option_spec::DEFAULT, seqan3::arithmetic_range_validator{0, 4}); diff --git a/doc/tutorial/read_mapper/read_mapper_step3.cpp b/doc/tutorial/read_mapper/read_mapper_step3.cpp index 8064de1cce0..08eaf52ba24 100644 --- a/doc/tutorial/read_mapper/read_mapper_step3.cpp +++ b/doc/tutorial/read_mapper/read_mapper_step3.cpp @@ -122,7 +122,7 @@ void initialise_argument_parser(seqan3::argument_parser & parser, cmd_arguments seqan3::input_file_validator{{"index"}}); parser.add_option(args.sam_path, 'o', "output", "The output SAM file path.", seqan3::option_spec::DEFAULT, - seqan3::output_file_validator{{"sam"}}); + seqan3::output_file_validator{seqan3::output_file_open_mode::exclusive, {"sam"}}); parser.add_option(args.errors, 'e', "error", "Maximum allowed errors.", seqan3::option_spec::DEFAULT, seqan3::arithmetic_range_validator{0, 4}); diff --git a/doc/tutorial/read_mapper/read_mapper_step4.cpp b/doc/tutorial/read_mapper/read_mapper_step4.cpp index 10932f772f4..8cd285d6dfb 100644 --- a/doc/tutorial/read_mapper/read_mapper_step4.cpp +++ b/doc/tutorial/read_mapper/read_mapper_step4.cpp @@ -130,7 +130,7 @@ void initialise_argument_parser(seqan3::argument_parser & parser, cmd_arguments seqan3::input_file_validator{{"index"}}); parser.add_option(args.sam_path, 'o', "output", "The output SAM file path.", seqan3::option_spec::DEFAULT, - seqan3::output_file_validator{{"sam"}}); + seqan3::output_file_validator{seqan3::output_file_open_mode::exclusive, {"sam"}}); parser.add_option(args.errors, 'e', "error", "Maximum allowed errors.", seqan3::option_spec::DEFAULT, seqan3::arithmetic_range_validator{0, 4}); diff --git a/include/seqan3/argument_parser/validators.hpp b/include/seqan3/argument_parser/validators.hpp index 0376cb1141e..6744d6e066a 100644 --- a/include/seqan3/argument_parser/validators.hpp +++ b/include/seqan3/argument_parser/validators.hpp @@ -574,6 +574,15 @@ class input_file_validator : public file_validator_base } }; +//!\brief Stores, if it is valid to overwrite the output file. +enum output_file_open_mode +{ + //!\brief Allow to overwrite the output file + overwritable, + //!\brief Forbid overwriting the output file + exclusive +}; + /*!\brief A validator that checks if a given path is a valid output file. * \ingroup argument_parser * \implements seqan3::validator @@ -600,17 +609,14 @@ class input_file_validator : public file_validator_base template class output_file_validator : public file_validator_base { -public: - //!\brief Stores, if it is valid to overwrite the output file. - bool allow_overwrite = false; // ToDo: bool oder enum? Für jedes File einzeln entscheiden, also zum Pfad dazugeben? Oder als Vektor angeben? +private: + //!\brief Stores the current mode, if it is valid to overwrite the output file. + output_file_open_mode mode; +public: static_assert(std::same_as || detail::has_type_valid_formats, "Expected either a template type with a static member called valid_formats (a file type) or void."); - // Wenn enum, dann: ? - // static_assert(std::same_as || detail::has_type_valid_formats, - // "Wenn gesetzt, prüfe ob file existiert."); - // Import from base class. using typename file_validator_base::option_value_type; @@ -618,58 +624,45 @@ class output_file_validator : public file_validator_base * \{ */ - //!\copydoc seqan3::input_file_validator::input_file_validator() - output_file_validator() + output_file_validator() = delete; //!< Deleted. + output_file_validator(output_file_validator const &) = default; //!< Defaulted. + output_file_validator(output_file_validator &&) = default; //!< Defaulted. + output_file_validator & operator=(output_file_validator const &) = default; //!< Defaulted. + output_file_validator & operator=(output_file_validator &&) = default; //!< Defaulted. + virtual ~output_file_validator() = default; //!< Virtual Destructor. + + /*!\brief Constructs from a given collection of valid extensions. + * \param[in] mode Sets a flag, if it is valid to overwrite the output file. + * + * \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 output_file_validator(output_file_open_mode const mode) : file_validator_base{}, mode{mode} { if constexpr (!std::same_as) file_validator_base::extensions = detail::valid_file_extensions(); } - output_file_validator(output_file_validator const &) = default; //!< Defaulted. - output_file_validator(output_file_validator &&) = default; //!< Defaulted. - output_file_validator & operator=(output_file_validator const &) = default; //!< Defaulted. - output_file_validator & operator=(output_file_validator &&) = default; //!< Defaulted. - virtual ~output_file_validator() = default; //!< Virtual Destructor. - - //!\copydoc seqan3::input_file_validator::input_file_validator(std::vector) - explicit output_file_validator(std::vector extensions) - //!\cond - requires std::same_as - //!\endcond - : file_validator_base{} - { - file_validator_base::extensions = std::move(extensions); - } - /*!\brief Constructs from a given collection of valid extensions. * \param[in] extensions The valid extensions to validate for. - * \param[in] allow_overwrite Sets a flag, if it is valid to overwrite the output file. + * \param[in] mode Sets a flag, if it is valid to overwrite the output file. * * \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 output_file_validator(std::vector extensions, bool allow_overwrite) + explicit output_file_validator(output_file_open_mode const mode, std::vector extensions) //!\cond requires std::same_as //!\endcond - : file_validator_base{}, allow_overwrite{allow_overwrite} + : file_validator_base{}, mode{mode} { file_validator_base::extensions = std::move(extensions); } - /*!\brief Constructs from a given collection of valid extensions. - * \param[in] allow_overwrite Sets a flag, if it is valid to overwrite the output file. - * - * \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 output_file_validator(bool allow_overwrite) : file_validator_base{}, allow_overwrite{allow_overwrite} - {} - - // Import base constructor. using file_validator_base::file_validator_base; //!\} @@ -686,7 +679,7 @@ class output_file_validator : public file_validator_base { try { - if (!allow_overwrite && std::filesystem::exists(file)) + if ((mode == exclusive) && std::filesystem::exists(file)) throw validation_error{detail::to_string("The file ", file, " already exists!")}; // Check if file has any write permissions. @@ -707,9 +700,9 @@ class output_file_validator : public file_validator_base //!\brief Returns a message that can be appended to the (positional) options help page info. std::string get_help_page_message() const { - if (allow_overwrite) + if (mode == overwritable) return "Write permissions must be granted." + valid_extensions_help_page_message(); - else + else // mode == exclusive return "The output file must not exist already and write permissions must be granted." + valid_extensions_help_page_message(); } diff --git a/test/snippet/argument_parser/validators_output_directory.cpp b/test/snippet/argument_parser/validators_output_directory.cpp index da7bab3511b..97b5b13fbd7 100644 --- a/test/snippet/argument_parser/validators_output_directory.cpp +++ b/test/snippet/argument_parser/validators_output_directory.cpp @@ -10,7 +10,8 @@ int main(int argc, const char ** argv) std::filesystem::path mydir{}; myparser.add_option(mydir, 'd', "dir", "The output directory for storing the files.", - seqan3::option_spec::DEFAULT, seqan3::output_directory_validator{}); + seqan3::option_spec::DEFAULT, + seqan3::output_file_validator{seqan3::output_file_open_mode::exclusive}); //! [validator_call] // an exception will be thrown if the user specifies a directory that cannot be created by the filesystem either diff --git a/test/snippet/argument_parser/validators_output_file.cpp b/test/snippet/argument_parser/validators_output_file.cpp index a60f6cda17a..571fcb53378 100644 --- a/test/snippet/argument_parser/validators_output_file.cpp +++ b/test/snippet/argument_parser/validators_output_file.cpp @@ -9,10 +9,12 @@ int main(int argc, const char ** argv) //! [validator_call] std::filesystem::path myfile{}; + // Add the output_file_open_mode, to allow overwriting existing files, or to avoid this. myparser.add_option(myfile,'f',"file","Output file containing the processed sequences.", - seqan3::option_spec::DEFAULT, seqan3::output_file_validator{{"fa","fasta"}}); - // Add an additional `true`, to allow overwriting existing files. - // seqan3::option_spec::DEFAULT, seqan3::output_file_validator{{"fa","fasta"}, true}); + seqan3::option_spec::DEFAULT, + seqan3::output_file_validator{seqan3::output_file_open_mode::overwritable, {"fa","fasta"}}); + // or + // seqan3::output_file_validator{seqan3::output_file_open_mode::exclusive, {"fa","fasta"}}); //! [validator_call] // an exception will be thrown if the user specifies a filename diff --git a/test/snippet/argument_parser/validators_output_file_ext_from_file.cpp b/test/snippet/argument_parser/validators_output_file_ext_from_file.cpp index 7209091b673..3bd9c937e20 100644 --- a/test/snippet/argument_parser/validators_output_file_ext_from_file.cpp +++ b/test/snippet/argument_parser/validators_output_file_ext_from_file.cpp @@ -5,15 +5,16 @@ int main(int argc, const char ** argv) { // Default constructed validator has an empty extension list. - seqan3::output_file_validator validator1{}; + seqan3::output_file_validator validator1{seqan3::output_file_open_mode::exclusive}; seqan3::debug_stream << validator1.get_help_page_message() << "\n"; // Specify your own extensions for the output file. - seqan3::output_file_validator validator2{std::vector{std::string{"exe"}, std::string{"fasta"}}}; + seqan3::output_file_validator validator2{seqan3::output_file_open_mode::exclusive, + std::vector{std::string{"exe"}, std::string{"fasta"}}}; seqan3::debug_stream << validator2.get_help_page_message() << "\n"; // Give the seqan3 file type as a template argument to get all valid extensions for this file. - seqan3::output_file_validator> validator3{}; + seqan3::output_file_validator> validator3{seqan3::output_file_open_mode::exclusive}; seqan3::debug_stream << validator3.get_help_page_message() << "\n"; return 0; diff --git a/test/unit/argument_parser/format_parse_validators_test.cpp b/test/unit/argument_parser/format_parse_validators_test.cpp index c3bd99728a2..f0ea6072424 100644 --- a/test/unit/argument_parser/format_parse_validators_test.cpp +++ b/test/unit/argument_parser/format_parse_validators_test.cpp @@ -209,53 +209,48 @@ TEST(validator_test, output_file) { // single file { // empty list of file. - seqan3::output_file_validator my_validator{}; + seqan3::output_file_validator my_validator{seqan3::output_file_open_mode::exclusive}; EXPECT_NO_THROW(my_validator(tmp_name.get_path())); } - { // file does exist. (default: overwriting is prohibited) + { // file does exist but allow to overwrite it (without given formats to the validator) std::ofstream tmp_file_2(tmp_name_2.get_path()); std::filesystem::path does_not_exist{tmp_name_2.get_path()}; - seqan3::output_file_validator my_validator{formats}; - EXPECT_THROW(my_validator(does_not_exist), seqan3::validation_error); + seqan3::output_file_validator my_validator{seqan3::output_file_open_mode::overwritable}; + EXPECT_NO_THROW(my_validator(does_not_exist)); } - { // file does exist and dont allow to overwrite it. (default) + { // file does exist & overwriting is prohibited std::ofstream tmp_file_2(tmp_name_2.get_path()); std::filesystem::path does_not_exist{tmp_name_2.get_path()}; - seqan3::output_file_validator my_validator{formats, false}; + seqan3::output_file_validator my_validator{seqan3::output_file_open_mode::exclusive, formats}; EXPECT_THROW(my_validator(does_not_exist), seqan3::validation_error); } { // file does exist but allow to overwrite it std::ofstream tmp_file_2(tmp_name_2.get_path()); std::filesystem::path does_not_exist{tmp_name_2.get_path()}; - seqan3::output_file_validator my_validator{formats, true}; - EXPECT_NO_THROW(my_validator(does_not_exist)); - // ToDo: test if the file was replaced?! - } - - { // file does exist but allow to overwrite it (without given formats to the validator) - std::ofstream tmp_file_2(tmp_name_2.get_path()); - std::filesystem::path does_not_exist{tmp_name_2.get_path()}; - seqan3::output_file_validator my_validator{true}; + seqan3::output_file_validator my_validator{seqan3::output_file_open_mode::overwritable, formats}; EXPECT_NO_THROW(my_validator(does_not_exist)); } { // file has wrong format. - seqan3::output_file_validator my_validator{std::vector{std::string{"sam"}}}; + seqan3::output_file_validator my_validator{seqan3::output_file_open_mode::exclusive, + std::vector{std::string{"sam"}}}; EXPECT_THROW(my_validator(tmp_name.get_path()), seqan3::validation_error); } { // file has no extension. std::filesystem::path no_extension{tmp_name.get_path()}; no_extension.replace_extension(); - seqan3::output_file_validator my_validator{formats}; + seqan3::output_file_validator my_validator{seqan3::output_file_open_mode::exclusive, formats}; EXPECT_THROW(my_validator(no_extension), seqan3::validation_error); } { // read from file - seqan3::output_file_validator my_validator{}; + // ToDo this is should throw an error: seqan3::output_file_validator my_validator{}; + // And: seqan3::output_file_validator{}; + seqan3::output_file_validator my_validator{seqan3::output_file_open_mode::exclusive}; EXPECT_NO_THROW(my_validator(tmp_name.get_path())); } @@ -267,7 +262,8 @@ TEST(validator_test, output_file) seqan3::argument_parser parser{"test_parser", 3, argv, false}; test_accessor::set_terminal_width(parser, 80); parser.add_option(file_out_path, 'o', "out-option", "desc", - seqan3::option_spec::DEFAULT, seqan3::output_file_validator{formats}); + seqan3::option_spec::DEFAULT, + seqan3::output_file_validator{seqan3::output_file_open_mode::exclusive, formats}); EXPECT_NO_THROW(parser.parse()); EXPECT_EQ(file_out_path.string(), path); @@ -283,7 +279,8 @@ TEST(validator_test, output_file) const char * argv[] = {"./argument_parser_test", path.c_str(), path_3.c_str()}; seqan3::argument_parser parser{"test_parser", 3, argv, false}; test_accessor::set_terminal_width(parser, 80); - parser.add_positional_option(output_files, "desc", seqan3::output_file_validator{formats}); + parser.add_positional_option(output_files, "desc", + seqan3::output_file_validator{seqan3::output_file_open_mode::exclusive, formats}); EXPECT_NO_THROW(parser.parse()); EXPECT_EQ(output_files.size(), 2u); @@ -297,7 +294,8 @@ TEST(validator_test, output_file) const char * argv[] = {"./argument_parser_test", "-h"}; seqan3::argument_parser parser{"test_parser", 2, argv, false}; test_accessor::set_terminal_width(parser, 80); - parser.add_positional_option(path, "desc", seqan3::output_file_validator{formats}); + parser.add_positional_option(path, "desc", + seqan3::output_file_validator{seqan3::output_file_open_mode::exclusive, formats}); testing::internal::CaptureStdout(); EXPECT_EXIT(parser.parse(), ::testing::ExitedWithCode(EXIT_SUCCESS), ""); @@ -322,7 +320,9 @@ TEST(validator_test, output_file) const char * argv[] = {"./argument_parser_test", "-h"}; seqan3::argument_parser parser{"test_parser", 2, argv, false}; test_accessor::set_terminal_width(parser, 80); - parser.add_positional_option(path, "desc", seqan3::output_file_validator{formats, true}); + parser.add_positional_option(path, "desc", + seqan3::output_file_validator{seqan3::output_file_open_mode::overwritable, + formats}); testing::internal::CaptureStdout(); EXPECT_EXIT(parser.parse(), ::testing::ExitedWithCode(EXIT_SUCCESS), ""); @@ -345,16 +345,20 @@ 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. - seqan3::output_file_validator validator{}; - EXPECT_EQ(validator.get_help_page_message(), "The output file must not exist already and write permissions must " + seqan3::output_file_validator validator1{seqan3::output_file_open_mode::exclusive}; + 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]."); - // EXPECT_EQ(validator.get_help_page_message(), "Write permissions must be granted. Valid file extensions are: [fa, " - // "fasta, sam, bam]."); - seqan3::output_file_validator validator2{}; - EXPECT_EQ(validator2.get_help_page_message(), "The output file must not exist already and write permissions must " + seqan3::output_file_validator validator2{seqan3::output_file_open_mode::overwritable}; + EXPECT_EQ(validator2.get_help_page_message(), "Write permissions must be granted. Valid file extensions are: [fa, " + "fasta, sam, bam]."); + + seqan3::output_file_validator validator3{seqan3::output_file_open_mode::exclusive}; + EXPECT_EQ(validator3.get_help_page_message(), "The output file must not exist already and write permissions must " "be granted."); - // EXPECT_EQ(validator2.get_help_page_message(), "Write permissions must be granted."); + + seqan3::output_file_validator validator4{seqan3::output_file_open_mode::overwritable}; + EXPECT_EQ(validator4.get_help_page_message(), "Write permissions must be granted."); } TEST(validator_test, input_directory) @@ -437,7 +441,8 @@ TEST(validator_test, output_directory) seqan3::argument_parser parser{"test_parser", 3, argv, false}; test_accessor::set_terminal_width(parser, 80); parser.add_option(dir_out_path, 'o', "output-option", "desc", - seqan3::option_spec::DEFAULT, seqan3::output_directory_validator{}); + seqan3::option_spec::DEFAULT, + seqan3::output_directory_validator{}); EXPECT_NO_THROW(parser.parse()); EXPECT_EQ(path, dir_out_path.string()); @@ -449,7 +454,8 @@ TEST(validator_test, output_directory) const char * argv[] = {"./argument_parser_test", "-h"}; seqan3::argument_parser parser{"test_parser", 2, argv, false}; test_accessor::set_terminal_width(parser, 80); - parser.add_positional_option(path, "desc", seqan3::output_directory_validator{}); + parser.add_positional_option(path, "desc", + seqan3::output_directory_validator{}); testing::internal::CaptureStdout(); EXPECT_EXIT(parser.parse(), ::testing::ExitedWithCode(EXIT_SUCCESS), ""); @@ -555,7 +561,7 @@ TEST(validator_test, outputfile_not_writable) seqan3::test::tmp_filename tmp_name{"my_file.test"}; std::filesystem::path tmp_file{tmp_name.get_path()}; - EXPECT_NO_THROW(seqan3::output_file_validator{}(tmp_file)); + EXPECT_NO_THROW(seqan3::output_file_validator{seqan3::output_file_open_mode::exclusive}(tmp_file)); // Parent path is not writable. std::filesystem::permissions(tmp_file.parent_path(), @@ -565,7 +571,8 @@ TEST(validator_test, outputfile_not_writable) if (!write_access(tmp_file)) { - EXPECT_THROW(seqan3::output_file_validator{}(tmp_file), seqan3::validation_error); + EXPECT_THROW(seqan3::output_file_validator{seqan3::output_file_open_mode::exclusive}(tmp_file), + seqan3::validation_error); } // make sure we can remove the directory. @@ -581,7 +588,7 @@ TEST(validator_test, outputdir_not_writable) seqan3::test::tmp_filename tmp_name{"dir"}; std::filesystem::path tmp_dir{tmp_name.get_path()}; - EXPECT_NO_THROW(seqan3::output_directory_validator{}(tmp_dir)); + EXPECT_NO_THROW(seqan3::output_file_validator{seqan3::output_file_open_mode::exclusive}(tmp_dir)); EXPECT_FALSE(std::filesystem::exists(tmp_dir)); // Parent path is not writable. std::filesystem::permissions(tmp_dir.parent_path(), @@ -591,7 +598,8 @@ TEST(validator_test, outputdir_not_writable) if (!write_access(tmp_dir)) { - EXPECT_THROW(seqan3::output_directory_validator{}(tmp_dir), seqan3::validation_error); + EXPECT_THROW(seqan3::output_file_validator{seqan3::output_file_open_mode::exclusive}(tmp_dir), + seqan3::validation_error); } // make sure we can remove the directory. @@ -616,7 +624,8 @@ TEST(validator_test, outputdir_not_writable) if (!write_access(tmp_dir)) { - EXPECT_THROW(seqan3::output_directory_validator{}(tmp_dir), seqan3::validation_error); + EXPECT_THROW(seqan3::output_file_validator{seqan3::output_file_open_mode::exclusive}(tmp_dir), + seqan3::validation_error); } // make sure we can remove the directory. @@ -1117,7 +1126,7 @@ TEST(validator_test, chaining_validators) std::string option_value{}; std::vector option_vector{}; seqan3::regex_validator absolute_path_validator{"(/[^/]+)+/.*\\.[^/\\.]+$"}; - seqan3::output_file_validator my_file_ext_validator{{"sa", "so"}}; + seqan3::output_file_validator my_file_ext_validator{seqan3::output_file_open_mode::exclusive, {"sa", "so"}}; seqan3::test::tmp_filename tmp_name{"file.sa"}; std::filesystem::path invalid_extension{tmp_name.get_path()}; @@ -1169,7 +1178,7 @@ TEST(validator_test, chaining_validators) parser.add_option(option_value, 's', "string-option", "desc", seqan3::option_spec::DEFAULT, seqan3::regex_validator{"(/[^/]+)+/.*\\.[^/\\.]+$"} | - seqan3::output_file_validator{{"sa", "so"}}); + seqan3::output_file_validator{seqan3::output_file_open_mode::exclusive, {"sa", "so"}}); testing::internal::CaptureStderr(); EXPECT_NO_THROW(parser.parse()); @@ -1186,7 +1195,7 @@ TEST(validator_test, chaining_validators) parser.add_option(option_value, 's', "string-option", "desc", seqan3::option_spec::DEFAULT, seqan3::regex_validator{"(/[^/]+)+/.*\\.[^/\\.]+$"} | - seqan3::output_file_validator{{"sa", "so"}} | + seqan3::output_file_validator{seqan3::output_file_open_mode::exclusive, {"sa", "so"}} | seqan3::regex_validator{".*"}); testing::internal::CaptureStderr(); @@ -1204,7 +1213,7 @@ TEST(validator_test, chaining_validators) parser.add_option(option_value, 's', "string-option", "desc", seqan3::option_spec::DEFAULT, seqan3::regex_validator{"(/[^/]+)+/.*\\.[^/\\.]+$"} | - seqan3::output_file_validator{{"sa", "so"}} | + seqan3::output_file_validator{seqan3::output_file_open_mode::exclusive, {"sa", "so"}} | seqan3::regex_validator{".*"}); testing::internal::CaptureStdout(); @@ -1233,7 +1242,7 @@ TEST(validator_test, chaining_validators) parser.add_option(option_value, 's', "string-option", "desc", seqan3::option_spec::DEFAULT, seqan3::regex_validator{"(/[^/]+)+/.*\\.[^/\\.]+$"} | - seqan3::output_file_validator{{"sa", "so"}, true} | + seqan3::output_file_validator{seqan3::output_file_open_mode::overwritable, {"sa", "so"}} | seqan3::regex_validator{".*"}); testing::internal::CaptureStdout(); @@ -1261,8 +1270,8 @@ TEST(validator_test, chaining_validators) test_accessor::set_terminal_width(parser, 80); parser.add_option(option_list_value, 's', "string-option", "desc", seqan3::option_spec::DEFAULT, - seqan3::regex_validator{"(/[^/]+)+/.*\\.[^/\\.]+$"} | seqan3::output_file_validator{{"sa", - "so"}}); + seqan3::regex_validator{"(/[^/]+)+/.*\\.[^/\\.]+$"} | + seqan3::output_file_validator{seqan3::output_file_open_mode::exclusive, {"sa", "so"}}); testing::internal::CaptureStderr(); EXPECT_NO_THROW(parser.parse());