Skip to content

Commit f61f66b

Browse files
author
John McFarlane
committed
Add unit testing 'framework'
- Wrapper around GTest which better unifies static and dynamic tests
1 parent 6d23474 commit f61f66b

File tree

107 files changed

+188
-401
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+188
-401
lines changed

include/cnl/_impl/type_traits/identical.h

-26
This file was deleted.

test/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ if (${GTest_FOUND})
5252
# workaround for github.com/conan-io/conan-center-index/issues/3222
5353
set(CNL_GTEST_MAIN_TARGET GTest::Main CACHE STRING "alternative GTest target name")
5454

55+
add_subdirectory(framework)
5556
add_subdirectory(unit)
5657
else ()
5758
message(STATUS "Google Test is required to build unit tests.")

test/framework/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# test framework
2+
3+
add_library(cnl_test INTERFACE)
4+
target_include_directories(cnl_test INTERFACE "${CMAKE_CURRENT_LIST_DIR}")
5+
target_link_libraries(cnl_test INTERFACE ${CNL_GTEST_MAIN_TARGET})

test/framework/test.h

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
// Copyright John McFarlane 2022.
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// (See accompanying file ../LICENSE_1_0.txt or copy at
5+
// http://www.boost.org/LICENSE_1_0.txt)
6+
7+
/// \file
8+
/// \brief definitions of use in tests
9+
10+
#if !defined(CNL_TEST_FRAMEWORK_TEST_H)
11+
#define CNL_TEST_FRAMEWORK_TEST_H
12+
13+
#include <gtest/gtest.h>
14+
15+
#include <type_traits>
16+
17+
// cnl::_impl::identical - compiles iff same type; returns true iff equal
18+
template<class A, class B>
19+
[[nodiscard]] constexpr auto identical(A const& a, B const& b)
20+
{
21+
static_assert(std::is_same<A, B>::value, "different types");
22+
return a == b;
23+
}
24+
25+
#endif // CNL_TEST_FRAMEWORK_TEST_H

test/unit/CMakeLists.txt

