diff options
author | Jade Lovelace <lix@jade.fyi> | 2024-07-05 15:52:55 +0200 |
---|---|---|
committer | Jade Lovelace <lix@jade.fyi> | 2024-07-13 00:56:37 +0200 |
commit | f9641b9efd2478929e4811209111c3ca76836d68 (patch) | |
tree | 5462c1cd966af4684a4b849ca0fec130d8397a67 /tests/unit/libutil-support | |
parent | dde51af97df647e423943d63b5f65b55bf35d811 (diff) |
libutil: add checked arithmetic tools
This is in preparation for adding checked arithmetic to the evaluator.
Change-Id: I6e115ce8f5411feda1706624977a4dcd5efd4d13
Diffstat (limited to 'tests/unit/libutil-support')
-rw-r--r-- | tests/unit/libutil-support/tests/gtest-with-params.hh | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/unit/libutil-support/tests/gtest-with-params.hh b/tests/unit/libutil-support/tests/gtest-with-params.hh new file mode 100644 index 000000000..323a083fe --- /dev/null +++ b/tests/unit/libutil-support/tests/gtest-with-params.hh @@ -0,0 +1,54 @@ +#pragma once +// SPDX-FileCopyrightText: 2014 Emil Eriksson +// +// SPDX-License-Identifier: BSD-2-Clause +// +// The lion's share of this code is copy pasted directly out of RapidCheck +// headers, so the copyright is set accordingly. +/** + * @file Implements the ability to run a RapidCheck test under gtest with changed + * test parameters such as the number of tests to run. This is useful for + * running very large numbers of the extremely cheap property tests. + */ + +#include <gtest/gtest.h> +#include <rapidcheck/gtest.h> +#include <rapidcheck/gen/Arbitrary.hpp> + +namespace rc::detail { + +using MakeTestParams = TestParams (*)(); + +template<typename Testable> +void checkGTestWith(Testable && testable, MakeTestParams makeTestParams) +{ + const auto testInfo = ::testing::UnitTest::GetInstance()->current_test_info(); + detail::TestMetadata metadata; + metadata.id = std::string(testInfo->test_case_name()) + "/" + std::string(testInfo->name()); + metadata.description = std::string(testInfo->name()); + + const auto result = checkTestable(std::forward<Testable>(testable), metadata, makeTestParams()); + + if (result.template is<detail::SuccessResult>()) { + const auto success = result.template get<detail::SuccessResult>(); + if (!success.distribution.empty()) { + printResultMessage(result, std::cout); + std::cout << std::endl; + } + } else { + std::ostringstream ss; + printResultMessage(result, ss); + FAIL() << ss.str() << std::endl; + } +} +} + +#define RC_GTEST_PROP_WITH_PARAMS(TestCase, Name, MakeParams, ArgList) \ + void rapidCheck_propImpl_##TestCase##_##Name ArgList; \ + \ + TEST(TestCase, Name) \ + { \ + ::rc::detail::checkGTestWith(&rapidCheck_propImpl_##TestCase##_##Name, MakeParams); \ + } \ + \ + void rapidCheck_propImpl_##TestCase##_##Name ArgList |