Skip to content

Commit 417bcd7

Browse files
committed
Add unittest for external interpreter use
1 parent 6b91054 commit 417bcd7

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

unittests/CppInterOp/InterpreterTest.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
#include "Utils.h"
22

33
#include "clang/Interpreter/CppInterOp.h"
4+
5+
#ifdef USE_CLING
6+
#include "cling/Interpreter/Interpreter.h"
7+
#endif // USE_CLING
8+
9+
#ifdef USE_REPL
10+
#include "clang/Interpreter/Interpreter.h"
11+
#endif // USE_REPL
12+
413
#include "clang/Basic/Version.h"
514

615
#include "llvm/ADT/SmallString.h"
@@ -162,3 +171,33 @@ TEST(InterpreterTest, CodeCompletion) {
162171
GTEST_SKIP();
163172
#endif
164173
}
174+
175+
TEST(InterpreterTest, ExternalInterpreterTest) {
176+
177+
#ifdef USE_REPL
178+
llvm::ExitOnError ExitOnErr;
179+
clang::IncrementalCompilerBuilder CB;
180+
CB.SetCompilerArgs({"-std=c++20"}); // pass `-xc` for a C REPL.
181+
182+
// Create the incremental compiler instance.
183+
std::unique_ptr<clang::CompilerInstance> CI;
184+
CI = ExitOnErr(CB.CreateCpp());
185+
186+
// Create the interpreter instance.
187+
std::unique_ptr<Interpreter> I =
188+
ExitOnErr(Interpreter::create(std::move(CI)));
189+
190+
auto ExtInterp = I.get();
191+
#endif
192+
193+
#ifdef USE_CLING
194+
const char* LLVMRESDIR = "/usr/local/"; // path to llvm resource directory
195+
cling::Interpreter interp(argc, argv, LLVMRESDIR);
196+
compat::Interpreter ExtInterp = &interp;
197+
#endif
198+
199+
std::cout << "External Interpreter:" << ExtInterp;
200+
EXPECT_NE(ExtInterp, nullptr);
201+
Cpp::UseExternalInterpreter(ExtInterp);
202+
EXPECT_FALSE(Cpp::OwnsInterpreter());
203+
}

0 commit comments

Comments
 (0)