+2-13
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,6 @@ set(sample_sources
138138

139139
find_package(Boost 1.71.0)
140140

141-
######################################################################
142-
# add_gtest_dependency
143-
144-
function(add_gtest_dependency target)
145-
target_link_libraries("${target}" ${CNL_GTEST_MAIN_TARGET})
146-
endfunction(add_gtest_dependency)
147-
148141
######################################################################
149142
# add test-unit target
150143

@@ -155,9 +148,8 @@ add_dependencies(test-all test-unit)
155148
# test plain - the all.cpp project with *no* tests of compiler flags
156149

157150
add_executable(test-unit-plain all.cpp)
158-
target_link_libraries(test-unit-plain Cnl)
151+
target_link_libraries(test-unit-plain Cnl cnl_test)
159152
add_test(test-unit-plain "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-unit-plain")
160-
add_gtest_dependency(test-unit-plain)
161153
add_dependencies(test-unit test-unit-plain)
162154

163155
######################################################################
@@ -175,12 +167,9 @@ function(make_test source compile_flags)
175167
add_executable("${target}" "${source}")
176168
target_include_directories("${target}" PRIVATE "${CMAKE_CURRENT_LIST_DIR}")
177169
set_target_properties("${target}" PROPERTIES COMPILE_FLAGS "${compile_flags}")
178-
target_link_libraries("${target}" Cnl)
170+
target_link_libraries("${target}" Cnl cnl_test)
179171
add_test("${target}" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${target}")
180172

181-
# Google Test dependency
182-
add_gtest_dependency("${target}")
183-
184173
# Boost dependency
185174
if(Boost_FOUND)
186175
target_compile_definitions("${target}" PRIVATE "-DCNL_BOOST_ENABLED")

test/unit/_impl/charconv/to_chars.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,11 @@
66

77
#include <cnl/_impl/charconv/to_chars.h>
88

9-
#include <cnl/_impl/type_traits/identical.h>
10-
11-
#include <gtest/gtest.h>
9+
#include <test.h>
1210

1311
#include <cstdint>
1412
#include <limits>
1513

16-
using cnl::_impl::identical;
17-
1814
#if !defined(_MSC_VER)
1915
namespace {
2016
static_assert(identical(

test/unit/_impl/cmath/abs.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99

1010
#include <cnl/_impl/cmath/abs.h>
1111

12-
#include <cnl/_impl/type_traits/identical.h>
1312
#include <cnl/cstdint.h>
14-
15-
using cnl::_impl::identical;
13+
#include <test.h>
1614

1715
namespace test_abs {
1816
static_assert(identical(cnl::_impl::abs(-302398479), 302398479));

test/unit/_impl/cmath/sqrt.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66

77
#include <cnl/_impl/cmath/sqrt.h>
88

9-
#include <cnl/_impl/type_traits/identical.h>
10-
11-
using cnl::_impl::identical;
9+
#include <test.h>
1210

1311
static_assert(identical(0xffffffffLLU, cnl::sqrt(0xfffffffe00000001LLU)));
1412
static_assert(identical(0xfffffffeLLU, cnl::sqrt(0xfffffffe00000000LLU)));

test/unit/_impl/duplex_int/definition.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,10 @@
1313
#include <cnl/_impl/duplex_integer/operators.h>
1414
#include <cnl/cstdint.h>
1515

16-
#include <cnl/_impl/type_traits/identical.h>
17-
18-
#include <gtest/gtest.h>
16+
#include <test.h>
1917

2018
#include <limits>
2119

22-
using cnl::_impl::identical;
23-
2420
namespace {
2521
namespace test_ctor {
2622
static_assert(

test/unit/_impl/duplex_int/digits.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
#include <cnl/_impl/duplex_integer/digits.h>
1111

12-
#include <cnl/_impl/type_traits/identical.h>
13-
14-
using cnl::_impl::identical;
12+
#include <test.h>
1513

1614
namespace {
1715
static_assert(

test/unit/_impl/duplex_int/from_value.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@
1010
#include <cnl/_impl/duplex_integer/from_value.h>
1111

1212
#include <cnl/_impl/duplex_integer.h>
13-
#include <cnl/_impl/type_traits/identical.h>
1413
#include <cnl/cstdint.h>
15-
16-
using cnl::_impl::identical;
14+
#include <test.h>
1715

1816
using duplex_63_int = cnl::_impl::duplex_integer<std::int32_t, std::uint32_t>;
1917
using duplex_127_int = cnl::_impl::duplex_integer<

test/unit/_impl/duplex_int/numeric_limits.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@
1111
#include <cnl/_impl/duplex_integer/numeric_limits.h>
1212
#include <cnl/_impl/duplex_integer/operators.h>
1313

14-
#include <cnl/_impl/type_traits/identical.h>
14+
#include <test.h>
1515

1616
#include <limits>
1717

18-
using cnl::_impl::identical;
19-
2018
namespace {
2119
namespace test_is_specialize {
2220
static_assert(

test/unit/_impl/duplex_int/operators.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@
1010
#include <cnl/_impl/duplex_integer/ctors.h>
1111
#include <cnl/_impl/duplex_integer/operators.h>
1212

13-
#include <cnl/_impl/type_traits/identical.h>
14-
15-
#include <gtest/gtest.h>
16-
17-
using cnl::_impl::identical;
13+
#include <test.h>
1814

1915
namespace {
2016
namespace test_not {

test/unit/_impl/elastic_int/sqrt.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88

99
#include <cnl/elastic_integer.h>
1010

11-
#include <cnl/_impl/type_traits/identical.h>
11+
#include <test.h>
1212

13-
using cnl::_impl::identical;
1413
using namespace cnl::literals;
1514

1615
static_assert(identical(

test/unit/_impl/num_traits/max_digits.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66

77
#include <cnl/_impl/config.h>
88
#include <cnl/_impl/num_traits/max_digits.h>
9-
#include <cnl/_impl/type_traits/identical.h>
9+
#include <test.h>
1010

1111
namespace {
12-
using cnl::_impl::identical;
13-
1412
#if defined(CNL_INT128_ENABLED)
1513
static_assert(
1614
identical(cnl::_impl::max_digits<std::uint8_t>, 128), "cnl::_impl::max_digits<>");

test/unit/_impl/ostream.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#include <cnl/_impl/ostream.h>
1111

12-
#include <gtest/gtest.h>
12+
#include <test.h>
1313

1414
#include <limits>
1515

test/unit/_impl/overflow/is_overflow.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// http://www.boost.org/LICENSE_1_0.txt)
66

77
#include <cnl/_impl/overflow/is_overflow.h>
8-
#include <cnl/_impl/type_traits/identical.h>
8+
#include <test.h>
99

1010
#include <limits>
1111

test/unit/_impl/rounding/convert_operator.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
/// \brief tests for <cnl/_impl/rounding/convert.h>
88

99
#include <cnl/_impl/rounding/convert_operator.h>
10-
#include <cnl/_impl/type_traits/identical.h>
1110
#include <cnl/elastic_scaled_integer.h>
1211
#include <cnl/scaled_integer.h>
13-
14-
using cnl::_impl::identical;
12+
#include <test.h>
1513

1614
namespace test_convert_nearest_rounding_native_datatypes {
1715

@@ -123,7 +121,7 @@ namespace test_convert_tie_to_pos_inf_rounding_native_datatypes {
123121

124122
namespace test_convert_native_rounding {
125123
static_assert(
126-
cnl::_impl::identical(
124+
identical(
127125
short{3},
128126
cnl::custom_operator<
129127
cnl::_impl::convert_op,

test/unit/_impl/wide-integer.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
#include <cnl/_impl/num_traits/rounding.h>
1010
#include <cnl/_impl/rounding/native_rounding_tag.h>
1111

12-
#include <cnl/_impl/type_traits/identical.h>
13-
14-
#include <gtest/gtest.h>
15-
16-
using cnl::_impl::identical;
12+
#include <test.h>
1713

1814
static_assert(cnl::is_integer_v<cnl::_impl::math::wide_integer::uintwide_t<64>>);
1915

test/unit/_impl/wide_int/definition.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,12 @@
99

1010
#include <cnl/_impl/wide_integer/definition.h>
1111

12-
#include <cnl/_impl/type_traits/identical.h>
1312
#include <cnl/cstdint.h>
1413
#include <cnl/wide_integer.h>
15-
16-
#include <gtest/gtest.h>
14+
#include <test.h>
1715

1816
#include <type_traits>
1917

20-
using cnl::_impl::identical;
21-
2218
namespace {
2319
namespace test_parameters {
2420
static_assert(

test/unit/_impl/wide_int/digits.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
#include <cnl/_impl/wide_integer/digits.h>
1111

12-
#include <cnl/_impl/type_traits/identical.h>
13-
14-
using cnl::_impl::identical;
12+
#include <test.h>
1513

1614
namespace {
1715
static_assert(

test/unit/_impl/wide_int/from_value.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99

1010
#include <cnl/wide_integer.h>
1111

12-
#include <cnl/_impl/type_traits/identical.h>
1312
#include <cnl/_impl/wide_integer/operators.h>
14-
15-
using cnl::_impl::identical;
13+
#include <test.h>
1614

1715
namespace {
1816
static_assert(

test/unit/_impl/wide_int/generic.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,9 @@
99

1010
#include <cnl/_impl/wide_tag/custom_operator.h>
1111

12-
#include <cnl/_impl/type_traits/identical.h>
1312
#include <cnl/cmath.h>
1413
#include <cnl/wide_integer.h>
15-
16-
#include <gtest/gtest.h>
17-
18-
using cnl::_impl::identical;
14+
#include <test.h>
1915

2016
namespace {
2117
TEST(wide_integer, multiply) // NOLINT

test/unit/_impl/wide_int/literals.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
#include <cnl/wide_integer.h>
1111

12-
#include <cnl/_impl/type_traits/identical.h>
13-
14-
using cnl::_impl::identical;
12+
#include <test.h>
1513

1614
namespace {
1715
namespace parse {

test/unit/_impl/wide_int/make_wide_int.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99

1010
#include <cnl/_impl/wide_integer/make_wide_integer.h>
1111

12-
#include <cnl/_impl/type_traits/identical.h>
1312
#include <cnl/_impl/wide_integer/operators.h>
14-
15-
using cnl::_impl::identical;
13+
#include <test.h>
1614

1715
namespace {
1816
static_assert(

test/unit/_impl/wide_int/numeric_limits.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,12 @@
99

1010
#include <cnl/_impl/wide_integer/numeric_limits.h>
1111

12-
#include <cnl/_impl/type_traits/identical.h>
1312
#include <cnl/wide_integer.h>
1413

15-
#include <gtest/gtest.h>
14+
#include <test.h>
1615

1716
#include <limits>
1817

19-
using cnl::_impl::identical;
20-
2118
namespace {
2219
static_assert(
2320
std::numeric_limits<cnl::wide_integer<>>::is_specialized,

test/unit/_impl/wide_int/scale.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@
1212
#include <cnl/_impl/num_traits/fixed_width_scale.h>
1313
#include <cnl/wide_integer.h>
1414

15-
#include <cnl/_impl/type_traits/identical.h>
16-
17-
#include <gtest/gtest.h>
18-
19-
using cnl::_impl::identical;
15+
#include <test.h>
2016

2117
namespace {
2218
namespace test_power_value {

0 commit comments

Comments
 (0)