Skip to content

Commit

Permalink
[BUG] SARIF report is not recognized by github #352 (#353)
Browse files Browse the repository at this point in the history
- `results` entry in json need to be an empy vector, not `null` if no error
- logging was adjusted for CLI mode
- relative path calculation was extended for the case of CLI run inside the project folder
  • Loading branch information
alexey-utkin authored Jul 27, 2022
1 parent 465c838 commit 90d1d38
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion server/src/KleeRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void KleeRunner::runKlee(const std::vector<tests::TestMethod> &testMethods,
fileToMethods[method.sourceFilePath].push_back(method);
}

nlohmann::json sarifResults;
nlohmann::json sarifResults = nlohmann::json::array();

std::function<void(tests::Tests &tests)> prepareTests = [&](tests::Tests &tests) {
fs::path filePath = tests.sourceFilePath;
Expand Down
5 changes: 3 additions & 2 deletions server/src/SARIFGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace sarif {
}
++p;
}
if (foundStartFragment && p == path.end()) {
if (p == path.end()) {
while (s != src.end()) {
relToProject = relToProject / *s;
++s;
Expand Down Expand Up @@ -77,6 +77,7 @@ namespace sarif {
const fs::path &relPathInProject = getInProjectPath(projectContext.projectPath, srcPath);
const fs::path &fullPathInProject = projectContext.projectPath / relPathInProject;
if (Paths::isSubPathOf(projectContext.buildDir, fullPathInProject)) {
LOG_S(DEBUG) << "Full path " << fullPathInProject << " is in build - skip it";
continue;
}
if (!relPathInProject.empty() && fs::exists(fullPathInProject)) {
Expand Down Expand Up @@ -119,7 +120,7 @@ namespace sarif {
codeFlowsLocations["locations"].push_back(locationWrapper);
} else {
// the rest is the KLEE calls that are not applicable for navigation
LOG_S(INFO) << "Skip path in stack frame :" << srcPath;
LOG_S(DEBUG) << "Skip path in stack frame :" << srcPath;
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions server/src/streams/tests/CLITestsWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ void CLITestsWriter::writeTestsWithProgress(tests::TestsMap &testMap,
LOG_S(INFO) << "total test files generated: " << totalTestsCounter;
}

void CLITestsWriter::writeReport(const std::string &content,
const std::string &message,
const fs::path &pathToStore) const {
TestsWriter::writeReport(content, message, pathToStore);
LOG_S(INFO) << message;
}

bool CLITestsWriter::writeTestFile(const tests::Tests &tests, const fs::path &testDirPath) {
fs::path testFilePath = testDirPath / tests.relativeFileDir / tests.testFilename;
FileSystemUtils::writeToFile(testFilePath, tests.code);
Expand Down
4 changes: 4 additions & 0 deletions server/src/streams/tests/CLITestsWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ class CLITestsWriter : public TestsWriter {
std::function<void(tests::Tests &)> &&prepareTests,
std::function<void()> &&prepareTotal) override;

void writeReport(const std::string &content,
const std::string &message,
const fs::path &pathToStore) const override;

private:
static bool writeTestFile(const tests::Tests &tests, const fs::path &testDirPath);
};
Expand Down

0 comments on commit 90d1d38

Please sign in to comment.