Skip to content

Commit

Permalink
Improve the test coverage of the C API -- Take 5
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnimuc committed Jan 13, 2025
1 parent 0333803 commit 11fea7d
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions unittests/CppInterOp/InterpreterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <iostream>", 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

Expand Down Expand Up @@ -121,13 +131,6 @@ TEST(InterpreterTest, CreateInterpreter) {

clang_Interpreter_addSearchPath(CXI, "dummy", false, false);
clang_Interpreter_addIncludePath(CXI, "dummy");
clang_Interpreter_declare(CXI, "#include <iostream>", 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);
Expand Down

0 comments on commit 11fea7d

Please sign in to comment.