Gromacs
2025.1
|
#include <algorithm>
#include <filesystem>
#include <functional>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <variant>
#include <gtest/gtest.h>
#include "gromacs/utility/enumerationhelpers.h"
#include "gromacs/utility/stringutil.h"
#include "testasserts.h"
Functionality for customizing names of tests and the files containing their reference data in a declarative way.
To provide GoogleTest with helpfully customized names for test cases constructed via testing::TestWithParam<TestParameters>,
gmx::test::NameOfTestFromTuple<TestParameters>
,When passed, the sc_testNamer
functor is called by GoogleTest to generate a unique name for the test, which is done by NameOfTestFromTuple<TestParamers>
calling the formatters (passing the respective parameters) to construct an underscore-separated string as the test name.
Several helper functions have been provided to smooth common use cases, including
useString
for using a string paramater as-isPrefixFormatter
for prefixing an existing formatter with a label stringtoEmptyString
for producing no output for a stringtoEmptyString
is particularly useful for the case where the test case needs reference data, but only a subset of the test parameters contribute to computing the expected result, while others specify the implementation (e.g. target hardware, or which sets of outputs are to be computed, or an implementation detail). To do this:
RefDataFilenameMaker<TestParameters>
and provide formatters to it to either contribute to or be omitted from the name of the reference data file (mostly these are the same as the formatters used with sc_testNamer
),TestReferenceData
with the name returned by sc_refDataFilenameMaker(GetParam())
Alternatively, if the test author prefers to use a struct for parameters, the supporting machinery can be declared inside that struct for clarity, like
Classes | |
struct | gmx::test::detail::FormatterVariant< T, Enable > |
Single-component variant for a formatting callable for variables of type T . More... | |
struct | gmx::test::detail::FormatterVariant< Enum, typename std::enable_if_t< std::is_enum_v< Enum > > > |
Specialization for formatting function of variables whose type is an enum. More... | |
struct | gmx::test::detail::ParamsToFormatterVariants< Tuple > |
Template for mapping parameter types to formatter variants. More... | |
struct | gmx::test::detail::ParamsToFormatterVariants< std::tuple< Ts...> > |
Specialization for tuple of parameter types to tuple of formatter variants. More... | |
struct | gmx::test::detail::IsTuple< T > |
Type trait for whether T is a std::tuple. More... | |
struct | gmx::test::detail::IsTuple< std::tuple< Ts...> > |
Specialization to successfully match a std::tuple. More... | |
class | gmx::test::NameOfTestFromTuple< ParametersTuple > |
Function object that helps GoogleTest name our test cases. More... | |
class | gmx::test::RefDataFilenameMaker< ParametersTuple > |
Functor to name a refdata filename for this test. More... | |
struct | gmx::test::PrefixFormatter< T, formatter > |
Functor to add a prefix to the return from formatter for T . More... | |
Functions | |
template<typename Param > | |
std::string | gmx::test::detail::formatNameFromParam (const Param param, const typename FormatterVariant< Param >::Variant formatterVariant) |
Apply the formatterVariant to the respective param to produce a string. More... | |
template<typename T , T... S, typename F > | |
constexpr void | gmx::test::detail::ForSequence (std::integer_sequence< T, S...>, F &&f) |
Fold a constexpr sequence of integers that match S to calls to the function f taking a matching std::integral_constant. | |
template<typename ParametersTuple > | |
std::string | gmx::test::detail::mapNameFormattersToParameters (const ParametersTuple params, const typename ParamsToFormatterVariants< ParametersTuple >::type &formatters) |
Apply the formatters to the respective params to produce an underscore-separated string. More... | |
static std::string | gmx::test::useString (const std::string s) |
Formatter to pass std::string through. | |
template<typename T > | |
std::string | gmx::test::toEmptyString (const T) |
Formatter to ignore test parameters in a self-documenting way. | |
Variables | |
template<class > | |
constexpr bool | gmx::test::detail::sc_alwaysFalse = false |
Helper constant for the std::visitor in formatNameFromParam . More... | |