Skip to content

Commit bfaa28f

Browse files
aobolenskCopilot
andauthored
Fix functions order check in Task class dtor (#380)
Prevent creating `Task` class with public API usage ignored by checking for invalid API calls order (or its absence) in dtor --------- Co-authored-by: Copilot <[email protected]>
1 parent 26eb045 commit bfaa28f

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

modules/core/task/include/task.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class Task {
6565
std::vector<std::string> right_functions_order_ = {"Validation", "PreProcessing", "Run", "PostProcessing"};
6666
static constexpr double kMaxTestTime = 1.0;
6767
std::chrono::high_resolution_clock::time_point tmp_time_point_;
68+
bool functions_order_validation_ = true;
6869
};
6970

7071
} // namespace ppc::core

modules/core/task/src/task.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <chrono>
44
#include <cstddef>
5+
#include <exception>
56
#include <iomanip>
67
#include <iostream>
78
#include <sstream>
@@ -48,8 +49,9 @@ void ppc::core::Task::InternalOrderTest(const std::string& str) {
4849

4950
for (size_t i = 0; i < functions_order_.size(); i++) {
5051
if (functions_order_[i] != right_functions_order_[i % right_functions_order_.size()]) {
51-
throw std::invalid_argument("ORDER OF FUCTIONS IS NOT RIGHT: \n" + std::string("Serial number: ") +
52-
std::to_string(i + 1) + "\n" + std::string("Yours function: ") + functions_order_[i] +
52+
functions_order_validation_ = false;
53+
throw std::invalid_argument("ORDER OF FUNCTIONS IS NOT RIGHT: \n" + std::string("Serial number: ") +
54+
std::to_string(i + 1) + "\n" + std::string("Your function: ") + functions_order_[i] +
5355
"\n" + std::string("Expected function: ") + right_functions_order_[i]);
5456
}
5557
}
@@ -74,4 +76,21 @@ void ppc::core::Task::InternalOrderTest(const std::string& str) {
7476
}
7577
}
7678

77-
ppc::core::Task::~Task() { functions_order_.clear(); }
79+
ppc::core::Task::~Task() {
80+
if (functions_order_.empty()) {
81+
std::cerr << "ORDER OF FUNCTIONS IS NOT RIGHT: No task functions were executed\n";
82+
std::terminate();
83+
}
84+
if (functions_order_validation_) {
85+
for (size_t i = 0; i < functions_order_.size(); i++) {
86+
if (functions_order_[i] != right_functions_order_[i % right_functions_order_.size()]) {
87+
std::cerr << "ORDER OF FUNCTIONS IS NOT RIGHT: \n"
88+
<< std::string("Serial number: ") << std::to_string(i + 1) << "\n"
89+
<< std::string("Your function: ") << functions_order_[i] << "\n"
90+
<< std::string("Expected function: ") << right_functions_order_[i] << "\n";
91+
std::terminate();
92+
}
93+
}
94+
}
95+
functions_order_.clear();
96+
}

0 commit comments

Comments
 (0)