1 //===-- LuaTests.cpp ------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "Plugins/ScriptInterpreter/Lua/Lua.h" 10 #include "gtest/gtest.h" 11 12 using namespace lldb_private; 13 14 extern "C" int luaopen_lldb(lua_State *L) { return 0; } 15 16 #pragma clang diagnostic push 17 #pragma clang diagnostic ignored "-Wreturn-type-c-linkage" 18 19 // Disable warning C4190: 'LLDBSwigPythonBreakpointCallbackFunction' has 20 // C-linkage specified, but returns UDT 'llvm::Expected<bool>' which is 21 // incompatible with C 22 #if _MSC_VER 23 #pragma warning (push) 24 #pragma warning (disable : 4190) 25 #endif 26 27 extern "C" llvm::Expected<bool> 28 LLDBSwigLuaBreakpointCallbackFunction(lua_State *L, 29 lldb::StackFrameSP stop_frame_sp, 30 lldb::BreakpointLocationSP bp_loc_sp) { 31 return false; 32 } 33 34 #if _MSC_VER 35 #pragma warning (pop) 36 #endif 37 38 #pragma clang diagnostic pop 39 40 TEST(LuaTest, RunValid) { 41 Lua lua; 42 llvm::Error error = lua.Run("foo = 1"); 43 EXPECT_FALSE(static_cast<bool>(error)); 44 } 45 46 TEST(LuaTest, RunInvalid) { 47 Lua lua; 48 llvm::Error error = lua.Run("nil = foo"); 49 EXPECT_TRUE(static_cast<bool>(error)); 50 EXPECT_EQ(llvm::toString(std::move(error)), 51 "[string \"buffer\"]:1: unexpected symbol near 'nil'\n"); 52 } 53