Skip to content

Commit 90d1d38

Browse files
authored
[BUG] SARIF report is not recognized by github #352 (#353)
- `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
1 parent 465c838 commit 90d1d38

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

server/src/KleeRunner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void KleeRunner::runKlee(const std::vector<tests::TestMethod> &testMethods,
4545
fileToMethods[method.sourceFilePath].push_back(method);
4646
}
4747

48-
nlohmann::json sarifResults;
48+
nlohmann::json sarifResults = nlohmann::json::array();
4949

5050
std::function<void(tests::Tests &tests)> prepareTests = [&](tests::Tests &tests) {
5151
fs::path filePath = tests.sourceFilePath;

server/src/SARIFGenerator.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace sarif {
3535
}
3636
++p;
3737
}
38-
if (foundStartFragment && p == path.end()) {
38+
if (p == path.end()) {
3939
while (s != src.end()) {
4040
relToProject = relToProject / *s;
4141
++s;
@@ -77,6 +77,7 @@ namespace sarif {
7777
const fs::path &relPathInProject = getInProjectPath(projectContext.projectPath, srcPath);
7878
const fs::path &fullPathInProject = projectContext.projectPath / relPathInProject;
7979
if (Paths::isSubPathOf(projectContext.buildDir, fullPathInProject)) {
80+
LOG_S(DEBUG) << "Full path " << fullPathInProject << " is in build - skip it";
8081
continue;
8182
}
8283
if (!relPathInProject.empty() && fs::exists(fullPathInProject)) {
@@ -119,7 +120,7 @@ namespace sarif {
119120
codeFlowsLocations["locations"].push_back(locationWrapper);
120121
} else {
121122
// the rest is the KLEE calls that are not applicable for navigation
122-
LOG_S(INFO) << "Skip path in stack frame :" << srcPath;
123+
LOG_S(DEBUG) << "Skip path in stack frame :" << srcPath;
123124
}
124125
}
125126
}

server/src/streams/tests/CLITestsWriter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ void CLITestsWriter::writeTestsWithProgress(tests::TestsMap &testMap,
2424
LOG_S(INFO) << "total test files generated: " << totalTestsCounter;
2525
}
2626

27+
void CLITestsWriter::writeReport(const std::string &content,
28+
const std::string &message,
29+
const fs::path &pathToStore) const {
30+
TestsWriter::writeReport(content, message, pathToStore);
31+
LOG_S(INFO) << message;
32+
}
33+
2734
bool CLITestsWriter::writeTestFile(const tests::Tests &tests, const fs::path &testDirPath) {
2835
fs::path testFilePath = testDirPath / tests.relativeFileDir / tests.testFilename;
2936
FileSystemUtils::writeToFile(testFilePath, tests.code);

server/src/streams/tests/CLITestsWriter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ class CLITestsWriter : public TestsWriter {
1616
std::function<void(tests::Tests &)> &&prepareTests,
1717
std::function<void()> &&prepareTotal) override;
1818

19+
void writeReport(const std::string &content,
20+
const std::string &message,
21+
const fs::path &pathToStore) const override;
22+
1923
private:
2024
static bool writeTestFile(const tests::Tests &tests, const fs::path &testDirPath);
2125
};

0 commit comments

Comments
 (0)