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> LLDBSwigLuaBreakpointCallbackFunction( 28 lua_State *L, lldb::StackFrameSP stop_frame_sp, 29 lldb::BreakpointLocationSP bp_loc_sp, StructuredDataImpl *extra_args_impl) { 30 return false; 31 } 32 33 extern "C" llvm::Expected<bool> LLDBSwigLuaWatchpointCallbackFunction( 34 lua_State *L, lldb::StackFrameSP stop_frame_sp, lldb::WatchpointSP wp_sp) { 35 return false; 36 } 37 38 #if _MSC_VER 39 #pragma warning (pop) 40 #endif 41 42 #pragma clang diagnostic pop 43 44 TEST(LuaTest, RunValid) { 45 Lua lua; 46 llvm::Error error = lua.Run("foo = 1"); 47 EXPECT_FALSE(static_cast<bool>(error)); 48 } 49 50 TEST(LuaTest, RunInvalid) { 51 Lua lua; 52 llvm::Error error = lua.Run("nil = foo"); 53 EXPECT_TRUE(static_cast<bool>(error)); 54 EXPECT_EQ(llvm::toString(std::move(error)), 55 "[string \"buffer\"]:1: unexpected symbol near 'nil'\n"); 56 } 57