Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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
1 change: 1 addition & 0 deletions unittests/CppInterOp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ add_cppinterop_unittest(CppInterOpTests
TypeReflectionTest.cpp
Utils.cpp
VariableReflectionTest.cpp
PathsTest.cpp
${EXTRA_TEST_SOURCE_FILES}
)

Expand Down
40 changes: 40 additions & 0 deletions unittests/CppInterOp/PathsTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "gtest/gtest.h"
#include "clang/Lex/HeaderSearchOptions.h"
#include "llvm/ADT/SmallVector.h"
#include <string>
#include <algorithm>
#include <string>


#include "../../lib/CppInterOp/Paths.h"

namespace {

TEST(PathsTest, CopyIncludePathsEdgeCases) {
clang::HeaderSearchOptions Opts;

// Set up edge-case flags to trigger uncovered branches
Opts.ModuleCachePath = "/tmp/fake_cache"; // Triggers -fmodule-cache-path
Opts.UseStandardSystemIncludes = false; // Triggers -nostdinc
Opts.UseStandardCXXIncludes = false; // Triggers -nostdinc++
Opts.UseLibcxx = true; // Triggers -stdlib=libc++
Opts.Verbose = true; // Triggers -v

llvm::SmallVector<std::string, 16> IncPaths;

CppInternal::utils::CopyIncludePaths(Opts, IncPaths, true, true);

auto Contains = [&](const std::string& flag) {
return std::find(IncPaths.begin(), IncPaths.end(), flag) != IncPaths.end();
};

// Verify the results
EXPECT_TRUE(Contains("-fmodule-cache-path"));
EXPECT_TRUE(Contains("/tmp/fake_cache"));
EXPECT_TRUE(Contains("-nostdinc"));
EXPECT_TRUE(Contains("-nostdinc++"));
EXPECT_TRUE(Contains("-stdlib=libc++"));
EXPECT_TRUE(Contains("-v"));
}

} // end anonymous namespace
Loading