Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions lib/analyzerinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,13 @@ bool AnalyzerInformation::skipAnalysis(const tinyxml2::XMLDocument &analyzerInfo

std::string AnalyzerInformation::getAnalyzerInfoFileFromFilesTxt(std::istream& filesTxt, const std::string &sourcefile, const std::string &cfg, int fileIndex)
{
const std::string id = (fileIndex > 0) ? std::to_string(fileIndex) : "";
std::string line;
const std::string end(sep + cfg + sep + id + sep + Path::simplifyPath(sourcefile));
while (std::getline(filesTxt,line)) {
if (line.size() <= end.size() + 2U)
continue;
if (!endsWith(line, end.c_str(), end.size()))
continue;
return line.substr(0,line.find(sep));
AnalyzerInformation::Info filesTxtInfo;
if (!filesTxtInfo.parse(line))
continue; // TODO: report error?
if (endsWith(sourcefile, filesTxtInfo.sourceFile) && filesTxtInfo.cfg == cfg && filesTxtInfo.fileIndex == fileIndex)
return filesTxtInfo.afile;
}
return "";
}
Expand Down
5 changes: 5 additions & 0 deletions lib/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ bool endsWith(const std::string& str, const char (&end)[N])
return endsWith(str, end, N - 1);
}

inline bool endsWith(const std::string& str, const std::string& end)
{
return endsWith(str, end.c_str(), end.length());
}

inline static bool isPrefixStringCharLiteral(const std::string &str, char q, const std::string& p)
{
// str must be at least the prefix plus the start and end quote
Expand Down
14 changes: 9 additions & 5 deletions test/testanalyzerinformation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,23 @@ class TestAnalyzerInformation : public TestFixture {
};

void run() override {
TEST_CASE(getAnalyzerInfoFileFromFilesTxt);
TEST_CASE(getAnalyzerInfoFile);
TEST_CASE(duplicateFile);
TEST_CASE(filesTextDuplicateFile);
TEST_CASE(parse);
TEST_CASE(skipAnalysis);
}

void getAnalyzerInfoFile() const {
void getAnalyzerInfoFileFromFilesTxt() const {
constexpr char filesTxt[] = "file1.a4:::file1.c\n";
std::istringstream f1(filesTxt);
ASSERT_EQUALS("file1.a4", AnalyzerInformationTest::getAnalyzerInfoFileFromFilesTxt(f1, "file1.c", "", 0));
std::istringstream f2(filesTxt);
ASSERT_EQUALS("file1.a4", AnalyzerInformationTest::getAnalyzerInfoFileFromFilesTxt(f2, "./file1.c", "", 0));
std::istringstream f(filesTxt);
ASSERT_EQUALS("file1.a4", AnalyzerInformationTest::getAnalyzerInfoFileFromFilesTxt(f, "file1.c", "", 0));
f.str(filesTxt);
ASSERT_EQUALS("file1.a4", AnalyzerInformationTest::getAnalyzerInfoFileFromFilesTxt(f, "./file1.c", "", 0));
}

void getAnalyzerInfoFile() const {
ASSERT_EQUALS("builddir/file1.c.analyzerinfo", AnalyzerInformation::getAnalyzerInfoFile("builddir", "file1.c", "", 0));
ASSERT_EQUALS("builddir/file1.c.analyzerinfo", AnalyzerInformation::getAnalyzerInfoFile("builddir", "some/path/file1.c", "", 0));
}
Expand Down
12 changes: 12 additions & 0 deletions test/testutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class TestUtils : public TestFixture {
TEST_CASE(splitString);
TEST_CASE(as_const);
TEST_CASE(memoize);
TEST_CASE(endsWith);
}

void isValidGlobPattern() const {
Expand Down Expand Up @@ -563,6 +564,17 @@ class TestUtils : public TestFixture {
ASSERT_EQUALS(1, callF());
ASSERT_EQUALS(1, count);
}

void endsWith() const
{
ASSERT(::endsWith("test", "test"));
ASSERT(::endsWith("test2", "2"));
ASSERT(::endsWith("test test", "test"));
ASSERT(::endsWith("test", "t"));
ASSERT(!::endsWith("", "test"));
ASSERT(!::endsWith("tes", "test"));
ASSERT(!::endsWith("2test", "2"));
}
};

REGISTER_TEST(TestUtils)