etl/test/CMakeLists.txt
John Wellbelove afa17c5042 Squashed commit of the following:
commit c5dc331004b4d9611ab996935bedada203676c71
Author: John Wellbelove <john.wellbelove@etlcpp.com>
Date:   Sat Jul 11 12:32:20 2026 +0100

    Updated release notes

commit 4bf6ed6ce8d79857658d763e368ee56617542b2c
Author: vcoselev <145198867+vcoselev@users.noreply.github.com>
Date:   Sat Jul 11 12:05:39 2026 +0100

    Fix for 1405: etl::exchange doesn't work with unique_ptr (#1477)

    * Separate bit order and endianness in bit_stream.h (#1495)

    * Factor out ranges tests from test_algorithm.cpp to test_algorithm_ranges.cpp (#1497)

    * Fix exchange to use forwarding reference (U&&) and move

    - etl::exchange was using the copy constructor. Changed for etl::move.
    - The assignment to the new object is now done with forward.
    - Added a test with unique_ptr.

    ---------

    Co-authored-by: Roland Reichwein <Roland.Reichwein@bmw.de>
    Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>

commit 2ed9019df04d470530c41c1f27d35adc30b9a32d
Author: Moritz Pflanzer <moritz@pflanzer.eu>
Date:   Fri Jul 10 11:42:32 2026 +0200

    Update operator[] docs for map class (#1499)

    * Separate bit order and endianness in bit_stream.h (#1495)

    * Update operator[] docs for map class

    No const variant is implemented for the operator[].

    ---------

    Co-authored-by: Roland Reichwein <Roland.Reichwein@bmw.de>

commit 423e18d96dc645f1c733cb0d8ae6b675b9eb7e83
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date:   Fri Jul 10 11:14:08 2026 +0200

    Factor out ranges tests from test_algorithm.cpp to test_algorithm_ranges.cpp (#1497)

commit 338bfdbb1f4df3c5c08a68a9038f13b8dae1c28b
Author: John Wellbelove <jwellbelove@users.noreply.github.com>
Date:   Fri Jul 10 10:12:04 2026 +0100

    Add coverage report to docs (#1498)

    * Updated release notes

    * Added link to coverage report

    ---------

    Co-authored-by: John Wellbelove <john.wellbelove@etlcpp.com>

commit 269025424f4c6f61cebac090f4df82985fb3b239
Merge: c004cc9d faa4c15b
Author: John Wellbelove <john.wellbelove@etlcpp.com>
Date:   Thu Jul 9 14:18:32 2026 +0100

    Merge branch 'development' of https://github.com/ETLCPP/etl into development

commit c004cc9d508efcf398630758a47aae95b37a7eb8
Author: John Wellbelove <john.wellbelove@etlcpp.com>
Date:   Thu Jul 9 10:06:17 2026 +0100

    Updated release notes

commit faa4c15b49c8ad15475c83ae23e00f5a46f803ca
Author: John Wellbelove <john.wellbelove@etlcpp.com>
Date:   Thu Jul 9 10:06:17 2026 +0100

    Updated release notes

commit 1523e63e35a15cfd1fa72d230a3c79efa7b9c3e0
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date:   Wed Jul 8 20:48:33 2026 +0200

    Support non-assignable alternatives in variant (#1496)

commit 878a0ba5a28f6b0dcae9f472a6a6a1f107de0a74
Author: John Wellbelove <john.wellbelove@etlcpp.com>
Date:   Wed Jul 8 11:07:01 2026 +0100

    Updated version and release notes

commit 5287fe4b3b9f58330881d2a62abf6ce8e1159b8d
Author: John Wellbelove <jwellbelove@users.noreply.github.com>
Date:   Wed Jul 8 09:06:50 2026 +0100

    Allow etl::vector to store pointers to functions and member functions (#1492)

    * Refactored vector.h

    Deleted ivectorpointer.h

    * Minor changes

    * Fixed code incompatible with C++03

    * Clang-format changes

    * Removed redundant double-qualified name

    * Fixed is_is_object_pointer_v to is_object_pointer_v

    * Added new test files to meson.build

    * Added overflow checks to vector_ext copy and move constructors and assignments

    Added assert throw tests.

    * Added diagnostic pushes to eliminate GCC warning false positives

    * Changed the GCC C++23 Github action to use GCC14

    * Applied clang-format

    * Added guard to pop_heap

    * Added guard to adjust_heap

    * Attempt to fix GCC diagnostic

    * Attempt to fix GCC diagnostic

    Re-enable ranges algorithm tests

    * Attempt to fix GCC diagnostic

    Re-enable ranges algorithm tests

    * clang-format

    * Attempt to fix GCC diagnostic

    Re-enable ranges algorithm tests

    * Attempt to fix GCC diagnostic

    Re-enable ranges algorithm tests

    * Attempt to fix GCC diagnostic

    Re-enable ranges algorithm tests

    * Missing newline at end of file

    * Attempt to fix GCC diagnostic

    Re-enable ranges algorithm tests

    * Attempt to fix GCC diagnostic

    Re-enable ranges algorithm tests

    * Attempt to fix GCC diagnostic

    Re-enable ranges algorithm tests

    * Attempt to fix GCC diagnostic

    Re-enable ranges algorithm tests

    * Attempt to fix GCC diagnostic

    * clang-format

    * Changed gcc --version to gcc-14 --version

    ---------

    Co-authored-by: John Wellbelove <john.wellbelove@etlcpp.com>
    Co-authored-by: Roland Reichwein <Roland.Reichwein@bmw.de>

commit 40dddd7f9601985ae7350e60a404af9028bc9fe9
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date:   Tue Jul 7 23:41:17 2026 +0200

    Add optional etl_profile label_flag for Bazel profile injection (#1491)

    Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>

commit 84fca4cd62f72c382c062376ca934803116a20d5
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date:   Tue Jul 7 21:45:47 2026 +0200

    Add missing memory functions, according the standard (#1490)

    Adding:

    - etl::align
    - etl::assume_aligned
    - etl::is_sufficiently_aligned
    - etl::launder
    - etl::pointer_traits
    - etl::start_lifetime_as

    Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>

commit dca6653b3759b2cdc79307fec7425589feea478d
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date:   Tue Jul 7 21:00:09 2026 +0200

    Add missing interfaces to etl::chrono (#1489)

    Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>

commit c52b2ac7b1f675e6b1d34052239423b7f3634033
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date:   Tue Jul 7 18:06:05 2026 +0200

    Fix etl::mem_cast cross-size copy constructor and assignment (#1488)

    The templated cross-size copy constructor and assignment operator were
    broken in two ways:

    - They accessed other.buffer / rhs.buffer, which is private in a
      different mem_cast instantiation, so the cross-size overloads failed
      to compile whenever they were actually instantiated.
    - They copied Size_ (the destination size) bytes from a source buffer
      that is only Other_Size bytes large, reading past the end of the
      source when the destination was larger.

    Use the public data() accessor and copy Other_Size bytes. The existing
    static_assert(Size >= Other_Size) guarantees the destination is big
    enough.

    Add test_mem_cast_copy_and_assign_from_smaller regression test.

    Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>

commit 165674cb23dda1fd4f7e5a1182f49554a796bfe8
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date:   Tue Jul 7 16:41:50 2026 +0200

    Fix etl::pearson::reset() not resetting the first-byte flag (#1487)

    reset() cleared the hash array but left the `first` flag false, so a
    calculator reused after reset() took the XOR update path on its next
    add() instead of the initialisation path. This produced an incorrect
    hash for any pearson object that was reset and reused.

    Reset `first` to true in reset() so a reset calculator behaves like a
    freshly constructed one.

    Add test_pearson_reset regression test.

    Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>

commit 032ec4cc80f1c0f1baa0383bdbc5f9239b68f268
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date:   Tue Jul 7 13:40:04 2026 +0200

    Fix etl::bitset single-element from_string shift on empty string (#1486)

    The single-element from_string overloads (char, wchar_t, char16_t,
    char32_t) computed element_type(1) << (string_length - 1U) before the
    copy loop. For an empty string, or when active_bits is 0, string_length
    is 0, so the shift count underflows to SIZE_MAX. Shifting by more than
    the element width is undefined behaviour, which also breaks constexpr
    evaluation.

    Guard the mask with a zero-length check so the shift is only performed
    when string_length > 0. The multi-element from_string overloads were
    already safe.

    Add test_construct_from_empty_string regression test.

    Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>

commit 98cb365d4c28e7b72f8547b734a03a4068acd3f5
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date:   Tue Jul 7 12:32:56 2026 +0200

    Fix etl::histogram copy/move not preserving start_index (#1485)

    The run-time-offset specialization of etl::histogram stores a start_index
    member used to map keys to bins (accumulator[key - start_index]). Its copy
    constructor, move constructor, copy assignment, and move assignment copied
    only the accumulator and left start_index uninitialized, so a copied or
    moved histogram indexed the wrong bin in operator[]/add(), causing
    out-of-bounds access (undefined behavior).

    All four special member functions now also copy start_index. The
    compile-time-offset specialization is unaffected, as its start index is a
    template constant rather than a data member.

    Add regression tests covering copy/move construction and assignment.

    Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>

commit 5cd2f28cd54e4019f7be126bcf7394a6a8318eb9
Author: Drew Rife <darife@jlg.com>
Date:   Tue Jul 7 03:14:48 2026 -0400

    Refactor variant::emplace to perfect forward args instead of copy/move construct (#1494)

    * refactor: emplace logic to use do_emplace for in-place construction with forwarded arguments #1493

    * Add test for variant_variadic

    ---------

    Co-authored-by: Roland Reichwein <Roland.Reichwein@bmw.de>

commit a47c0aae81b886259918961d5fcee20faa06fdd0
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date:   Mon Jul 6 17:32:26 2026 +0200

    Fix etl::message_timer firing following timers early on unregister (#1484)

    active_list.remove(id, has_expired) adjusts the next timer's delta only
    when has_expired is false. When unregistering an active, non-expired timer,
    unregister_timer() incorrectly passed true, skipping that adjustment, so
    every timer after the removed one in the active list fired early by the
    removed timer's delta.

    Pass false instead, matching the etl::callback_timer family. tick() still
    passes true, since the timer has genuinely expired there. The bug affected
    all four variants: message_timer, message_timer_interrupt,
    message_timer_atomic and message_timer_locked. Existing tests missed it
    because they only ever unregistered the tail timer, where the delta
    adjustment is a no-op.

    Add a regression test that unregisters a non-tail active timer and checks
    the following timer still fires at its original absolute time.
2026-07-11 13:02:42 +01:00

570 lines
15 KiB
CMake

cmake_minimum_required(VERSION 3.10)
project(etl_unit_tests LANGUAGES CXX)
#include(FetchContent)
#FetchContent_Declare(
# googletest
# URL https://github.com/google/googletest/archive/refs/heads/main.zip
#)
#set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
#FetchContent_MakeAvailable(googletest)
add_executable(etl_tests
main.cpp
murmurhash3.cpp
test_algorithm.cpp
test_algorithm_ranges.cpp
test_alignment.cpp
test_array.cpp
test_array_view.cpp
test_array_wrapper.cpp
test_atomic.cpp
test_base64_RFC2152_decoder.cpp
test_base64_RFC2152_encoder.cpp
test_base64_RFC3501_decoder.cpp
test_base64_RFC3501_encoder.cpp
test_base64_RFC4648_decoder_with_no_padding.cpp
test_base64_RFC4648_decoder_with_padding.cpp
test_base64_RFC4648_encoder_with_no_padding.cpp
test_base64_RFC4648_encoder_with_padding.cpp
test_base64_RFC4648_URL_decoder_with_no_padding.cpp
test_base64_RFC4648_URL_decoder_with_padding.cpp
test_base64_RFC4648_URL_encoder_with_no_padding.cpp
test_base64_RFC4648_URL_encoder_with_padding.cpp
test_binary.cpp
test_bip_buffer_spsc_atomic.cpp
test_bit.cpp
test_bitset_legacy.cpp
test_bitset_new_comparisons.cpp
test_bitset_new_default_element_type.cpp
test_bitset_new_explicit_single_element_type.cpp
test_bitset_new_ext_default_element_type.cpp
test_bitset_new_ext_explicit_single_element_type.cpp
test_bit_stream.cpp
test_bit_stream_reader_big_endian.cpp
test_bit_stream_reader_little_endian.cpp
test_bit_stream_writer_big_endian.cpp
test_bit_stream_writer_little_endian.cpp
test_bloom_filter.cpp
test_bresenham_line.cpp
test_bsd_checksum.cpp
test_buffer_descriptors.cpp
test_byte.cpp
test_byte_stream.cpp
test_callback_service.cpp
test_callback_timer.cpp
test_callback_timer_atomic.cpp
test_callback_timer_deferred_locked.cpp
test_callback_timer_interrupt.cpp
test_callback_timer_locked.cpp
test_char_traits.cpp
test_checksum.cpp
test_chrono_clocks.cpp
test_chrono_day.cpp
test_chrono_duration.cpp
test_chrono_hh_mm_ss.cpp
test_chrono_literals.cpp
test_chrono_month.cpp
test_chrono_month_day.cpp
test_chrono_month_day_last.cpp
test_chrono_month_weekday.cpp
test_chrono_month_weekday_last.cpp
test_chrono_operators.cpp
test_chrono_time_point.cpp
test_chrono_weekday.cpp
test_chrono_weekday_indexed.cpp
test_chrono_weekday_last.cpp
test_chrono_year.cpp
test_chrono_year_month.cpp
test_chrono_year_month_day.cpp
test_chrono_year_month_day_last.cpp
test_chrono_year_month_weekday.cpp
test_chrono_year_month_weekday_last.cpp
test_circular_buffer.cpp
test_circular_buffer_external_buffer.cpp
test_circular_iterator.cpp
test_closure_with_default_delegate.cpp
test_closure_with_default_delegate_constexpr.cpp
test_closure_with_inplace_function.cpp
test_compare.cpp
test_concepts.cpp
test_constant.cpp
test_const_map.cpp
test_const_map_constexpr.cpp
test_const_map_ext.cpp
test_const_map_ext_constexpr.cpp
test_const_multimap.cpp
test_const_multimap_constexpr.cpp
test_const_multimap_ext.cpp
test_const_multimap_ext_constexpr.cpp
test_const_multiset.cpp
test_const_multiset_constexpr.cpp
test_const_multiset_ext.cpp
test_const_multiset_ext_constexpr.cpp
test_const_set.cpp
test_const_set_constexpr.cpp
test_const_set_ext.cpp
test_const_set_ext_constexpr.cpp
test_container.cpp
test_correlation.cpp
test_covariance.cpp
test_crc1.cpp
test_crc16.cpp
test_crc16_a.cpp
test_crc16_arc.cpp
test_crc16_aug_ccitt.cpp
test_crc16_buypass.cpp
test_crc16_ccitt.cpp
test_crc16_cdma2000.cpp
test_crc16_dds110.cpp
test_crc16_dectr.cpp
test_crc16_dectx.cpp
test_crc16_dnp.cpp
test_crc16_en13757.cpp
test_crc16_genibus.cpp
test_crc16_kermit.cpp
test_crc16_m17.cpp
test_crc16_maxim.cpp
test_crc16_mcrf4xx.cpp
test_crc16_modbus.cpp
test_crc16_opensafety_a.cpp
test_crc16_opensafety_b.cpp
test_crc16_profibus.cpp
test_crc16_riello.cpp
test_crc16_t10dif.cpp
test_crc16_teledisk.cpp
test_crc16_tms37157.cpp
test_crc16_usb.cpp
test_crc16_x25.cpp
test_crc16_xmodem.cpp
test_crc32.cpp
test_crc32_bzip2.cpp
test_crc32_c.cpp
test_crc32_d.cpp
test_crc32_jamcrc.cpp
test_crc32_mpeg2.cpp
test_crc32_posix.cpp
test_crc32_q.cpp
test_crc32_xfer.cpp
test_crc64_ecma.cpp
test_crc64_iso.cpp
test_crc8_ccitt.cpp
test_crc8_cdma2000.cpp
test_crc8_darc.cpp
test_crc8_dvbs2.cpp
test_crc8_ebu.cpp
test_crc8_icode.cpp
test_crc8_itu.cpp
test_crc8_j1850.cpp
test_crc8_j1850_zero.cpp
test_crc8_maxim.cpp
test_crc8_nrsc5.cpp
test_crc8_opensafety.cpp
test_crc8_rohc.cpp
test_crc8_wcdma.cpp
test_cyclic_value.cpp
test_debounce.cpp
test_delegate.cpp
test_delegate_cpp03.cpp
test_delegate_observable.cpp
test_delegate_service.cpp
test_delegate_service_compile_time.cpp
test_delegate_service_cpp03.cpp
test_deque.cpp
test_endian.cpp
test_enum_type.cpp
test_error_handler.cpp
test_etl_assert.cpp
test_etl_traits.cpp
test_exception.cpp
test_expected.cpp
test_fixed_iterator.cpp
test_fixed_sized_memory_block_allocator.cpp
test_flags.cpp
test_flat_map.cpp
test_flat_multimap.cpp
test_flat_multiset.cpp
test_flat_set.cpp
test_fnv_1.cpp
test_format.cpp
test_format_spec.cpp
test_forward_list.cpp
test_forward_list_shared_pool.cpp
test_fsm.cpp
test_function.cpp
test_functional.cpp
test_function_traits.cpp
test_gamma.cpp
test_hash.cpp
test_hfsm.cpp
test_hfsm_recurse_to_inner_state_on_start.cpp
test_hfsm_transition_on_enter.cpp
test_histogram.cpp
test_index_of_type.cpp
test_indirect_vector.cpp
test_indirect_vector_external_buffer.cpp
test_inplace_function.cpp
test_instance_count.cpp
test_integral_limits.cpp
test_intrusive_avl_tree.cpp
test_intrusive_forward_list.cpp
test_intrusive_links.cpp
test_intrusive_list.cpp
test_intrusive_queue.cpp
test_intrusive_stack.cpp
test_invert.cpp
test_invoke.cpp
test_io_port.cpp
test_is_invocable.cpp
test_iterator.cpp
test_jenkins.cpp
test_largest.cpp
test_limiter.cpp
test_limits.cpp
test_list.cpp
test_list_shared_pool.cpp
test_macros.cpp
test_make_string.cpp
test_manchester.cpp
test_map.cpp
test_math.cpp
test_math_functions.cpp
test_mean.cpp
test_memory.cpp
test_mem_cast.cpp
test_mem_cast_ptr.cpp
test_message.cpp
test_message_broker.cpp
test_message_bus.cpp
test_message_packet.cpp
test_message_router.cpp
test_message_router_registry.cpp
test_message_timer.cpp
test_message_timer_atomic.cpp
test_message_timer_interrupt.cpp
test_message_timer_locked.cpp
test_multimap.cpp
test_multiset.cpp
test_multi_array.cpp
test_multi_range.cpp
test_multi_span.cpp
test_multi_vector.cpp
test_murmur3.cpp
test_not_null_pointer.cpp
test_not_null_pointer_constexpr.cpp
test_not_null_unique_pointer.cpp
test_nth_type.cpp
test_numeric.cpp
test_observer.cpp
test_optional.cpp
test_overload.cpp
test_packet.cpp
test_parameter_pack.cpp
test_parameter_type.cpp
test_parity_checksum.cpp
test_pearson.cpp
test_poly_span_dynamic_extent.cpp
test_poly_span_fixed_extent.cpp
test_pool.cpp
test_pool_external_buffer.cpp
test_priority_queue.cpp
test_print.cpp
test_pseudo_moving_average.cpp
test_quantize.cpp
test_queue.cpp
test_queue_lockable.cpp
test_queue_lockable_small.cpp
test_queue_memory_model_small.cpp
test_queue_mpmc_mutex.cpp
test_queue_mpmc_mutex_small.cpp
test_queue_spsc_atomic.cpp
test_queue_spsc_atomic_small.cpp
test_queue_spsc_isr.cpp
test_queue_spsc_isr_small.cpp
test_queue_spsc_locked.cpp
test_queue_spsc_locked_small.cpp
test_random.cpp
test_ranges.cpp
test_ratio.cpp
test_reference_flat_map.cpp
test_reference_flat_multimap.cpp
test_reference_flat_multiset.cpp
test_reference_flat_set.cpp
test_rescale.cpp
test_result.cpp
test_rms.cpp
test_rounded_integral_division.cpp
test_scaled_rounding.cpp
test_set.cpp
test_shared_message.cpp
test_signal.cpp
test_singleton.cpp
test_singleton_base.cpp
test_smallest.cpp
test_span_dynamic_extent.cpp
test_span_fixed_extent.cpp
test_stack.cpp
test_standard_deviation.cpp
test_state_chart.cpp
test_state_chart_compile_time.cpp
test_state_chart_compile_time_with_data_parameter.cpp
test_state_chart_with_data_parameter.cpp
test_state_chart_with_rvalue_data_parameter.cpp
test_string_char.cpp
test_string_char_external_buffer.cpp
test_string_stream.cpp
test_string_stream_u16.cpp
test_string_stream_u32.cpp
test_string_stream_u8.cpp
test_string_stream_wchar_t.cpp
test_string_u16.cpp
test_string_u16_external_buffer.cpp
test_string_u32.cpp
test_string_u32_external_buffer.cpp
test_string_u8.cpp
test_string_u8_external_buffer.cpp
test_string_utilities.cpp
test_string_utilities_std.cpp
test_string_utilities_std_u16.cpp
test_string_utilities_std_u32.cpp
test_string_utilities_std_u8.cpp
test_string_utilities_std_wchar_t.cpp
test_string_utilities_u16.cpp
test_string_utilities_u32.cpp
test_string_utilities_u8.cpp
test_string_utilities_wchar_t.cpp
test_string_view.cpp
test_string_wchar_t.cpp
test_string_wchar_t_external_buffer.cpp
test_successor.cpp
test_task_scheduler.cpp
test_threshold.cpp
test_to_arithmetic.cpp
test_to_arithmetic_u16.cpp
test_to_arithmetic_u32.cpp
test_to_arithmetic_u8.cpp
test_to_arithmetic_wchar_t.cpp
test_to_string.cpp
test_to_u16string.cpp
test_to_u32string.cpp
test_to_u8string.cpp
test_to_wstring.cpp
test_tuple.cpp
test_type_def.cpp
test_type_list.cpp
test_type_lookup.cpp
test_type_select.cpp
test_type_traits.cpp
test_unaligned_type.cpp
test_unaligned_type_ext.cpp
test_uncopyable.cpp
test_unordered_map.cpp
test_unordered_multimap.cpp
test_unordered_multiset.cpp
test_unordered_set.cpp
test_user_type.cpp
test_utility.cpp
test_variance.cpp
test_variant_legacy.cpp
test_variant_pool.cpp
test_variant_pool_external_buffer.cpp
test_variant_variadic.cpp
test_vector.cpp
test_vector_external_buffer.cpp
test_vector_non_trivial.cpp
test_vector_pointer.cpp
test_vector_pointer_external_buffer.cpp
test_vector_function_pointer.cpp
test_vector_function_pointer_external_buffer.cpp
test_vector_member_function_pointer.cpp
test_vector_member_function_pointer_external_buffer.cpp
test_visitor.cpp
test_xor_checksum.cpp
test_xor_rotate_checksum.cpp
)
target_compile_definitions(etl_tests PRIVATE -DETL_DEBUG)
option(ETL_NO_STL "No STL" OFF)
set(EXTRA_COMPILE_OPTIONS "" CACHE STRING "Additional compiler options")
set(EXTRA_LINK_OPTIONS "" CACHE STRING "Additional linker options")
set(EXTRA_LINK_LIBS "" CACHE STRING "Additional libraries to link")
set(EXTRA_TESTING_FLAGS "" CACHE STRING "Additional testing flags for ctest")
if (ETL_CXX_STANDARD MATCHES "98")
message(STATUS "Compiling for C++98")
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 98)
elseif (ETL_CXX_STANDARD MATCHES "03")
message(STATUS "Compiling for C++03 (C++98)")
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 98)
elseif (ETL_CXX_STANDARD MATCHES "11")
message(STATUS "Compiling for C++11")
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 11)
elseif (ETL_CXX_STANDARD MATCHES "14")
message(STATUS "Compiling for C++14")
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 14)
elseif (ETL_CXX_STANDARD MATCHES "17")
message(STATUS "Compiling for C++17")
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 17)
elseif (ETL_CXX_STANDARD MATCHES "20")
message(STATUS "Compiling for C++20")
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 20)
elseif (ETL_CXX_STANDARD MATCHES "23")
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.20")
message(STATUS "Compiling for C++23")
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 23)
else()
message(STATUS "CMake version ${CMAKE_VERSION} does not support C++23, falling back to C++20")
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 20)
endif()
elseif (ETL_CXX_STANDARD MATCHES "26")
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.25")
message(STATUS "Compiling for C++26")
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 26)
elseif (CMAKE_VERSION VERSION_GREATER_EQUAL "3.20")
message(STATUS "CMake version ${CMAKE_VERSION} does not support C++26, falling back to C++23")
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 23)
else()
message(FATAL_ERROR "CMake version ${CMAKE_VERSION} is too old to support C++23 or C++26. Please upgrade to CMake 3.20 or later.")
endif()
else()
message(STATUS "Compiling for C++17")
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 17)
endif()
if (NO_STL OR ETL_NO_STL)
message(STATUS "Compiling for No STL")
target_compile_definitions(etl_tests PRIVATE -DETL_NO_STL)
else()
message(STATUS "Compiling for STL")
endif()
if (ETL_USE_TYPE_TRAITS_BUILTINS)
message(STATUS "Compiling for built-in type traits")
target_compile_definitions(etl_tests PRIVATE -DETL_USE_TYPE_TRAITS_BUILTINS)
endif()
if (ETL_USER_DEFINED_TYPE_TRAITS)
message(STATUS "Compiling for user defined type traits")
target_compile_definitions(etl_tests PRIVATE -DETL_USER_DEFINED_TYPE_TRAITS)
endif()
if (ETL_MESSAGES_ARE_NOT_VIRTUAL)
message(STATUS "Compiling for non-virtual messages")
target_compile_definitions(etl_tests PRIVATE -DETL_MESSAGES_ARE_NOT_VIRTUAL)
endif()
if (ETL_FORCE_TEST_CPP03_IMPLEMENTATION)
message(STATUS "Compiling for forced C++03 tests")
target_compile_definitions(etl_tests PRIVATE -DETL_FORCE_TEST_CPP03_IMPLEMENTATION)
endif()
if (ETL_OPTIMISATION MATCHES "-O1")
message(STATUS "Compiling with -O1 optimisations")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1")
endif()
if (ETL_OPTIMISATION MATCHES "-O2")
message(STATUS "Compiling with -O2 optimisations")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
endif()
if (ETL_OPTIMISATION MATCHES "-O3")
message(STATUS "Compiling with -O3 optimisations")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
endif()
if ((CMAKE_CXX_COMPILER_ID MATCHES "MSVC"))
message(STATUS "Using MSVC compiler")
target_compile_options(etl_tests
PRIVATE
/Zc:__cplusplus
)
endif ()
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
message(STATUS "Using GCC compiler")
endif ()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
message(STATUS "Using Clang compiler")
endif ()
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
target_compile_options(etl_tests
PRIVATE
-fno-omit-frame-pointer
-fno-common
-pedantic-errors
-Wall
-Wextra
-Werror
-Wfloat-equal
-Wshadow
-Wnull-dereference
-Wsign-conversion
-Wextra-semi
-g
${EXTRA_COMPILE_OPTIONS}
)
target_link_options(etl_tests PRIVATE ${EXTRA_LINK_OPTIONS})
endif ()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(etl_tests
PRIVATE
-fno-omit-frame-pointer
-fno-common
-pedantic-errors
-Wall
-Wextra
-Werror
-Wfloat-equal
-Wshadow
-Wnull-dereference
-Wsign-conversion
-Wextra-semi
-Wextra-semi-stmt
-Wc++11-extra-semi
-g
${EXTRA_COMPILE_OPTIONS}
)
target_link_options(etl_tests PRIVATE ${EXTRA_LINK_OPTIONS})
endif ()
if ((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
if (ETL_ENABLE_SANITIZER MATCHES "ON")
message(STATUS "Compiling with Sanitizer enabled")
# MinGW doesn't presently support sanitization
if (NOT MINGW)
target_compile_options(etl_tests
PRIVATE
-fsanitize=address,undefined,bounds
)
target_link_options(etl_tests
PRIVATE
-fsanitize=address,undefined,bounds
)
endif()
endif ()
endif ()
target_include_directories(etl_tests
PRIVATE
${PROJECT_SOURCE_DIR}/../include)
add_subdirectory(UnitTest++)
target_link_libraries(etl_tests PRIVATE UnitTestpp ${EXTRA_LINK_LIBS})
enable_testing()
# Enable the 'make test' CMake target using the executable defined above
add_test(NAME etl_unit_tests COMMAND etl_tests ${EXTRA_TESTING_FLAGS})
# Since ctest will only show you the results of the single executable
# define a target that will output all of the failing or passing tests
# as they appear from UnitTest++
add_custom_target(test_verbose COMMAND ${CMAKE_CTEST_COMMAND} --verbose)