Skip to content

Commit d39d2d1

Browse files
committed
[tests] Add edge case coverage for CopyIncludePaths in Paths.cpp
1 parent 4ce13f7 commit d39d2d1

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

unittests/CppInterOp/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ add_cppinterop_unittest(CppInterOpTests
2121
TypeReflectionTest.cpp
2222
Utils.cpp
2323
VariableReflectionTest.cpp
24+
PathsTest.cpp
2425
${EXTRA_TEST_SOURCE_FILES}
2526
)
2627

unittests/CppInterOp/PathsTest.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include "gtest/gtest.h"
2+
#include "clang/Lex/HeaderSearchOptions.h"
3+
#include "llvm/ADT/SmallVector.h"
4+
#include <string>
5+
#include <algorithm>
6+
7+
8+
#include "../../lib/CppInterOp/Paths.h"
9+
10+
namespace {
11+
12+
TEST(PathsTest, CopyIncludePathsEdgeCases) {
13+
clang::HeaderSearchOptions Opts;
14+
15+
// Set up edge-case flags to trigger uncovered branches
16+
Opts.ModuleCachePath = "/tmp/fake_cache"; // Triggers -fmodule-cache-path
17+
Opts.UseStandardSystemIncludes = false; // Triggers -nostdinc
18+
Opts.UseStandardCXXIncludes = false; // Triggers -nostdinc++
19+
Opts.UseLibcxx = true; // Triggers -stdlib=libc++
20+
Opts.Verbose = true; // Triggers -v
21+
22+
llvm::SmallVector<std::string, 16> IncPaths;
23+
24+
CppInternal::utils::CopyIncludePaths(Opts, IncPaths, true, true);
25+
26+
auto Contains = [&](const std::string& flag) {
27+
return std::find(IncPaths.begin(), IncPaths.end(), flag) != IncPaths.end();
28+
};
29+
30+
// Verify the results
31+
EXPECT_TRUE(Contains("-fmodule-cache-path"));
32+
EXPECT_TRUE(Contains("/tmp/fake_cache"));
33+
EXPECT_TRUE(Contains("-nostdinc"));
34+
EXPECT_TRUE(Contains("-nostdinc++"));
35+
EXPECT_TRUE(Contains("-stdlib=libc++"));
36+
EXPECT_TRUE(Contains("-v"));
37+
}
38+
39+
} // end anonymous namespace

0 commit comments

Comments
 (0)