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 30, 2024
1 parent 6b91054 commit 417bcd7
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions unittests/CppInterOp/InterpreterTest.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
#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 +171,33 @@ TEST(InterpreterTest, CodeCompletion) {
GTEST_SKIP();
#endif
}

TEST(InterpreterTest, ExternalInterpreterTest) {

#ifdef USE_REPL
llvm::ExitOnError ExitOnErr;
clang::IncrementalCompilerBuilder CB;
CB.SetCompilerArgs({"-std=c++20"}); // pass `-xc` for a C REPL.

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

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

auto ExtInterp = I.get();
#endif

#ifdef USE_CLING
const char* LLVMRESDIR = "/usr/local/"; // path to llvm resource directory
cling::Interpreter interp(argc, argv, LLVMRESDIR);
compat::Interpreter ExtInterp = &interp;
#endif

std::cout << "External Interpreter:" << ExtInterp;
EXPECT_NE(ExtInterp, nullptr);
Cpp::UseExternalInterpreter(ExtInterp);
EXPECT_FALSE(Cpp::OwnsInterpreter());
}

0 comments on commit 417bcd7

Please sign in to comment.