From 11fea7db277675249f7b1d1ebd488f30130603c2 Mon Sep 17 00:00:00 2001 From: Gnimuc Date: Mon, 13 Jan 2025 20:57:06 +0900 Subject: [PATCH] Improve the test coverage of the C API -- Take 5 --- unittests/CppInterOp/InterpreterTest.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/unittests/CppInterOp/InterpreterTest.cpp b/unittests/CppInterOp/InterpreterTest.cpp index 409f762a2..03d69f518 100644 --- a/unittests/CppInterOp/InterpreterTest.cpp +++ b/unittests/CppInterOp/InterpreterTest.cpp @@ -82,16 +82,26 @@ TEST(InterpreterTest, Process) { #endif if (llvm::sys::RunningOnValgrind()) GTEST_SKIP() << "XFAIL due to Valgrind report"; - Cpp::CreateInterpreter(); + auto* I = Cpp::CreateInterpreter(); EXPECT_TRUE(Cpp::Process("") == 0); EXPECT_TRUE(Cpp::Process("int a = 12;") == 0); EXPECT_FALSE(Cpp::Process("error_here;") == 0); // Linker/JIT error. EXPECT_FALSE(Cpp::Process("int f(); int res = f();") == 0); + + // C API + auto CXI = clang_createInterpreterFromRawPtr(I); + clang_Interpreter_declare(CXI, "#include ", false); + clang_Interpreter_process(CXI, "int c = 42;"); + auto* CXV = clang_createValue(); + auto Res = clang_Interpreter_evaluate(CXI, "c", CXV); + EXPECT_EQ(Res, CXError_Success); + clang_Value_dispose(CXV); + clang_Interpreter_dispose(CXI); } TEST(InterpreterTest, CreateInterpreter) { - auto I = Cpp::CreateInterpreter(); + auto* I = Cpp::CreateInterpreter(); EXPECT_TRUE(I); // Check if the default standard is c++14 @@ -121,13 +131,6 @@ TEST(InterpreterTest, CreateInterpreter) { clang_Interpreter_addSearchPath(CXI, "dummy", false, false); clang_Interpreter_addIncludePath(CXI, "dummy"); - clang_Interpreter_declare(CXI, "#include ", false); - clang_Interpreter_process(CXI, "int c = 42;"); - auto* CXV = clang_createValue(); - auto Res = clang_Interpreter_evaluate(CXI, "c", CXV); - EXPECT_EQ(Res, CXError_Success); - - clang_Value_dispose(CXV); auto I2 = clang_Interpreter_takeInterpreterAsPtr(CXI); EXPECT_EQ(I, I2); clang_Interpreter_dispose(CXI);