|
32 | 32 | #include "utils/stats/TestsGenerationStats.h"
|
33 | 33 | #include "utils/stats/TestsExecutionStats.h"
|
34 | 34 | #include "utils/TypeUtils.h"
|
| 35 | +#include "utils/JsonUtils.h" |
35 | 36 | #include "building/ProjectBuildDatabase.h"
|
36 | 37 |
|
37 | 38 | #include <thread>
|
@@ -237,6 +238,49 @@ Status Server::TestsGenServiceImpl::ProcessBaseTestRequest(BaseTestGen &testGen,
|
237 | 238 |
|
238 | 239 | FeaturesFilter::filter(testGen.settingsContext, typesHandler, testGen.tests);
|
239 | 240 | StubsCollector(typesHandler).collect(testGen.tests);
|
| 241 | + if (!testGen.projectContext.itfPath.string().empty()) { |
| 242 | + try { |
| 243 | + fs::path fullFilePath = Paths::getFileFullPath(testGen.projectContext.itfPath, |
| 244 | + testGen.projectContext.projectPath); |
| 245 | + if (!fs::exists(fullFilePath)) { |
| 246 | + std::string message = "File with init and teardown functions, doesn't exists"; |
| 247 | + LOG_S(ERROR) << message; |
| 248 | + throw EnvironmentException(message); |
| 249 | + } |
| 250 | + LOG_S(INFO) << "Use init and teardown functions from: " << fullFilePath; |
| 251 | + nlohmann::json itfJson = JsonUtils::getJsonFromFile(fullFilePath); |
| 252 | + auto defaultInitIt = itfJson.find("default init"); |
| 253 | + std::string defaultInitial = itfJson.value("default init", ""); |
| 254 | + std::string defaultTeardown = itfJson.value("default teardown", ""); |
| 255 | + |
| 256 | + std::optional<nlohmann::json> initJson = std::nullopt; |
| 257 | + if (itfJson.contains("init")) { |
| 258 | + initJson = itfJson.at("init"); |
| 259 | + } |
| 260 | + |
| 261 | + std::optional<nlohmann::json> teardownJson = std::nullopt; |
| 262 | + if (itfJson.contains("teardown")) { |
| 263 | + teardownJson = itfJson.at("teardown"); |
| 264 | + } |
| 265 | + for (tests::TestsMap::iterator it = testGen.tests.begin(); it != testGen.tests.end(); ++it) { |
| 266 | + tests::Tests &tests = it.value(); |
| 267 | + for (tests::Tests::MethodsMap::iterator testsIt = tests.methods.begin(); |
| 268 | + testsIt != tests.methods.end(); testsIt++) { |
| 269 | + const std::string &methodName = testsIt.key(); |
| 270 | + tests::Tests::MethodDescription &method = testsIt.value(); |
| 271 | + if (initJson.has_value()) { |
| 272 | + method.initFunction = initJson->value(methodName, defaultInitial); |
| 273 | + } |
| 274 | + if (teardownJson.has_value()) { |
| 275 | + method.teardownFunction = teardownJson->value(methodName, defaultTeardown); |
| 276 | + } |
| 277 | + } |
| 278 | + } |
| 279 | + } catch (const std::exception &e) { |
| 280 | + LOG_S(ERROR) << e.what(); |
| 281 | + throw EnvironmentException(e.what()); |
| 282 | + } |
| 283 | + } |
240 | 284 |
|
241 | 285 | PathSubstitution pathSubstitution = {};
|
242 | 286 | if (lineTestGen != nullptr) {
|
@@ -627,7 +671,10 @@ Server::TestsGenServiceImpl::ConfigureProject(ServerContext *context,
|
627 | 671 |
|
628 | 672 | MEASURE_FUNCTION_EXECUTION_TIME
|
629 | 673 |
|
| 674 | + LOG_S(ERROR) << "ITF request path: " << request->projectcontext().itfpath(); |
630 | 675 | utbot::ProjectContext utbotProjectContext{request->projectcontext()};
|
| 676 | + LOG_S(ERROR) << "ITF request2 path: " << utbotProjectContext.itfPath; |
| 677 | + |
631 | 678 | fs::path buildDirPath =
|
632 | 679 | fs::path(utbotProjectContext.projectPath) / utbotProjectContext.buildDirRelativePath;
|
633 | 680 | switch (request->configmode()) {
|
|
0 commit comments