Skip to content

Commit

Permalink
Merge pull request #39 from Irallia/MISC/Remove_dependency_of_seqan3_…
Browse files Browse the repository at this point in the history
…test_accessor

[MISC] Remove dependency of seqan3::detail::test_accessor.
  • Loading branch information
eseiler authored Dec 21, 2021
2 parents 4a7548e + 1a8c5c4 commit c67fef4
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 91 deletions.
4 changes: 2 additions & 2 deletions include/sharg/argument_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,8 @@ class argument_parser
//!\brief Whether the **user** specified to perform the version check (true) or not (false), default unset.
std::optional<bool> version_check_user_decision;

//!\brief Befriend seqan3::detail::test_accessor to grant access to version_check_future and format.
friend struct ::seqan3::detail::test_accessor;
//!\brief Befriend sharg::detail::test_accessor to grant access to version_check_future and format.
friend struct ::sharg::detail::test_accessor;

//!\brief The future object that keeps track of the detached version check call thread.
std::future<bool> version_check_future;
Expand Down
12 changes: 3 additions & 9 deletions include/sharg/detail/format_help.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@

#include <sharg/detail/format_base.hpp>
#include <sharg/detail/terminal.hpp>

namespace seqan3::detail
{

struct test_accessor;

} // seqan3::detail
#include <sharg/detail/test_accessor.hpp>

namespace sharg::detail
{
Expand Down Expand Up @@ -380,8 +374,8 @@ class format_help : public format_help_base<format_help>
//!\brief Needed for correct formatting while calling different print functions.
bool prev_was_paragraph{false};

//!\brief Befriend seqan3::detail::test_accessor to grant access to layout.
friend struct ::seqan3::detail::test_accessor;
//!\brief Befriend sharg::detail::test_accessor to grant access to layout.
friend struct ::sharg::detail::test_accessor;

//!\brief Stores the relevant parameters of the documentation on the screen.
console_layout_struct layout{};
Expand Down
26 changes: 26 additions & 0 deletions include/sharg/detail/test_accessor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// -----------------------------------------------------------------------------------------------------------
// Copyright (c) 2006-2021, Knut Reinert & Freie Universität Berlin
// Copyright (c) 2016-2021, Knut Reinert & MPI für molekulare Genetik
// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
// shipped with this file and also available at: https://github.com/seqan/sharg-parser/blob/master/LICENSE.md
// -----------------------------------------------------------------------------------------------------------

/*!\file
* \brief Forward declares sharg::detail::test_accessor.
* \author Lydia Buntrock <lydia.buntrock AT fu-berlin.de>
*/

#pragma once

#include <sharg/platform.hpp>

namespace sharg::detail
{

/*!\brief Attorney-Client pattern for accessing private / protected class members in test cases.
* \attention You can currently only have one definition of test_accessor in one translation unit.
* \see https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Friendship_and_the_Attorney-Client
*/
struct test_accessor;

} // sharg::detail
36 changes: 17 additions & 19 deletions test/unit/detail/format_help_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ std::string license_text()
return str.substr(license_start, license_end - license_start);
}

namespace seqan3::detail
namespace sharg::detail
{
struct test_accessor
{
Expand All @@ -68,15 +68,13 @@ struct test_accessor
}, parser.format);
}
};
} // seqan3::detail

using seqan3::detail::test_accessor;
} // sharg::detail

