Skip to content

Commit 7116221

Browse files
committed
Made cross-translation units mocks available only through a feature flag.
1 parent 45e33f9 commit 7116221

File tree

8 files changed

+87
-6
lines changed

8 files changed

+87
-6
lines changed

.github/workflows/ci_linux_clang.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ jobs:
1616
fail-fast: false
1717
matrix:
1818
config:
19+
- {
20+
name: "Ubuntu 22.04 Clang 13 C++11 with cross-translation units mocks",
21+
os: ubuntu-22.04,
22+
build_type: Debug,
23+
cc: "clang-13", cxx: "clang++-13",
24+
cxx_standard: 11,
25+
additional_parameters: "-DENABLE_FAKEIT_CROSS_TRANSLATION_UNITS_MOCKS_IN_TESTS=ON"
26+
}
1927
- {
2028
name: "Ubuntu 22.04 Clang 13",
2129
os: ubuntu-22.04,
@@ -88,6 +96,14 @@ jobs:
8896
cc: "clang-18", cxx: "clang++-18",
8997
cxx_standard: 26
9098
}
99+
- {
100+
name: "Ubuntu 24.04 Clang 18 C++26 with cross-translation units mocks",
101+
os: ubuntu-24.04,
102+
build_type: Debug,
103+
cc: "clang-18", cxx: "clang++-18",
104+
cxx_standard: 26,
105+
additional_parameters: "-DENABLE_FAKEIT_CROSS_TRANSLATION_UNITS_MOCKS_IN_TESTS=ON"
106+
}
91107
- {
92108
name: "Ubuntu 24.04 Clang with sanitizers",
93109
os: ubuntu-24.04,
@@ -107,7 +123,8 @@ jobs:
107123
-DENABLE_TESTING=ON \
108124
-DWARNINGS_AS_ERRORS_FOR_TESTS=ON \
109125
-DOVERRIDE_CXX_STANDARD_FOR_TESTS=${{ matrix.config.cxx_standard }} \
110-
-DENABLE_SANITIZERS_IN_TESTS=${{ matrix.config.enable_sanitizers_in_tests }}
126+
-DENABLE_SANITIZERS_IN_TESTS=${{ matrix.config.enable_sanitizers_in_tests }} \
127+
${{ matrix.config.additional_parameters }}
111128
cmake --build build -j
112129
- name: Run tests
113130
run: |

.github/workflows/ci_linux_gcc.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ jobs:
1616
fail-fast: false
1717
matrix:
1818
config:
19+
- {
20+
name: "Ubuntu 22.04 GCC 10 C++11 with cross-translation units mocks",
21+
os: ubuntu-22.04,
22+
build_type: Debug,
23+
cc: "gcc-10", cxx: "g++-10",
24+
cxx_standard: 11,
25+
additional_parameters: "-DENABLE_FAKEIT_CROSS_TRANSLATION_UNITS_MOCKS_IN_TESTS=ON"
26+
}
1927
- {
2028
name: "Ubuntu 22.04 GCC 10",
2129
os: ubuntu-22.04,
@@ -82,6 +90,14 @@ jobs:
8290
cc: "gcc-14", cxx: "g++-14",
8391
cxx_standard: 26
8492
}
93+
- {
94+
name: "Ubuntu 24.04 GCC 14 C++26 with cross-translation units mocks",
95+
os: ubuntu-24.04,
96+
build_type: Debug,
97+
cc: "gcc-14", cxx: "g++-14",
98+
cxx_standard: 26,
99+
additional_parameters: "-DENABLE_FAKEIT_CROSS_TRANSLATION_UNITS_MOCKS_IN_TESTS=ON"
100+
}
85101
- {
86102
name: "Ubuntu 24.04 GCC with sanitizers",
87103
os: ubuntu-24.04,
@@ -101,7 +117,8 @@ jobs:
101117
-DENABLE_TESTING=ON \
102118
-DWARNINGS_AS_ERRORS_FOR_TESTS=ON \
103119
-DOVERRIDE_CXX_STANDARD_FOR_TESTS=${{ matrix.config.cxx_standard }} \
104-
-DENABLE_SANITIZERS_IN_TESTS=${{ matrix.config.enable_sanitizers_in_tests }}
120+
-DENABLE_SANITIZERS_IN_TESTS=${{ matrix.config.enable_sanitizers_in_tests }} \
121+
${{ matrix.config.additional_parameters }}
105122
cmake --build build -j
106123
- name: Run tests
107124
run: |

.github/workflows/ci_macos_appleclang.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ jobs:
1616
fail-fast: false
1717
matrix:
1818
config:
19+
- {
20+
name: "macOS 14 AppleClang 15 C++11 with cross-translation units mocks",
21+
os: macos-14,
22+
build_type: Debug,
23+
cxx_standard: 11,
24+
additional_parameters: "-DENABLE_FAKEIT_CROSS_TRANSLATION_UNITS_MOCKS_IN_TESTS=ON"
25+
}
1926
- {
2027
name: "macOS 14 AppleClang 15 C++11",
2128
os: macos-14,
@@ -64,6 +71,13 @@ jobs:
6471
build_type: Debug,
6572
cxx_standard: 26
6673
}
74+
- {
75+
name: "macOS 15 AppleClang 17 C++26 with cross-translation units mocks",
76+
os: macos-15,
77+
build_type: Debug,
78+
cxx_standard: 26,
79+
additional_parameters: "-DENABLE_FAKEIT_CROSS_TRANSLATION_UNITS_MOCKS_IN_TESTS=ON"
80+
}
6781
- {
6882
name: "macOS 15 AppleClang with sanitizers",
6983
os: macos-15,
@@ -80,7 +94,8 @@ jobs:
8094
-DENABLE_TESTING=ON \
8195
-DWARNINGS_AS_ERRORS_FOR_TESTS=ON \
8296
-DOVERRIDE_CXX_STANDARD_FOR_TESTS=${{ matrix.config.cxx_standard }} \
83-
-DENABLE_SANITIZERS_IN_TESTS=${{ matrix.config.enable_sanitizers_in_tests }}
97+
-DENABLE_SANITIZERS_IN_TESTS=${{ matrix.config.enable_sanitizers_in_tests }} \
98+
${{ matrix.config.additional_parameters }}
8499
cmake --build build -j
85100
- name: Run tests
86101
run: |

.github/workflows/ci_windows_msvc.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ jobs:
1616
fail-fast: false
1717
matrix:
1818
config:
19+
- {
20+
name: "Windows 2022 MSVC 2022 Win32 C++11 with cross-translation units mocks",
21+
os: windows-2022,
22+
build_type: Debug,
23+
generator: "Visual Studio 17 2022",
24+
architecture: "Win32",
25+
cxx_standard: 11,
26+
additional_parameters: "-DENABLE_FAKEIT_CROSS_TRANSLATION_UNITS_MOCKS_IN_TESTS=ON"
27+
}
1928
- {
2029
name: "Windows 2022 MSVC 2022 Win32",
2130
os: windows-2022,
@@ -126,6 +135,15 @@ jobs:
126135
architecture: "x64",
127136
cxx_standard: 26
128137
}
138+
- {
139+
name: "Windows 2025 MSVC 2022 x64 C++26 with cross-translation units mocks",
140+
os: windows-2025,
141+
build_type: Debug,
142+
generator: "Visual Studio 17 2022",
143+
architecture: "x64",
144+
cxx_standard: 26,
145+
additional_parameters: "-DENABLE_FAKEIT_CROSS_TRANSLATION_UNITS_MOCKS_IN_TESTS=ON"
146+
}
129147
steps:
130148
- uses: actions/checkout@v3
131149
- name: Build project
@@ -135,7 +153,8 @@ jobs:
135153
-A ${{ matrix.config.architecture }} \
136154
-DENABLE_TESTING=ON \
137155
-DWARNINGS_AS_ERRORS_FOR_TESTS=ON \
138-
-DOVERRIDE_CXX_STANDARD_FOR_TESTS=${{ matrix.config.cxx_standard }}
156+
-DOVERRIDE_CXX_STANDARD_FOR_TESTS=${{ matrix.config.cxx_standard }} \
157+
${{ matrix.config.additional_parameters }}
139158
cmake --build build --config ${{ matrix.config.build_type }} -j
140159
- name: Run tests
141160
run: |

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ set(OVERRIDE_CXX_STANDARD_FOR_TESTS "" CACHE STRING "Override the C++ standard u
88
option(WARNINGS_AS_ERRORS_FOR_TESTS "Treat warnings as errors when building tests." OFF)
99
option(ENABLE_SANITIZERS_IN_TESTS "Enable address / undefined sanitizers in tests." OFF)
1010
option(ENABLE_COVERAGE "Enable coverage reporting for gcc/clang." OFF)
11+
option(ENABLE_FAKEIT_CROSS_TRANSLATION_UNITS_MOCKS_IN_TESTS "Enable cross-translation units mocks in tests." OFF)
1112

1213
# Directory containing main targets of FakeIt.
1314
add_subdirectory(include)

include/fakeit/api_macros.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@
1111
#define STUB_ID_STR( counter ) \
1212
__FILE__ COUNTER_STRINGIFY(counter)
1313

14-
#define STUB_ID(counter) \
15-
fakeit::constExprHash(STUB_ID_STR(counter))
14+
#ifdef FAKEIT_CROSS_TRANSLATION_UNITS_MOCKS
15+
#define STUB_ID(counter) \
16+
fakeit::constExprHash(STUB_ID_STR(counter))
17+
#else
18+
#define STUB_ID(counter) \
19+
counter
20+
#endif
1621

1722
#define MOCK_TYPE(mock) \
1823
std::remove_reference<decltype((mock).get())>::type

tests/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,9 @@ if(ENABLE_COVERAGE)
8484
endif()
8585
endif()
8686

87+
if(ENABLE_FAKEIT_CROSS_TRANSLATION_UNITS_MOCKS_IN_TESTS)
88+
target_compile_definitions(FakeIt_tests PRIVATE FAKEIT_CROSS_TRANSLATION_UNITS_MOCKS)
89+
message(STATUS "Cross-translation units mocks enabled.")
90+
endif()
91+
8792
add_test(NAME FakeIt_tests COMMAND FakeIt_tests)

tests/multiple_translation_units_stub_test.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using namespace fakeit;
66
using namespace multiple_tu;
77

8+
#ifdef FAKEIT_CROSS_TRANSLATION_UNITS_MOCKS
89
struct MultipleTranslationUnitsStub : tpunit::TestFixture {
910

1011
MultipleTranslationUnitsStub() :
@@ -126,3 +127,4 @@ struct MultipleTranslationUnitsStub : tpunit::TestFixture {
126127
}
127128

128129
} __MultipleTranslationUnitsStub;
130+
#endif

0 commit comments

Comments
 (0)