Aller au contenu
Bienvenue sur la nouvelle documentation de CppUtils !

Namespace: CppUtils::UnitTest

enum class ComparisonOperator {
Equal,
NotEqual,
LessThan,
LessThanOrEqual,
GreaterThan,
GreaterThanOrEqual
};

Relational comparison operators supported in assertion decomposition.

enum class TestStatus {
Success,
Failure,
Skipped
};

Outcome status of an individual test case execution.

using CppUtils::UnitTest::ComparisonOperatorMapping = typedef Type::Mapping<Type::Pair<ComparisonOperator::Equal, String::Hasher{"=="}>, Type::Pair<ComparisonOperator::NotEqual, String::Hasher{"!="}>, Type::Pair<ComparisonOperator::LessThan, String::Hasher{"<"}>, Type::Pair<ComparisonOperator::LessThanOrEqual, String::Hasher{"<="}>, Type::Pair<ComparisonOperator::GreaterThan, String::Hasher{">"}>, Type::Pair<ComparisonOperator::GreaterThanOrEqual, String::Hasher{">="}>>;

Mapping between ComparisonOperator and its string representation.

using CppUtils::UnitTest::ValueTestSuiteBuilder = typedef ParameterizedTestSuiteBuilder<std::tuple<Values...>>;

Builder for registering a test suite parameterized over a discrete pack of values.

using CppUtils::UnitTest::RangeTestSuiteBuilder = typedef ParameterizedTestSuiteBuilder<Range>;

Builder for registering a test suite parameterized over an input range.

constexpr ThrowsMatcher<ExceptionType> CppUtils::UnitTest::throws;

Matcher tag variable template for expecting an exception of type ExceptionType.

constexpr NoThrowMatcher CppUtils::UnitTest::noThrow;

Matcher instance asserting that an action completes without throwing any exception.

constexpr CrashesMatcher CppUtils::UnitTest::crashes;

Matcher instance asserting that an action terminates abnormally.

constexpr EventuallyMatcher CppUtils::UnitTest::eventually;

Matcher instance asserting that a predicate eventually becomes true.

constexpr CompletesMatcher CppUtils::UnitTest::completes;

Matcher instance asserting that a future or reactive primitive completes.

auto CppUtils::UnitTest::testRunner;

Global test runner instance used for test suite registration and execution.

constexpr auto getComparisonOperatorString(ComparisonOperator comparisonOperator) noexcept -> std::string_view;

Converts a ComparisonOperator enumerator to its C++ operator string literal.

ParamètreDescription
comparisonOperatorEnumerator value.

Retourne : Operator string view (e.g. "==", "<=", "!="), or empty string if invalid.

constexpr auto getComparisonOperator(std::string_view operatorString) noexcept -> std::optional<ComparisonOperator>;

Parses an operator string literal into its corresponding ComparisonOperator.

ParamètreDescription
operatorStringOperator symbol string (e.g. "==", "<=").

Retourne : ComparisonOperator wrapped in std::optional, or std::nullopt if unknown.

template <ComparisonOperator Operator>
constexpr auto applyOperator(const auto& left, const auto& right) -> bool;
template <ComparisonOperator Operator>
constexpr auto compareFloatingPoint(const auto& left, const auto& right) -> bool;
template <ComparisonOperator Operator>
constexpr auto compareIntegers(const auto& left, const auto& right) -> bool;
template <ComparisonOperator Operator>
constexpr auto evaluateComparison(const auto& left, const auto& right) -> bool;
template <class OperandType>
constexpr auto expect(OperandType&& operand, std::source_location location=std::source_location::current()) noexcept -> ExpectationProxy<OperandType>;

Asserts an expectation on a value, condition, or callable.

Supports comparison assertions using relational operators:

expect(value) == expected;
expect(score) >= 100;

standalone boolean conditions:

expect(result.has_value());

and matchers:

