Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 7 additions & 0 deletions simplecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3278,6 +3278,13 @@ static std::string getFileIdPath(const std::map<std::string, simplecpp::TokenLis
if (!match.empty()) {
return match;
}
// if the file exists but hasn't been loaded yet then we need to stop searching here or we could get a false match
std::ifstream f;
openHeader(f, relativeOrAbsoluteFilename);
if (f.is_open()) {
f.close();
return "";
}
} else if (filedata.find(header) != filedata.end()) {
return header;// system header that its file is already in the filedata - return that as is
}
Expand Down
41 changes: 41 additions & 0 deletions test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2990,6 +2990,43 @@ static void fuzz_crash()
}
}

static void same_name()
{
const char code[] = "#include <header_a.h>\n"
"#include <header_b.h>\n"
"TEST\n";

simplecpp::DUI dui;
dui.includePaths.push_back("./testsuite/path-tests/include_a");
Comment thread
danmar marked this conversation as resolved.
Outdated
dui.includePaths.push_back("./testsuite/path-tests/include_b");

ASSERT_EQUALS("\n\nOK", preprocess(code, dui));
}

static void file_id()
{
const char code[] = "#include \"once.h\"\n"
"#include \"Once.h\"\n"
Comment thread
danmar marked this conversation as resolved.
Outdated

"#include <once.h>\n"
"#include <Once.h>\n"

"#include \"../path-tests/once.h\"\n"
"#include \"../path-tests/Once.h\"\n"
"#include \"../Path-Tests/once.h\"\n"
"#include \"../Path-Tests/Once.h\"\n"

"#include \"include_a/../once.h\"\n"
"#include \"include_a/../Once.h\"\n"
"#include \"include_A/../once.h\"\n"
"#include \"include_A/../Once.h\"\n";

simplecpp::DUI dui;
dui.includePaths.push_back("./testsuite/path-tests");

ASSERT_EQUALS("\n#line 2 \"testsuite/path-tests/once.h\"\nONCE", preprocess(code, dui));
}

int main(int argc, char **argv)
{
TEST_CASE(backslash);
Expand Down Expand Up @@ -3212,6 +3249,10 @@ int main(int argc, char **argv)

TEST_CASE(warning);

// path resolution
TEST_CASE(same_name);
TEST_CASE(file_id);

// utility functions.
TEST_CASE(simplifyPath);
TEST_CASE(simplifyPath_cppcheck);
Expand Down
1 change: 1 addition & 0 deletions testsuite/path-tests/include_a/header_a.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "same_name.h"
1 change: 1 addition & 0 deletions testsuite/path-tests/include_a/same_name.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#define TEST E
1 change: 1 addition & 0 deletions testsuite/path-tests/include_b/header_b.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "same_name.h"
1 change: 1 addition & 0 deletions testsuite/path-tests/include_b/same_name.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#define TEST OK
2 changes: 2 additions & 0 deletions testsuite/path-tests/once.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#pragma once
ONCE
Loading