Skip to content

Commit 2ef7b8e

Browse files
author
Vladislav Kalugin
committed
refactoring after review 6
1 parent dfdfd3b commit 2ef7b8e

File tree

7 files changed

+37
-30
lines changed

7 files changed

+37
-30
lines changed

server/src/KleeGenerator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class KleeGenerator {
3535
public:
3636
/**
3737
* @brief Also creates tmp directories for build files.
38-
* @param testGen contains request and build information .
38+
* @param testGen contains request and build information.
3939
* @param typesHandler provides additional information about types.
4040
* @param filePathsSubstitution Mapping from source file path to modified file. Required for
4141
* line test generation requests.

server/src/building/CompileCommand.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,7 @@ namespace utbot {
5757
this->sourcePath = it;
5858
*this->sourcePath = sourcePath;
5959
}
60-
{
61-
auto it = findOutput();
62-
if (it != commandLine.end()) {
63-
this->output = it;
64-
*this->output = Paths::getCCJsonFileFullPath(*it, this->directory);
65-
} else {
66-
auto path = Paths::getCCJsonFileFullPath(Paths::replaceExtension(*this->sourcePath, ".o"), this->directory);
67-
this->output = std::next(addFlagsToBegin({ "-o", path }));
68-
}
69-
}
60+
initOutput();
7061
}
7162

7263
void swap(CompileCommand &a, CompileCommand &b) noexcept {
@@ -107,9 +98,22 @@ namespace utbot {
10798
return StringUtils::startsWith(arg, "-I");
10899
});
109100
}
101+
110102
void CompileCommand::removeWerror() {
111103
CollectionUtils::erase_if(commandLine, [](const std::string &arg) {
112104
return StringUtils::startsWith(arg, "-Werror");
113105
});
114106
}
107+
108+
void CompileCommand::initOutput() {
109+
auto it = findOutput();
110+
if (it != commandLine.end()) {
111+
this->output = it;
112+
*this->output = Paths::getCCJsonFileFullPath(*it, this->directory);
113+
} else {
114+
auto path = Paths::getCCJsonFileFullPath(Paths::replaceExtension(*this->sourcePath, ".o"), this->directory);
115+
this->output = std::next(addFlagsToBegin({"-o", path}));
116+
}
117+
118+
}
115119
}

server/src/building/CompileCommand.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ namespace utbot {
1616
private:
1717
iterator sourcePath;
1818

19+
void initOutput();
20+
1921
public:
2022
CompileCommand() = default;
2123

server/src/building/ProjectBuildDatabase.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@
44
#include "BuildDatabase.h"
55

66
class ProjectBuildDatabase : public BuildDatabase {
7-
public:
8-
ProjectBuildDatabase(fs::path _buildCommandsJsonPath, fs::path _serverBuildDir,
9-
utbot::ProjectContext _projectContext);
10-
11-
static std::shared_ptr<ProjectBuildDatabase> create(const utbot::ProjectContext &projectContext);
12-
7+
private:
138
void initObjects(const nlohmann::json &compileCommandsJson);
149

1510
void initInfo(const nlohmann::json &linkCommandsJson);
@@ -20,6 +15,12 @@ class ProjectBuildDatabase : public BuildDatabase {
2015

2116
void fillTargetInfoParents();
2217

18+
public:
19+
ProjectBuildDatabase(fs::path _buildCommandsJsonPath, fs::path _serverBuildDir,
20+
utbot::ProjectContext _projectContext);
21+
22+
static std::shared_ptr<ProjectBuildDatabase> create(const utbot::ProjectContext &projectContext);
23+
2324
bool hasAutoTarget() const override;
2425

2526
fs::path getTargetPath() const override;

server/test/framework/TestUtils.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ namespace testUtils {
212212
const fs::path &projectPath,
213213
const std::string &buildDirRelativePath,
214214
const std::vector<fs::path> &srcPaths,
215-
const std::string &target,
215+
const std::string &targetOrSourcePath,
216216
bool useStubs,
217217
bool verbose,
218218
int kleeTimeout) {
@@ -224,20 +224,20 @@ namespace testUtils {
224224
return GrpcUtils::createProjectRequest(std::move(projectContext),
225225
std::move(settingsContext),
226226
srcPaths,
227-
target);
227+
targetOrSourcePath);
228228
}
229229

230230
std::unique_ptr<FileRequest> createFileRequest(const std::string &projectName,
231231
const fs::path &projectPath,
232232
const std::string &buildDirRelativePath,
233233
const std::vector<fs::path> &srcPaths,
234234
const fs::path &filePath,
235-
const std::string &target,
235+
const std::string &targetOrSourcePath,
236236
bool useStubs,
237237
bool verbose,
238238
int kleeTimeout) {
239239
auto projectRequest = createProjectRequest(projectName, projectPath, buildDirRelativePath,
240-
srcPaths, target, useStubs, verbose, kleeTimeout);
240+
srcPaths, targetOrSourcePath, useStubs, verbose, kleeTimeout);
241241
return GrpcUtils::createFileRequest(std::move(projectRequest), filePath);
242242
}
243243

@@ -247,12 +247,12 @@ namespace testUtils {
247247
const std::vector<fs::path> &srcPaths,
248248
const fs::path &filePath,
249249
int line,
250-
const std::string &target,
250+
const std::string &targetOrSourcePath,
251251
bool useStubs,
252252
bool verbose,
253253
int kleeTimeout) {
254254
auto projectRequest = createProjectRequest(projectName, projectPath, buildDirRelativePath,
255-
srcPaths, target, useStubs, verbose, kleeTimeout);
255+
srcPaths, targetOrSourcePath, useStubs, verbose, kleeTimeout);
256256
auto lineInfo = GrpcUtils::createSourceInfo(filePath, line);
257257
return GrpcUtils::createLineRequest(std::move(projectRequest), std::move(lineInfo));
258258
}
@@ -263,12 +263,12 @@ namespace testUtils {
263263
const std::vector<fs::path> &srcPaths,
264264
const fs::path &filePath,
265265
int line,
266-
const std::string &target,
266+
const std::string &targetOrSourcePath,
267267
bool useStubs,
268268
bool verbose,
269269
int kleeTimeout) {
270270
auto lineRequest = createLineRequest(projectName, projectPath, buildDirRelativePath,
271-
srcPaths, filePath, line, target, useStubs, verbose, kleeTimeout);
271+
srcPaths, filePath, line, targetOrSourcePath, useStubs, verbose, kleeTimeout);
272272
return GrpcUtils::createClassRequest(std::move(lineRequest));
273273
}
274274

server/test/framework/TestUtils.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ namespace testUtils {
6868
const fs::path &projectPath,
6969
const std::string &buildDirRelativePath,
7070
const std::vector<fs::path> &srcPaths,
71-
const std::string &target = GrpcUtils::UTBOT_AUTO_TARGET_PATH,
71+
const std::string &targetOrSourcePath = GrpcUtils::UTBOT_AUTO_TARGET_PATH,
7272
bool useStubs = false,
7373
bool verbose = true,
7474
int kleeTimeout = 60);
@@ -78,7 +78,7 @@ namespace testUtils {
7878
const std::string &buildDirRelativePath,
7979
const std::vector<fs::path> &srcPaths,
8080
const fs::path &filePath,
81-
const std::string &target = GrpcUtils::UTBOT_AUTO_TARGET_PATH,
81+
const std::string &targetOrSourcePath = GrpcUtils::UTBOT_AUTO_TARGET_PATH,
8282
bool useStubs = false,
8383
bool verbose = true,
8484
int kleeTimeout = 60);
@@ -89,7 +89,7 @@ namespace testUtils {
8989
const std::vector<fs::path> &srcPaths,
9090
const fs::path &filePath,
9191
int line,
92-
const std::string &target = GrpcUtils::UTBOT_AUTO_TARGET_PATH,
92+
const std::string &targetOrSourcePath = GrpcUtils::UTBOT_AUTO_TARGET_PATH,
9393
bool useStubs = false,
9494
bool verbose = true,
9595
int kleeTimeout = 60);
@@ -100,7 +100,7 @@ namespace testUtils {
100100
const std::vector<fs::path> &srcPaths,
101101
const fs::path &filePath,
102102
int line,
103-
const std::string &target = GrpcUtils::UTBOT_AUTO_TARGET_PATH,
103+
const std::string &targetOrSourcePath = GrpcUtils::UTBOT_AUTO_TARGET_PATH,
104104
bool useStubs = false,
105105
bool verbose = true,
106106
int kleeTimeout = 60);

server/test/framework/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#include "TestUtils.h"
22
#include "utils/CLIUtils.h"
3+
#include "printers/DefaultMakefilePrinter.h"
34

45
#include "loguru.h"
56

67
#include <llvm/Support/Signals.h>
7-
#include "printers/DefaultMakefilePrinter.h"
88

99
//Usage: ./UTBot_UnitTests [--verbosity trace|debug|info|warning|error]
1010
int main(int argc, char **argv) {

0 commit comments

Comments
 (0)