Skip to content

Commit

Permalink
Merge pull request #1304 from marehr/fix_visibility_errors_argument_p…
Browse files Browse the repository at this point in the history
…arser

[FIX] visibility errors on gcc - argument_parser
  • Loading branch information
smehringer committed Oct 28, 2019
2 parents a3828f1 + b06636a commit 1083e5a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 10 deletions.
4 changes: 4 additions & 0 deletions include/seqan3/argument_parser/argument_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <seqan3/argument_parser/detail/version_check.hpp>
#include <seqan3/core/char_operations/predicate.hpp>
#include <seqan3/core/detail/terminal.hpp>
#include <seqan3/core/detail/test_accessor.hpp>
#include <seqan3/core/detail/to_string.hpp>
#include <seqan3/io/stream/concept.hpp>

Expand Down Expand Up @@ -536,6 +537,9 @@ 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.
friend struct ::seqan3::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
26 changes: 26 additions & 0 deletions include/seqan3/core/detail/test_accessor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// -----------------------------------------------------------------------------------------------------
// Copyright (c) 2006-2019, Knut Reinert & Freie Universität Berlin
// Copyright (c) 2016-2019, 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/seqan3/blob/master/LICENSE.md
// -----------------------------------------------------------------------------------------------------

/*!\file
* \brief Forward declares seqan3::detail::test_accessor.
* \author Marcel Ehrhardt <marcel.ehrhardt AT fu-berlin.de>
*/

#pragma once

#include <seqan3/core/platform.hpp>

namespace seqan3::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;

} // seqan3::detail
36 changes: 26 additions & 10 deletions test/unit/argument_parser/detail/version_check_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ using namespace seqan3;
// test fixtures
//------------------------------------------------------------------------------

namespace seqan3::detail
{
struct test_accessor
{
static auto & version_check_future(argument_parser & parser)
{
return parser.version_check_future;
}
};
} // seqan3::detail

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

if (future.valid())
return future.get();
return false;
}

struct version_check : public ::testing::Test
{
char const * const OPTION_VERSION_CHECK = "--version-check";
Expand Down Expand Up @@ -71,8 +91,7 @@ struct version_check : public ::testing::Test

// call future.get() to artificially wait for the thread to finish and avoid
// any interference with following tests
if (parser.version_check_future.valid())
app_call_succeeded = parser.version_check_future.get();
app_call_succeeded = wait_for(parser);

if (env != nullptr)
setenv("SEQAN3_NO_VERSION_CHECK", env, 1);
Expand Down Expand Up @@ -238,8 +257,9 @@ TEST_F(version_check, environment_variable_set)
std::string out = testing::internal::GetCapturedStdout();
std::string err = testing::internal::GetCapturedStderr();

if (parser.version_check_future.valid())
parser.version_check_future.get();
// call future.get() to artificially wait for the thread to finish and avoid
// any interference with following tests
wait_for(parser);

EXPECT_EQ(out, "");
EXPECT_EQ(err, "");
Expand Down Expand Up @@ -285,10 +305,7 @@ TEST_F(version_check, option_off)

// call future.get() to artificially wait for the thread to finish and avoid
// any interference with following tests
if (parser.version_check_future.valid())
{
EXPECT_FALSE(parser.version_check_future.get());
}
EXPECT_FALSE(wait_for(parser));

if (env != nullptr)
setenv("SEQAN3_NO_VERSION_CHECK", env, 1);
Expand Down Expand Up @@ -415,8 +432,7 @@ TEST_F(version_check, smaller_app_version_custom_url)

// call future.get() to artificially wait for the thread to finish and avoid
// any interference with following tests
if (parser.version_check_future.valid())
parser.version_check_future.get();
wait_for(parser);

EXPECT_EQ(out, "");
EXPECT_EQ(err, (detail::version_checker{APP_NAME, parser.info.version, parser.info.url}.message_app_update));
Expand Down

0 comments on commit 1083e5a

Please sign in to comment.