From e01d95528ea2137a4a27a88d1f57c6cb260aafed Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Mon, 24 Sep 2018 11:57:52 -0700 Subject: Export of internal Abseil changes. -- eca34da4ccb7bb6a580f1364dff9ca053418fa3b by Abseil Team : Internal change. PiperOrigin-RevId: 214305433 -- 35393bdd21a87c4286f945fd34dda93afc4e0cd6 by Abseil Team : Move some implementation details of string_view around to facilitate compiling on NVCC. Abseil does not officially support NVCC as a reminder. PiperOrigin-RevId: 214184876 -- 61846cab9ab9476a4676ecade7173f68978cd038 by Jorg Brown : Move the initialization values for constants back to their declaration. PiperOrigin-RevId: 214135927 -- 7ac7df6c5f78f2faf419268c04618b936cb26065 by Abseil Team : Performance improvements on format parser. PiperOrigin-RevId: 214032366 -- 90b4c0cf20e9feaa257a7ece40adaf7db40a60a7 by Xiaoyi Zhang : Add static_assert check to absl::visit to make sure all overloads of the visitor return the same type, as required by the C++ standard. PiperOrigin-RevId: 213677001 -- 787995342101b4c181291cde9ecea3048536e4bd by Abseil Team : Update comment to indicate finite durations are less than InfiniteDuration. PiperOrigin-RevId: 213660328 -- d78f0dce7cc31218807e96d93b9e8513b6c80b24 by Jon Cohen : s/invariant/contract in the exceptions safety testing framework. This is a better term as these can be type invariants or function post conditions. They also are very similar ground as to what is covered by c++20 Contracts (and could even be replaced by them. PiperOrigin-RevId: 213631019 -- 0b3ff1a640de9a7391a6c233568802cf86245b0e by Abseil Team : Add noinline attribute for GetStackTrace/GetStackFrames/... so the skipped frames will not change because of inlining difference. PiperOrigin-RevId: 213009637 GitOrigin-RevId: eca34da4ccb7bb6a580f1364dff9ca053418fa3b Change-Id: Iff1022fd24e440fcbdf3c4ab2a915ca8954daa31 --- absl/base/internal/exception_safety_testing.h | 138 +++++++++++++------------- 1 file changed, 69 insertions(+), 69 deletions(-) (limited to 'absl/base/internal/exception_safety_testing.h') diff --git a/absl/base/internal/exception_safety_testing.h b/absl/base/internal/exception_safety_testing.h index de4f0e2827cb..5665a1b67db2 100644 --- a/absl/base/internal/exception_safety_testing.h +++ b/absl/base/internal/exception_safety_testing.h @@ -191,19 +191,19 @@ class TrackedObject { ~TrackedObject() noexcept { ConstructorTracker::ObjectDestructed(this); } }; -template -absl::optional TestSingleInvariantAtCountdownImpl( +template +absl::optional TestSingleContractAtCountdownImpl( const Factory& factory, const Operation& operation, int count, - const Invariant& invariant) { + const Contract& contract) { auto t_ptr = factory(); absl::optional current_res; SetCountdown(count); try { operation(t_ptr.get()); } catch (const exceptions_internal::TestException& e) { - current_res.emplace(invariant(t_ptr.get())); + current_res.emplace(contract(t_ptr.get())); if (!current_res.value()) { - *current_res << e.what() << " failed invariant check"; + *current_res << e.what() << " failed contract check"; } } UnsetCountdown(); @@ -211,22 +211,22 @@ absl::optional TestSingleInvariantAtCountdownImpl( } template -absl::optional TestSingleInvariantAtCountdownImpl( +absl::optional TestSingleContractAtCountdownImpl( const Factory& factory, const Operation& operation, int count, StrongGuaranteeTagType) { using TPtr = typename decltype(factory())::pointer; auto t_is_strong = [&](TPtr t) { return *t == *factory(); }; - return TestSingleInvariantAtCountdownImpl(factory, operation, count, - t_is_strong); + return TestSingleContractAtCountdownImpl(factory, operation, count, + t_is_strong); } -template -int TestSingleInvariantAtCountdown( +template +int TestSingleContractAtCountdown( const Factory& factory, const Operation& operation, int count, - const Invariant& invariant, + const Contract& contract, absl::optional* reduced_res) { // If reduced_res is empty, it means the current call to - // TestSingleInvariantAtCountdown(...) is the first test being run so we do + // TestSingleContractAtCountdown(...) is the first test being run so we do // want to run it. Alternatively, if it's not empty (meaning a previous test // has run) we want to check if it passed. If the previous test did pass, we // want to contine running tests so we do want to run the current one. If it @@ -234,22 +234,22 @@ int TestSingleInvariantAtCountdown( // output. If that's the case, we do not run the current test and instead we // simply return. if (!reduced_res->has_value() || reduced_res->value()) { - *reduced_res = TestSingleInvariantAtCountdownImpl(factory, operation, count, - invariant); + *reduced_res = + TestSingleContractAtCountdownImpl(factory, operation, count, contract); } return 0; } -template -inline absl::optional TestAllInvariantsAtCountdown( +template +inline absl::optional TestAllContractsAtCountdown( const Factory& factory, const Operation& operation, int count, - const Invariants&... invariants) { + const Contracts&... contracts) { absl::optional reduced_res; // Run each checker, short circuiting after the first failure int dummy[] = { - 0, (TestSingleInvariantAtCountdown(factory, operation, count, invariants, - &reduced_res))...}; + 0, (TestSingleContractAtCountdown(factory, operation, count, contracts, + &reduced_res))...}; static_cast(dummy); return reduced_res; } @@ -884,15 +884,15 @@ class DefaultFactory { T t_; }; -template using EnableIfTestable = typename absl::enable_if_t< - LazyInvariantsCount != 0 && + LazyContractsCount != 0 && !std::is_same::value && !std::is_same::value>; template + typename Operation = UninitializedT, typename... Contracts> class ExceptionSafetyTester; } // namespace exceptions_internal @@ -903,7 +903,7 @@ namespace exceptions_internal { /* * Builds a tester object that tests if performing a operation on a T follows - * exception safety guarantees. Verification is done via invariant assertion + * exception safety guarantees. Verification is done via contract assertion * callbacks applied to T instances post-throw. * * Template parameters for ExceptionSafetyTester: @@ -921,18 +921,18 @@ namespace exceptions_internal { * fresh T instance so it's free to modify and destroy the T instances as it * pleases. * - * - Invariants...: The invariant assertion callback objects (passed in via - * tester.WithInvariants(...)) must be invocable with the signature + * - Contracts...: The contract assertion callback objects (passed in via + * tester.WithContracts(...)) must be invocable with the signature * `testing::AssertionResult operator()(T*) const` where T is the type being - * tested. Invariant assertion callbacks are provided T instances post-throw. - * They must return testing::AssertionSuccess when the type invariants of the - * provided T instance hold. If the type invariants of the T instance do not + * tested. Contract assertion callbacks are provided T instances post-throw. + * They must return testing::AssertionSuccess when the type contracts of the + * provided T instance hold. If the type contracts of the T instance do not * hold, they must return testing::AssertionFailure. Execution order of - * Invariants... is unspecified. They will each individually get a fresh T + * Contracts... is unspecified. They will each individually get a fresh T * instance so they are free to modify and destroy the T instances as they * please. */ -template +template class ExceptionSafetyTester { public: /* @@ -948,7 +948,7 @@ class ExceptionSafetyTester { * tester.WithFactory(...). */ template - ExceptionSafetyTester, Operation, Invariants...> + ExceptionSafetyTester, Operation, Contracts...> WithInitialValue(const T& t) const { return WithFactory(DefaultFactory(t)); } @@ -961,9 +961,9 @@ class ExceptionSafetyTester { * method tester.WithInitialValue(...). */ template - ExceptionSafetyTester, Operation, Invariants...> + ExceptionSafetyTester, Operation, Contracts...> WithFactory(const NewFactory& new_factory) const { - return {new_factory, operation_, invariants_}; + return {new_factory, operation_, contracts_}; } /* @@ -972,39 +972,39 @@ class ExceptionSafetyTester { * tester. */ template - ExceptionSafetyTester, Invariants...> + ExceptionSafetyTester, Contracts...> WithOperation(const NewOperation& new_operation) const { - return {factory_, new_operation, invariants_}; + return {factory_, new_operation, contracts_}; } /* - * Returns a new ExceptionSafetyTester with the provided MoreInvariants... - * combined with the Invariants... that were already included in the instance - * on which the method was called. Invariants... cannot be removed or replaced + * Returns a new ExceptionSafetyTester with the provided MoreContracts... + * combined with the Contracts... that were already included in the instance + * on which the method was called. Contracts... cannot be removed or replaced * once added to an ExceptionSafetyTester instance. A fresh object must be - * created in order to get an empty Invariants... list. + * created in order to get an empty Contracts... list. * - * In addition to passing in custom invariant assertion callbacks, this method + * In addition to passing in custom contract assertion callbacks, this method * accepts `testing::strong_guarantee` as an argument which checks T instances * post-throw against freshly created T instances via operator== to verify * that any state changes made during the execution of the operation were * properly rolled back. */ - template - ExceptionSafetyTester...> - WithInvariants(const MoreInvariants&... more_invariants) const { - return {factory_, operation_, - std::tuple_cat(invariants_, - std::tuple...>( - more_invariants...))}; + template + ExceptionSafetyTester...> + WithContracts(const MoreContracts&... more_contracts) const { + return { + factory_, operation_, + std::tuple_cat(contracts_, std::tuple...>( + more_contracts...))}; } /* * Returns a testing::AssertionResult that is the reduced result of the * exception safety algorithm. The algorithm short circuits and returns - * AssertionFailure after the first invariant callback returns an - * AssertionFailure. Otherwise, if all invariant callbacks return an + * AssertionFailure after the first contract callback returns an + * AssertionFailure. Otherwise, if all contract callbacks return an * AssertionSuccess, the reduced result is AssertionSuccess. * * The passed-in testable operation will not be saved in a new tester instance @@ -1013,33 +1013,33 @@ class ExceptionSafetyTester { * * Preconditions for tester.Test(const NewOperation& new_operation): * - * - May only be called after at least one invariant assertion callback and a + * - May only be called after at least one contract assertion callback and a * factory or initial value have been provided. */ template < typename NewOperation, - typename = EnableIfTestable> + typename = EnableIfTestable> testing::AssertionResult Test(const NewOperation& new_operation) const { - return TestImpl(new_operation, absl::index_sequence_for()); + return TestImpl(new_operation, absl::index_sequence_for()); } /* * Returns a testing::AssertionResult that is the reduced result of the * exception safety algorithm. The algorithm short circuits and returns - * AssertionFailure after the first invariant callback returns an - * AssertionFailure. Otherwise, if all invariant callbacks return an + * AssertionFailure after the first contract callback returns an + * AssertionFailure. Otherwise, if all contract callbacks return an * AssertionSuccess, the reduced result is AssertionSuccess. * * Preconditions for tester.Test(): * - * - May only be called after at least one invariant assertion callback, a + * - May only be called after at least one contract assertion callback, a * factory or initial value and a testable operation have been provided. */ - template > + template < + typename LazyOperation = Operation, + typename = EnableIfTestable> testing::AssertionResult Test() const { - return TestImpl(operation_, absl::index_sequence_for()); + return TestImpl(operation_, absl::index_sequence_for()); } private: @@ -1051,8 +1051,8 @@ class ExceptionSafetyTester { ExceptionSafetyTester() {} ExceptionSafetyTester(const Factory& f, const Operation& o, - const std::tuple& i) - : factory_(f), operation_(o), invariants_(i) {} + const std::tuple& i) + : factory_(f), operation_(o), contracts_(i) {} template testing::AssertionResult TestImpl(const SelectedOperation& selected_operation, @@ -1064,28 +1064,28 @@ class ExceptionSafetyTester { // Run the full exception safety test algorithm for the current countdown auto reduced_res = - TestAllInvariantsAtCountdown(factory_, selected_operation, count, - std::get(invariants_)...); - // If there is no value in the optional, no invariants were run because no + TestAllContractsAtCountdown(factory_, selected_operation, count, + std::get(contracts_)...); + // If there is no value in the optional, no contracts were run because no // exception was thrown. This means that the test is complete and the loop // can exit successfully. if (!reduced_res.has_value()) { return testing::AssertionSuccess(); } - // If the optional is not empty and the value is falsy, an invariant check + // If the optional is not empty and the value is falsy, an contract check // failed so the test must exit to propegate the failure. if (!reduced_res.value()) { return reduced_res.value(); } // If the optional is not empty and the value is not falsy, it means - // exceptions were thrown but the invariants passed so the test must + // exceptions were thrown but the contracts passed so the test must // continue to run. } } Factory factory_; Operation operation_; - std::tuple invariants_; + std::tuple contracts_; }; } // namespace exceptions_internal @@ -1096,7 +1096,7 @@ class ExceptionSafetyTester { * instances of ExceptionSafetyTester. * * In order to test a T for exception safety, a factory for that T, a testable - * operation, and at least one invariant callback returning an assertion + * operation, and at least one contract callback returning an assertion * result must be applied using the respective methods. */ inline exceptions_internal::ExceptionSafetyTester<> -- cgit 1.4.1