xref: /llvm-project/lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp (revision 692ae97ae71d62ce51d784681a0481fb54343fc1)
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 "Plugins/ScriptInterpreter/Lua/SWIGLuaBridge.h"
11 #include "gtest/gtest.h"
12 
13 using namespace lldb_private;
14 
luaopen_lldb(lua_State * L)15 extern "C" int luaopen_lldb(lua_State *L) { return 0; }
16 
17 llvm::Expected<bool>
LLDBSwigLuaBreakpointCallbackFunction(lua_State * L,lldb::StackFrameSP stop_frame_sp,lldb::BreakpointLocationSP bp_loc_sp,const StructuredDataImpl & extra_args_impl)18 lldb_private::lua::SWIGBridge::LLDBSwigLuaBreakpointCallbackFunction(
19     lua_State *L, lldb::StackFrameSP stop_frame_sp,
20     lldb::BreakpointLocationSP bp_loc_sp,
21     const StructuredDataImpl &extra_args_impl) {
22   return false;
23 }
24 
25 llvm::Expected<bool>
LLDBSwigLuaWatchpointCallbackFunction(lua_State * L,lldb::StackFrameSP stop_frame_sp,lldb::WatchpointSP wp_sp)26 lldb_private::lua::SWIGBridge::LLDBSwigLuaWatchpointCallbackFunction(
27     lua_State *L, lldb::StackFrameSP stop_frame_sp, lldb::WatchpointSP wp_sp) {
28   return false;
29 }
30 
TEST(LuaTest,RunValid)31 TEST(LuaTest, RunValid) {
32   Lua lua;
33   llvm::Error error = lua.Run("foo = 1");
34   EXPECT_FALSE(static_cast<bool>(error));
35 }
36 
TEST(LuaTest,RunInvalid)37 TEST(LuaTest, RunInvalid) {
38   Lua lua;
39   llvm::Error error = lua.Run("nil = foo");
40   EXPECT_TRUE(static_cast<bool>(error));
41   EXPECT_EQ(llvm::toString(std::move(error)),
42             "[string \"buffer\"]:1: unexpected symbol near 'nil'\n");
43 }
44