diff --git a/unittests/CppInterOp/InterpreterTest.cpp b/unittests/CppInterOp/InterpreterTest.cpp index 9b70b8a4..3db57e10 100644 --- a/unittests/CppInterOp/InterpreterTest.cpp +++ b/unittests/CppInterOp/InterpreterTest.cpp @@ -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" @@ -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"}); // pass `-xc` for a C REPL. + + // Create the incremental compiler instance. + std::unique_ptr CI; + CI = ExitOnErr(CB.CreateCpp()); + + // Create the interpreter instance. + std::unique_ptr I = + ExitOnErr(clang::Interpreter::create(std::move(CI))); +#endif + +#ifdef USE_CLING + std::unique_ptr I(0, "", LLVM_BINARY_DIR); +#endif + + auto ExtInterp = I.get(); + EXPECT_NE(ExtInterp, nullptr); + Cpp::UseExternalInterpreter(ExtInterp); + EXPECT_FALSE(Cpp::OwnsInterpreter()); + I.release(); +}