Skip to content

Commit 8e63250

Browse files
author
John McFarlane
committed
Add unit testing 'framework'
- Replace cnl::_impl::identical with test-local equivalanet - Remove cnl::_impl::assert_same entirely
1 parent 6d23474 commit 8e63250

108 files changed

Lines changed: 200 additions & 439 deletions

File tree

Some content is hidden

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

include/cnl/_impl/type_traits/assert_same.h

Lines changed: 0 additions & 22 deletions
This file was deleted.

include/cnl/_impl/type_traits/identical.h

Lines changed: 0 additions & 26 deletions
This file was deleted.

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 25 additions & 0 deletions
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

Lines changed: 2 additions & 13 deletions
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

Lines changed: 1 addition & 5 deletions
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 1 addition & 5 deletions
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(

0 commit comments

Comments
 (0)