Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove "#define private public" from tests #2352

Merged
merged 1 commit into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ doctest:
# -Wno-documentation-unknown-command: code uses user-defined commands like @complexity
# -Wno-exit-time-destructors: warning in json code triggered by NLOHMANN_JSON_SERIALIZE_ENUM
# -Wno-float-equal: not all comparisons in the tests can be replaced by Approx
# -Wno-keyword-macro: unit-tests use "#define private public"
# -Wno-missing-prototypes: for NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE
# -Wno-padded: padding is nothing to warn about
# -Wno-range-loop-analysis: items tests "for(const auto i...)"
Expand All @@ -98,7 +97,6 @@ pedantic_clang:
-Wno-documentation-unknown-command \
-Wno-exit-time-destructors \
-Wno-float-equal \
-Wno-keyword-macro \
-Wno-missing-prototypes \
-Wno-padded \
-Wno-range-loop-analysis \
Expand Down
4 changes: 2 additions & 2 deletions include/nlohmann/detail/iterators/iter_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class iter_impl
return *this;
}

private:
JSON_PRIVATE_UNLESS_TESTED:
/*!
@brief set the iterator to the first value
@pre The iterator is initialized; i.e. `m_object != nullptr`.
Expand Down Expand Up @@ -627,7 +627,7 @@ class iter_impl
return operator*();
}

private:
JSON_PRIVATE_UNLESS_TESTED:
/// associated JSON instance
pointer m_object = nullptr;
/// the actual iterator of the associated instance
Expand Down
1 change: 1 addition & 0 deletions include/nlohmann/detail/iterators/primitive_iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class primitive_iterator_t
static constexpr difference_type begin_value = 0;
static constexpr difference_type end_value = begin_value + 1;

JSON_PRIVATE_UNLESS_TESTED:
/// iterator as signed integer type
difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)();

Expand Down
4 changes: 4 additions & 0 deletions include/nlohmann/detail/json_pointer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ class json_pointer
return static_cast<size_type>(res);
}

JSON_PRIVATE_UNLESS_TESTED:
json_pointer top() const
{
if (JSON_HEDLEY_UNLIKELY(empty()))
Expand All @@ -387,6 +388,7 @@ class json_pointer
return result;
}

private:
/*!
@brief create and return a reference to the pointed to value

Expand Down Expand Up @@ -823,6 +825,7 @@ class json_pointer
{}
}

JSON_PRIVATE_UNLESS_TESTED:
/// escape "~" to "~0" and "/" to "~1"
static std::string escape(std::string s)
{
Expand All @@ -838,6 +841,7 @@ class json_pointer
replace_substring(s, "~0", "~");
}

private:
/*!
@param[in] reference_string the reference string to the current value
@param[in] value the value to consider
Expand Down
7 changes: 7 additions & 0 deletions include/nlohmann/detail/macro_scope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@
#define JSON_ASSERT(x) assert(x)
#endif

// allow to access some private functions (needed by the test suite)
#if defined(JSON_TESTS_PRIVATE)
#define JSON_PRIVATE_UNLESS_TESTED public
#else
#define JSON_PRIVATE_UNLESS_TESTED private
#endif

/*!
@brief macro to briefly define a mapping between an enum and JSON
@def NLOHMANN_JSON_SERIALIZE_ENUM
Expand Down
1 change: 1 addition & 0 deletions include/nlohmann/detail/macro_unscope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#undef JSON_CATCH
#undef JSON_THROW
#undef JSON_TRY
#undef JSON_PRIVATE_UNLESS_TESTED
#undef JSON_HAS_CPP_14
#undef JSON_HAS_CPP_17
#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
Expand Down
3 changes: 2 additions & 1 deletion include/nlohmann/detail/output/serializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ class serializer
}
}

private:
JSON_PRIVATE_UNLESS_TESTED:
/*!
@brief dump escaped string

Expand Down Expand Up @@ -625,6 +625,7 @@ class serializer
}
}

private:
/*!
@brief count digits

Expand Down
7 changes: 6 additions & 1 deletion include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ class basic_json
/// workaround type for MSVC
using basic_json_t = NLOHMANN_BASIC_JSON_TPL;

JSON_PRIVATE_UNLESS_TESTED:
// convenience aliases for types residing in namespace detail;
using lexer = ::nlohmann::detail::lexer_base<basic_json>;

Expand All @@ -204,6 +205,7 @@ class basic_json
std::move(cb), allow_exceptions, ignore_comments);
}

private:
using primitive_iterator_t = ::nlohmann::detail::primitive_iterator_t;
template<typename BasicJsonType>
using internal_iterator = ::nlohmann::detail::internal_iterator<BasicJsonType>;
Expand All @@ -220,6 +222,7 @@ class basic_json
using binary_reader = ::nlohmann::detail::binary_reader<basic_json, InputType>;
template<typename CharType> using binary_writer = ::nlohmann::detail::binary_writer<basic_json, CharType>;

JSON_PRIVATE_UNLESS_TESTED:
using serializer = ::nlohmann::detail::serializer<basic_json>;

public:
Expand Down Expand Up @@ -934,6 +937,7 @@ class basic_json
// JSON value storage //
////////////////////////

JSON_PRIVATE_UNLESS_TESTED:
/*!
@brief a JSON value

Expand Down Expand Up @@ -1210,6 +1214,7 @@ class basic_json
}
};

private:
/*!
@brief checks the class invariants

Expand Down Expand Up @@ -6947,7 +6952,7 @@ class basic_json
}


private:
JSON_PRIVATE_UNLESS_TESTED:
//////////////////////
// member variables //
//////////////////////
Expand Down
27 changes: 23 additions & 4 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2100,6 +2100,13 @@ JSON_HEDLEY_DIAGNOSTIC_POP
#define JSON_ASSERT(x) assert(x)
#endif

// allow to access some private functions (needed by the test suite)
#if defined(JSON_TESTS_PRIVATE)
#define JSON_PRIVATE_UNLESS_TESTED public
#else
#define JSON_PRIVATE_UNLESS_TESTED private
#endif

/*!
@brief macro to briefly define a mapping between an enum and JSON
@def NLOHMANN_JSON_SERIALIZE_ENUM
Expand Down Expand Up @@ -10642,6 +10649,7 @@ class primitive_iterator_t
static constexpr difference_type begin_value = 0;
static constexpr difference_type end_value = begin_value + 1;

JSON_PRIVATE_UNLESS_TESTED:
/// iterator as signed integer type
difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)();

Expand Down Expand Up @@ -10934,7 +10942,7 @@ class iter_impl
return *this;
}

private:
JSON_PRIVATE_UNLESS_TESTED:
/*!
@brief set the iterator to the first value
@pre The iterator is initialized; i.e. `m_object != nullptr`.
Expand Down Expand Up @@ -11398,7 +11406,7 @@ class iter_impl
return operator*();
}

private:
JSON_PRIVATE_UNLESS_TESTED:
/// associated JSON instance
pointer m_object = nullptr;
/// the actual iterator of the associated instance
Expand Down Expand Up @@ -11913,6 +11921,7 @@ class json_pointer
return static_cast<size_type>(res);
}

JSON_PRIVATE_UNLESS_TESTED:
json_pointer top() const
{
if (JSON_HEDLEY_UNLIKELY(empty()))
Expand All @@ -11925,6 +11934,7 @@ class json_pointer
return result;
}

private:
/*!
@brief create and return a reference to the pointed to value

Expand Down Expand Up @@ -12361,6 +12371,7 @@ class json_pointer
{}
}

JSON_PRIVATE_UNLESS_TESTED:
/// escape "~" to "~0" and "/" to "~1"
static std::string escape(std::string s)
{
Expand All @@ -12376,6 +12387,7 @@ class json_pointer
replace_substring(s, "~0", "~");
}

private:
/*!
@param[in] reference_string the reference string to the current value
@param[in] value the value to consider
Expand Down Expand Up @@ -15801,7 +15813,7 @@ class serializer
}
}

private:
JSON_PRIVATE_UNLESS_TESTED:
/*!
@brief dump escaped string

Expand Down Expand Up @@ -16064,6 +16076,7 @@ class serializer
}
}

private:
/*!
@brief count digits

Expand Down Expand Up @@ -16682,6 +16695,7 @@ class basic_json
/// workaround type for MSVC
using basic_json_t = NLOHMANN_BASIC_JSON_TPL;

JSON_PRIVATE_UNLESS_TESTED:
// convenience aliases for types residing in namespace detail;
using lexer = ::nlohmann::detail::lexer_base<basic_json>;

Expand All @@ -16697,6 +16711,7 @@ class basic_json
std::move(cb), allow_exceptions, ignore_comments);
}

private:
using primitive_iterator_t = ::nlohmann::detail::primitive_iterator_t;
template<typename BasicJsonType>
using internal_iterator = ::nlohmann::detail::internal_iterator<BasicJsonType>;
Expand All @@ -16713,6 +16728,7 @@ class basic_json
using binary_reader = ::nlohmann::detail::binary_reader<basic_json, InputType>;
template<typename CharType> using binary_writer = ::nlohmann::detail::binary_writer<basic_json, CharType>;

JSON_PRIVATE_UNLESS_TESTED:
using serializer = ::nlohmann::detail::serializer<basic_json>;

public:
Expand Down Expand Up @@ -17427,6 +17443,7 @@ class basic_json
// JSON value storage //
////////////////////////

JSON_PRIVATE_UNLESS_TESTED:
/*!
@brief a JSON value

Expand Down Expand Up @@ -17703,6 +17720,7 @@ class basic_json
}
};

private:
/*!
@brief checks the class invariants

Expand Down Expand Up @@ -23440,7 +23458,7 @@ class basic_json
}


private:
JSON_PRIVATE_UNLESS_TESTED:
//////////////////////
// member variables //
//////////////////////
Expand Down Expand Up @@ -25296,6 +25314,7 @@ inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std
#undef JSON_CATCH
#undef JSON_THROW
#undef JSON_TRY
#undef JSON_PRIVATE_UNLESS_TESTED
#undef JSON_HAS_CPP_14
#undef JSON_HAS_CPP_17
#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
Expand Down
3 changes: 1 addition & 2 deletions test/src/unit-allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ SOFTWARE.

#include "doctest_compatibility.h"

#define private public
#define JSON_TESTS_PRIVATE
#include <nlohmann/json.hpp>
using nlohmann::json;
#undef private

namespace
{
Expand Down
3 changes: 1 addition & 2 deletions test/src/unit-class_const_iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ SOFTWARE.

#include "doctest_compatibility.h"

#define private public
#define JSON_TESTS_PRIVATE
#include <nlohmann/json.hpp>
using nlohmann::json;
#undef private

TEST_CASE("const_iterator class")
{
Expand Down
3 changes: 1 addition & 2 deletions test/src/unit-class_iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ SOFTWARE.

#include "doctest_compatibility.h"

#define private public
#define JSON_TESTS_PRIVATE
#include <nlohmann/json.hpp>
using nlohmann::json;
#undef private

TEST_CASE("iterator class")
{
Expand Down
3 changes: 1 addition & 2 deletions test/src/unit-class_lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ SOFTWARE.

#include "doctest_compatibility.h"

#define private public
#define JSON_TESTS_PRIVATE
#include <nlohmann/json.hpp>
using nlohmann::json;
#undef private

namespace
{
Expand Down
3 changes: 1 addition & 2 deletions test/src/unit-class_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ SOFTWARE.

#include "doctest_compatibility.h"

#define private public
#define JSON_TESTS_PRIVATE
#include <nlohmann/json.hpp>
using nlohmann::json;
#undef private

#include <valarray>

Expand Down
3 changes: 1 addition & 2 deletions test/src/unit-constructor1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ SOFTWARE.
#include "doctest_compatibility.h"
DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal")

#define private public
#define JSON_TESTS_PRIVATE
#include <nlohmann/json.hpp>
using nlohmann::json;
#undef private

#include <deque>
#include <forward_list>
Expand Down
3 changes: 1 addition & 2 deletions test/src/unit-convenience.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ SOFTWARE.

#include "doctest_compatibility.h"

#define private public
#define JSON_TESTS_PRIVATE
#include <nlohmann/json.hpp>
using nlohmann::json;
#undef private

#include <sstream>

Expand Down
Loading