TEST(help_page_printing, short_help)
{
// Empty call with no options given. For sharg::detail::format_short_help
sharg::argument_parser parser0{"empty_options", 1, argv0};
test_accessor::set_terminal_width(parser0, 80);
sharg::detail::test_accessor::set_terminal_width(parser0, 80);
parser0.info.synopsis.push_back("./some_binary_name synopsis");
testing::internal::CaptureStdout();
EXPECT_EXIT(parser0.parse(), ::testing::ExitedWithCode(EXIT_SUCCESS), "");
Expand All @@ -93,7 +91,7 @@ TEST(help_page_printing, no_information)
{
// Empty help call with -h
sharg::argument_parser parser1{"test_parser", 2, argv1};
test_accessor::set_terminal_width(parser1, 80);
sharg::detail::test_accessor::set_terminal_width(parser1, 80);
testing::internal::CaptureStdout();
EXPECT_EXIT(parser1.parse(), ::testing::ExitedWithCode(EXIT_SUCCESS), "");
std_cout = testing::internal::GetCapturedStdout();
Expand All @@ -110,7 +108,7 @@ TEST(help_page_printing, with_short_copyright)
{
// Again, but with short copyright, long copyright, and citation.
sharg::argument_parser short_copy("test_parser", 2, argv1);
test_accessor::set_terminal_width(short_copy, 80);
sharg::detail::test_accessor::set_terminal_width(short_copy, 80);
short_copy.info.short_copyright = "short";
testing::internal::CaptureStdout();
EXPECT_EXIT(short_copy.parse(), ::testing::ExitedWithCode(EXIT_SUCCESS), "");
Expand All @@ -132,7 +130,7 @@ TEST(help_page_printing, with_short_copyright)
TEST(help_page_printing, with_long_copyright)
{
sharg::argument_parser long_copy("test_parser", 2, argv1);
test_accessor::set_terminal_width(long_copy, 80);
sharg::detail::test_accessor::set_terminal_width(long_copy, 80);
long_copy.info.long_copyright = "long";
testing::internal::CaptureStdout();
EXPECT_EXIT(long_copy.parse(), ::testing::ExitedWithCode(EXIT_SUCCESS), "");
Expand All @@ -154,7 +152,7 @@ TEST(help_page_printing, with_long_copyright)
TEST(help_page_printing, with_citation)
{
sharg::argument_parser citation("test_parser", 2, argv1);
test_accessor::set_terminal_width(citation, 80);
sharg::detail::test_accessor::set_terminal_width(citation, 80);
citation.info.citation = "citation";
testing::internal::CaptureStdout();
EXPECT_EXIT(citation.parse(), ::testing::ExitedWithCode(EXIT_SUCCESS), "");
Expand All @@ -176,7 +174,7 @@ TEST(help_page_printing, with_citation)
TEST(help_page_printing, with_author)
{
sharg::argument_parser author("test_parser", 2, argv1);
test_accessor::set_terminal_width(author, 80);
sharg::detail::test_accessor::set_terminal_width(author, 80);
author.info.author = "author";
testing::internal::CaptureStdout();
EXPECT_EXIT(author.parse(), ::testing::ExitedWithCode(EXIT_SUCCESS), "");
Expand All @@ -198,7 +196,7 @@ TEST(help_page_printing, with_author)
TEST(help_page_printing, with_email)
{
sharg::argument_parser email("test_parser", 2, argv1);
test_accessor::set_terminal_width(email, 80);
sharg::detail::test_accessor::set_terminal_width(email, 80);
email.info.email = "email";
testing::internal::CaptureStdout();
EXPECT_EXIT(email.parse(), ::testing::ExitedWithCode(EXIT_SUCCESS), "");
Expand All @@ -221,7 +219,7 @@ TEST(help_page_printing, empty_advanced_help)
{
// Empty help call with -hh
sharg::argument_parser parser2{"test_parser", 2, argv2};
test_accessor::set_terminal_width(parser2, 80);
sharg::detail::test_accessor::set_terminal_width(parser2, 80);
testing::internal::CaptureStdout();
EXPECT_EXIT(parser2.parse(), ::testing::ExitedWithCode(EXIT_SUCCESS), "");
std_cout = testing::internal::GetCapturedStdout();
Expand All @@ -238,7 +236,7 @@ TEST(help_page_printing, empty_version_call)
{
// Empty version call
sharg::argument_parser parser3{"test_parser", 2, argv3};
test_accessor::set_terminal_width(parser3, 80);
sharg::detail::test_accessor::set_terminal_width(parser3, 80);
testing::internal::CaptureStdout();
EXPECT_EXIT(parser3.parse(), ::testing::ExitedWithCode(EXIT_SUCCESS), "");
std_cout = testing::internal::GetCapturedStdout();
Expand All @@ -253,7 +251,7 @@ TEST(help_page_printing, version_call)
{
// Version call with url and options.
sharg::argument_parser parser4{"test_parser", 2, argv3};
test_accessor::set_terminal_width(parser4, 80);
sharg::detail::test_accessor::set_terminal_width(parser4, 80);
parser4.info.url = "https://seqan.de";
parser4.add_option(option_value, 'i', "int", "this is a int option.");
parser4.add_flag(flag_value, 'f', "flag", "this is a flag.");
Expand All @@ -275,7 +273,7 @@ TEST(help_page_printing, do_not_print_hidden_options)
{
// Add an option and request help.
sharg::argument_parser parser5{"test_parser", 2, argv1};
test_accessor::set_terminal_width(parser5, 80);
sharg::detail::test_accessor::set_terminal_width(parser5, 80);
parser5.add_option(option_value, 'i', "int", "this is a int option.", sharg::option_spec::hidden);
parser5.add_flag(flag_value, 'f', "flag", "this is a flag.", sharg::option_spec::hidden);
testing::internal::CaptureStdout();
Expand Down Expand Up @@ -325,7 +323,7 @@ TEST(help_page_printing, advanced_options)

// without -hh, only the non/advanced information are shown
sharg::argument_parser parser_normal_help{"test_parser", 2, argv1};
test_accessor::set_terminal_width(parser_normal_help, 80);
sharg::detail::test_accessor::set_terminal_width(parser_normal_help, 80);
set_up(parser_normal_help);
testing::internal::CaptureStdout();
EXPECT_EXIT(parser_normal_help.parse(), ::testing::ExitedWithCode(EXIT_SUCCESS), "");
Expand All @@ -351,7 +349,7 @@ TEST(help_page_printing, advanced_options)

// with -hh everything is shown
sharg::argument_parser parser_advanced_help{"test_parser", 2, argv2};
test_accessor::set_terminal_width(parser_advanced_help, 80);
sharg::detail::test_accessor::set_terminal_width(parser_advanced_help, 80);
set_up(parser_advanced_help);
testing::internal::CaptureStdout();
EXPECT_EXIT(parser_advanced_help.parse(), ::testing::ExitedWithCode(EXIT_SUCCESS), "");
Expand Down Expand Up @@ -407,7 +405,7 @@ TEST(help_page_printing, full_information)

// Add synopsis, description, short description, positional option, option, flag, and example.
sharg::argument_parser parser6{"test_parser", 2, argv1};
test_accessor::set_terminal_width(parser6, 80);
sharg::detail::test_accessor::set_terminal_width(parser6, 80);
parser6.info.synopsis.push_back("./some_binary_name synopsis");
parser6.info.synopsis.push_back("./some_binary_name synopsis2");
parser6.info.description.push_back("description");
Expand Down Expand Up @@ -551,7 +549,7 @@ TEST(parse_test, subcommand_argument_parser)
argv,
sharg::update_notifications::on,
{"sub1", "sub2"}};
test_accessor::set_terminal_width(top_level_parser, 80);
sharg::detail::test_accessor::set_terminal_width(top_level_parser, 80);
top_level_parser.info.description.push_back("description");
top_level_parser.add_option(option_value, 'f', "foo", "foo bar.");

Expand Down
6 changes: 3 additions & 3 deletions test/unit/detail/version_check_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// test fixtures
//------------------------------------------------------------------------------

namespace seqan3::detail
namespace sharg::detail
{
struct test_accessor
{
Expand All @@ -23,11 +23,11 @@ struct test_accessor
return parser.version_check_future;
}
};
} // seqan3::detail
} // sharg::detail

bool wait_for(sharg::argument_parser & parser)
{
auto & future = seqan3::detail::test_accessor::version_check_future(parser);
auto & future = sharg::detail::test_accessor::version_check_future(parser);

if (future.valid())
return future.get();
Expand Down
Loading

1 comment on commit c67fef4

@vercel
Copy link

@vercel vercel bot commented on c67fef4 Dec 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.