Skip to content

Commit

Permalink
Add unittest for external interpreter use
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronj0 committed Oct 31, 2024
1 parent 6b91054 commit abe0d5a
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions unittests/CppInterOp/InterpreterTest.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@

#include "Utils.h"

#include "clang/Interpreter/CppInterOp.h"

#ifdef USE_CLING
#include "cling/Interpreter/Interpreter.h"
#endif // USE_CLING

#ifdef USE_REPL
#include "clang/Interpreter/Interpreter.h"
#endif // USE_REPL

#include "clang/Basic/Version.h"

#include "llvm/ADT/SmallString.h"
Expand Down Expand Up @@ -162,3 +172,35 @@ TEST(InterpreterTest, CodeCompletion) {
GTEST_SKIP();
#endif
}

TEST(InterpreterTest, ExternalInterpreterTest) {

#ifdef USE_REPL
llvm::ExitOnError ExitOnErr;
clang::IncrementalCompilerBuilder CB;
CB.SetCompilerArgs({"-std=c++20"});

// Create the incremental compiler instance.
std::unique_ptr<clang::CompilerInstance> CI;
CI = ExitOnErr(CB.CreateCpp());

// Create the interpreter instance.
std::unique_ptr<clang::Interpreter> I =
ExitOnErr(clang::Interpreter::create(std::move(CI)));
#endif

#ifdef USE_CLING
std::string MainExecutableName = sys::fs::getMainExecutable(nullptr, nullptr);
std::string ResourceDir = compat::MakeResourceDir(LLVM_BINARY_DIR);
std::vector<const char *> ClingArgv = {"-resource-dir", ResourceDir.c_str(),
"-std=c++14"};
ClingArgv.insert(ClingArgv.begin(), MainExecutableName.c_str());
std::unique_ptr<cling::Interpreter> I(ClingArgv.size(), &ClingArgv[0]);
#endif

auto ExtInterp = I.get();
EXPECT_NE(ExtInterp, nullptr);
Cpp::UseExternalInterpreter(ExtInterp);
EXPECT_FALSE(Cpp::OwnsInterpreter());
I.release();
}

0 comments on commit abe0d5a

Please sign in to comment.