Skip to content

Commit

Permalink
Merge branch 'master' into arch-indep
Browse files Browse the repository at this point in the history
  • Loading branch information
kris-jusiak authored Feb 4, 2025
2 parents 23b3f9f + fbb06e3 commit 780e6cb
Show file tree
Hide file tree
Showing 8 changed files with 251 additions and 113 deletions.
3 changes: 3 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ modernize-*,\
-modernize-pass-by-value,\
-modernize-use-trailing-return-type,\
performance-*,\
-performance-avoid-endl,\
portability-*,\
readability-*,\
-readability-identifier-length,\
-readability-redundant-member-init,\
-*implicit-bool-conversion,\
-*magic-numbers,\
-*named-parameter,\
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ jobs:
strategy:
matrix:
toolset: [ClangCl, v143]
std: [17, 20]
exclude:
- toolset: v143
std: 17
std: [20]

steps:
- uses: actions/checkout@v3
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/windows_shared.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ jobs:
strategy:
matrix:
toolset: [ClangCl, v143]
std: [17, 20]
exclude:
- toolset: v143
std: 17
std: [20]

steps:
- uses: actions/checkout@v3
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,17 @@ for (auto i : std::vector{1, 2, 3}) {
}
| std::tuple{true, 42};
```
When using the `operator|` syntax instead of a `for` loop, the test name will automatically
be extended to avoid duplicate names. For example, the test name for the `args and types` test
will be `args and types (true, bool)` for the first parameter and `args and types (42, int)`
for the second parameter. For simple built-in types (integral types and floating point numbers),
the test name will contain the parameter values. For other types, the parameters will simply be
enumerated. For example, if we would extend the test above to use
`std::tuple{true, 42, std::complex<double>{0.5, 1}}`, the test name in the third run would be
`args and types (3rd parameter, std::complex<double>)`. If you want to have the actual value of
a non-integral type included in the test name, you can overload the `format_test_parameter` function.
See the [example on parameterized tests](https://github.com/boost-ext/ut/blob/master/example/parameterized.cpp)
for details.
```
All tests passed (14 asserts in 10 tests)
Expand Down
14 changes: 0 additions & 14 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ find_program(BOOST_UT_MEMORYCHECK_COMMAND valgrind)

function(example file target)
add_executable(boost_ut_${target} ${file}.cpp)
if(${target} MATCHES "_cpp17$")
set_property(TARGET boost_ut_${target} PROPERTY CXX_STANDARD 17)
endif()
if(BOOST_UT_ENABLE_MEMCHECK AND BOOST_UT_MEMORYCHECK_COMMAND)
ut_add_custom_command_or_test(
TARGET
Expand Down Expand Up @@ -93,14 +90,3 @@ example(terse terse)
example(test _test)
example(tmp tmp)
example(using using)

if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
example(expect expect_cpp17)
example(test test_cpp17)
example(suite suite_cpp17)
example(tag tag_cpp17)
example(terse terse_cpp17)
example(section section_cpp17)
example(should should_cpp17)
example(skip skip_cpp17)
endif()
31 changes: 31 additions & 0 deletions example/parameterized.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,28 @@
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/ut.hpp>
#include <complex>
#include <concepts>
#include <ranges>
#include <string>
#include <tuple>
#include <type_traits>
#include <vector>

namespace boost::inline ext::ut {

namespace {
template <std::floating_point F>
std::string format_test_parameter(const std::complex<F>& arg,
[[maybe_unused]] const int counter) {
std::ostringstream oss;
oss << arg.real() << '+' << arg.imag() << 'i';
return oss.str();
}
} // namespace

} // namespace boost::inline ext::ut

int main() {
using namespace boost::ut;

Expand Down Expand Up @@ -58,4 +74,19 @@ int main() {
expect(42_i == static_cast<int>(arg) or arg);
expect(type<TArg> == type<int> or type<TArg> == type<bool>);
} | std::tuple{42, true};

// Modifying test names when using alternative syntax
// When using the alternative syntax, the test names are extended based on the
// test parameters (to ensure uniqueness). Here, for simple built-in types,
// the parameter value is printed, while other types are simply enumerated.
// Without the `format_test_parameter` overload above, the test names for the
// test below would be:
// "parameterized test names (42, int)"
// "parameterized test names (true, bool)"
// "parameterized test names (3rd parameter, std::complex<double>)"
// However, since the overload for std::complex is available, the third test name becomes:
// "parameterized test names (1.5+2i, std::complex<double>)"
"parameterized test names"_test = []<class TArg>([[maybe_unused]] TArg arg) {
expect(true);
} | std::tuple{42, true, std::complex{1.5, 2.0}};
}
Loading

0 comments on commit 780e6cb

Please sign in to comment.