Skip to content

Commit d2c2157

Browse files
author
William Jakobsson
committed
test
1 parent 77ac3ce commit d2c2157

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

lib/importproject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class CPPCHECKLIB WARN_UNUSED ImportProject {
110110
bool importCompileCommands(std::istream &istr);
111111
bool importCppcheckGuiProject(std::istream &istr, Settings &settings, Suppressions &supprs);
112112
static std::string collectArgs(const std::string &cmd, std::vector<std::string> &args);
113+
void setRelativePaths(const std::string &filename);
113114

114115
struct SharedItemsProject {
115116
bool successful = false;
@@ -123,7 +124,6 @@ class CPPCHECKLIB WARN_UNUSED ImportProject {
123124

124125
private:
125126
static void parseArgs(FileSettings &fs, const std::vector<std::string> &args);
126-
void setRelativePaths(const std::string &filename);
127127

128128
bool importSln(std::istream &istr, const std::string &path, const std::vector<std::string> &fileFilters);
129129
bool importSlnx(const std::string& filename, const std::vector<std::string>& fileFilters);

test/testimportproject.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class TestImporter final : public ImportProject {
4242
using ImportProject::collectArgs;
4343
using ImportProject::fsSetDefines;
4444
using ImportProject::fsSetIncludePaths;
45+
using ImportProject::setRelativePaths;
4546
};
4647

4748

@@ -56,6 +57,7 @@ class TestImportProject : public TestFixture {
5657
TEST_CASE(setIncludePaths1);
5758
TEST_CASE(setIncludePaths2);
5859
TEST_CASE(setIncludePaths3); // macro names are case insensitive
60+
TEST_CASE(setRelativePathsInclude); // #14746
5961
TEST_CASE(importCompileCommands1);
6062
TEST_CASE(importCompileCommands2); // #8563, #9567
6163
TEST_CASE(importCompileCommands3); // check with existing trailing / in directory
@@ -134,6 +136,17 @@ class TestImportProject : public TestFixture {
134136
ASSERT_EQUALS("c:/abc/other/", fs.includePaths.front());
135137
}
136138

139+
void setRelativePathsInclude() const {
140+
const std::string cwd = Path::fromNativeSeparators(Path::getCurrentPath());
141+
TestImporter importer;
142+
FileSettings fs{cwd + "/sub/a.c", Standards::Language::None, 0};
143+
fs.includePaths.push_back(cwd + "/");
144+
importer.fileSettings.push_back(std::move(fs));
145+
importer.setRelativePaths("project.json");
146+
ASSERT_EQUALS(".", importer.fileSettings.cbegin()->includePaths.front());
147+
ASSERT_EQUALS("sub/a.c", importer.fileSettings.cbegin()->filename());
148+
}
149+
137150
void importCompileCommands1() const {
138151
REDIRECT;
139152
constexpr char json[] = R"([{

0 commit comments

Comments
 (0)