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 2996beb
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 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,30 @@ 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::unique_ptr<cling::Interpreter> I;
#endif

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

0 comments on commit 2996beb

Please sign in to comment.