Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src/Progmasoft/StrategyContext.cpp
diff options
context:
space:
mode:
authorLeitwolf2026-10-25 10:31:36 +0300
committerGitHub2026-10-25 10:31:36 +0300
commitd2e3e074bb2e1b8ffd9fc990d0b87667ea602f58 (patch)
tree0bce4462b2e190c39b3e1c5f697e3e4abd1a5e2a /src/Progmasoft/StrategyContext.cpp
parent13f81a480a93807c14dddb5abdb97355ced4d4c5 (diff)
parent126dc333564cb72b5115d9a9242d66694694b6d0 (diff)
downloadcatch3-d2e3e074bb2e1b8ffd9fc990d0b87667ea602f58.tar.gz
Merge pull request #18 from Progmasoft/build/catch3-identity
Give Catch3 its own build names and headers
Diffstat (limited to 'src/Progmasoft/StrategyContext.cpp')
-rw-r--r--src/Progmasoft/StrategyContext.cpp125
1 files changed, 125 insertions, 0 deletions
diff --git a/src/Progmasoft/StrategyContext.cpp b/src/Progmasoft/StrategyContext.cpp
new file mode 100644
index 00000000..476b41de
--- /dev/null
+++ b/src/Progmasoft/StrategyContext.cpp
@@ -0,0 +1,125 @@
+// Copyright (c) 2026 Progmasoft.
+// SPDX-License-Identifier: MPL-2.0 WITH AdditionRef-Progmasoft-Exception-1.1
+#include <Progmasoft/Catch3/Strategy/Context.hpp>
+#include <string>
+#include <utility>
+
+namespace Progmasoft::Catch3
+{
+
+ namespace
+ {
+
+ thread_local TrialRecord *currentRecord = nullptr;
+ thread_local const std::string *defaultPropertyName = nullptr;
+
+ } // namespace
+
+ namespace Detail
+ {
+
+ TrialRecord *
+ CurrentTrialRecord() noexcept
+ {
+ return currentRecord;
+ }
+
+ TrialRecordScope::TrialRecordScope(TrialRecord &record) noexcept
+ : previous_(currentRecord)
+ {
+ currentRecord = &record;
+ }
+
+ TrialRecordScope::~TrialRecordScope()
+ {
+ currentRecord = previous_;
+ }
+
+ void
+ RecordPropertyFailure(std::string_view expression,
+ std::string_view file,
+ std::size_t line)
+ {
+ if (currentRecord == nullptr)
+ {
+ return;
+ }
+ // Only the first failure of a trial counts: it is the one the
+ // body stopped at.
+ if (!currentRecord->Failure.has_value())
+ {
+ currentRecord->Failure = "CATCH3_PROPERTY_ASSERT( "
+ + std::string(expression) + " ) at "
+ + std::string(file) + ":"
+ + std::to_string(line);
+ }
+ }
+
+ void
+ RecordPropertyFailureMessage(std::string message)
+ {
+ if (currentRecord != nullptr && !currentRecord->Failure.has_value())
+ {
+ currentRecord->Failure = std::move(message);
+ }
+ }
+
+ std::string
+ DefaultPropertyName()
+ {
+ return defaultPropertyName != nullptr ? *defaultPropertyName
+ : std::string();
+ }
+
+ PropertyNameScope::PropertyNameScope(std::string name)
+ : name_(std::move(name))
+ , previous_(defaultPropertyName)
+ {
+ defaultPropertyName = &name_;
+ }
+
+ PropertyNameScope::~PropertyNameScope()
+ {
+ defaultPropertyName = previous_;
+ }
+
+ } // namespace Detail
+
+ void
+ Note(std::string text)
+ {
+ if (currentRecord != nullptr)
+ {
+ currentRecord->Notes.push_back(std::move(text));
+ }
+ }
+
+ void
+ Classify(bool condition, std::string label)
+ {
+ if (currentRecord != nullptr && condition)
+ {
+ currentRecord->Labels.push_back(std::move(label));
+ }
+ }
+
+ void
+ Cover(double requiredPercentage, bool condition, std::string label)
+ {
+ if (currentRecord != nullptr)
+ {
+ currentRecord->Covers.push_back(
+ { std::move(label), requiredPercentage, condition });
+ }
+ }
+
+ void
+ Target(double score, std::string label)
+ {
+ if (currentRecord != nullptr)
+ {
+ currentRecord->Targets.push_back({ std::move(label), score });
+ }
+ }
+
+} // namespace Progmasoft::Catch3