Skip to content

Commit f98fa2a

Browse files
test(): Added a test checking the amalgamated library for ODR violations.
1 parent 4f46366 commit f98fa2a

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

tests/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# Function for defining a test with proper args
22
function(utl_add_test file_name)
3+
cmake_parse_arguments(PARSE_ARGV 0 ARG "" "" "ADDITIONAL_CPP") # optional named argument
4+
35
string(REPLACE "/" "-" target_name "${file_name}") # CMake doesn't like target names with slashes
46
string(PREPEND target_name "test-") # so we don't intersect names with benchmarks & examples
57

6-
add_executable(${target_name} ${file_name}.cpp)
8+
add_executable(${target_name} ${file_name}.cpp ${ARG_ADDITIONAL_CPP})
79

810
target_compile_features (${target_name} PRIVATE ${UTL_COMPILE_FEATURES} )
911
target_compile_options (${target_name} PRIVATE ${UTL_TEST_FLAGS} )
@@ -24,7 +26,7 @@ endfunction()
2426
# Note 2: '--force-colors' makes doctest show colored output in the terminal, but makes up CTest logs save ANSI
2527
# color codes. Without this flag doctest suppresses color because it detects CTest writing output to the file.
2628

27-
# Tests
29+
# Module tests
2830
utl_add_test("module_assertion/assertions")
2931
utl_add_test("module_bit/enum_bitflags")
3032
utl_add_test("module_bit/group_bit_operations")
@@ -70,3 +72,5 @@ utl_add_test("module_struct_reflect/perfect_forwarding")
7072
utl_add_test("module_struct_reflect/reflection")
7173
utl_add_test("module_table/formats")
7274
utl_add_test("module_time/unit_split")
75+
# General tests
76+
utl_add_test("general_odr/main" ADDITIONAL_CPP "general_odr/second.cpp")

tests/general_odr/main.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// __________________________________ CONTENTS ___________________________________
2+
//
3+
// Compile-time test that checks the library for ODR violations,
4+
// should any of the headers miss an 'inline' this will not build
5+
// due to including the same thing in multiple translation units.
6+
// _______________________________________________________________________________
7+
8+
#include "second.hpp"
9+
10+
int main() {
11+
print_hello();
12+
}

tests/general_odr/second.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "second.hpp"
2+
3+
void print_hello() { utl::log::println("Hello (second)"); }

tests/general_odr/second.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
3+
#include "single_include/UTL.hpp"
4+
// this will be included in both translation units, should
5+
// there be any ODR violations the compiler will complain
6+
//
7+
// we include the automatically amalgamated header so we don't have
8+
// to update this test every time there is a new module, this also
9+
// has a benefit of testing the amalgamated include in general
10+
11+
void print_hello();

0 commit comments

Comments
 (0)