expect([&] { divide(1, 0); }) == throws<std::invalid_argument>;
expect([&] { divide(1, 2); }) == noThrow;
ParamètreDescription
operandValue to compare, boolean condition, or callable to evaluate.
locationSource location used for failure reporting (automatically captured).

Retourne : ExpectationProxy evaluating the expectation.

auto testSuite(std::string name) -> TestSuiteBuilder;

Declares a test suite.

ParamètreDescription
nameDescriptive test suite identifier.

Retourne : TestSuiteBuilder used to configure dependencies or assign suite body.

Deliberately skips the current test, reporting it as skipped in test results.

ParamètreDescription
messageJustification for skipping the test.
locationSource location used for skip reporting (automatically captured).
auto skipIf(bool condition, std::string message, std::source_location location=std::source_location::current()) -> void;

Conditionally skips the current test if the provided condition evaluates to true.

ParamètreDescription
conditionBoolean flag determining whether to skip.
messageJustification for skipping the test.
locationSource location used for skip reporting (automatically captured).
auto fail(std::string message="Explicit test failure", std::source_location location=std::source_location::current()) -> void;

Explicitly fails the current test with a diagnostic message.

ParamètreDescription
messageDiagnostic description explaining why the test failed.
locationSource location used for failure reporting (automatically captured).
template <String::Hasher eventName = Type::Hash{}, class... Args, class Emitter>
auto watch(Emitter& emitter);

Creates an RAII EventWatcher to observe emitted events.

Paramètre templateDescription
eventNameHashed string identifying the event.
ArgsPayload parameter types.
ParamètreDescription
emitterEvent emitter instance to subscribe to.

Retourne : EventWatcher instance managing event subscription.

auto benchmark(std::string name, Type::Callable auto&& function) -> BenchmarkResult;

Times the synchronous execution of a callable.

ParamètreDescription
nameDiagnostic identifier of the benchmark.
functionCallable to measure.

Retourne : BenchmarkResult containing measured duration in nanoseconds.

auto compareBenchmarks(const BenchmarkResult& first, const BenchmarkResult& second) -> BenchmarkComparison;

Compares two benchmark results, logs their relative speedup, and returns the comparison.

ParamètreDescription
firstFirst benchmark result (candidate).
secondSecond benchmark result (baseline).

Retourne : BenchmarkComparison structure with speedup and relative performance analysis.

auto warnIfSlower(const BenchmarkResult& candidate, const BenchmarkResult& baseline) -> void;

Emits a warning log if a candidate benchmark ran slower than a baseline benchmark.

ParamètreDescription
candidateBenchmark result being evaluated.
baselineReference benchmark result.
auto fuzz(std::string name, std::size_t iterations, Type::Callable<Math::DeterministicRandomEngine &> auto&& function, std::uint64_t seed=Math::DeterministicRandomEngine::defaultSeed, std::source_location location=std::source_location::current()) -> void;

Executes a fuzz testing loop passing a DeterministicRandomEngine to the test body.

ParamètreDescription
nameDescriptive identifier of the fuzz test.
iterationsNumber of iterations to execute.
functionTest callback receiving a DeterministicRandomEngine&.
seedInitial pseudo-random number generator seed (defaults to DeterministicRandomEngine::defaultSeed).
locationSource location used for failure reporting (automatically captured).
auto executeTests(TestSettings settings) -> int;

Runs all registered test suites respecting dependency order and configuration settings.

ParamètreDescription
settingsExecution settings controlling verbose output, filtering, and abort conditions.

Retourne : Exit code: 0 on success, non-zero if any test suite failed.

auto executeCommands(std::span<const std::string_view> arguments) -> TestSettings;

Parses command-line arguments into a TestSettings configuration object.

ParamètreDescription
argumentsSpan of command-line argument tokens.

Retourne : Parsed TestSettings configuration.

auto executeCommands(int argc, const char* const argv[]) -> TestSettings;

Parses standard main() arguments (argc, argv) into a TestSettings configuration object.

ParamètreDescription
argcArgument count.
argvArray of argument strings.

Retourne : Parsed TestSettings configuration.