xref: /llvm-project/lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp (revision 692ae97ae71d62ce51d784681a0481fb54343fc1)
128613242SJonas Devlieghere //===-- LuaTests.cpp ------------------------------------------------------===//
228613242SJonas Devlieghere //
328613242SJonas Devlieghere // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
428613242SJonas Devlieghere // See https://llvm.org/LICENSE.txt for license information.
528613242SJonas Devlieghere // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
628613242SJonas Devlieghere //
728613242SJonas Devlieghere //===----------------------------------------------------------------------===//
828613242SJonas Devlieghere 
928613242SJonas Devlieghere #include "Plugins/ScriptInterpreter/Lua/Lua.h"
10a52af6d3SPavel Labath #include "Plugins/ScriptInterpreter/Lua/SWIGLuaBridge.h"
1128613242SJonas Devlieghere #include "gtest/gtest.h"
1228613242SJonas Devlieghere 
1328613242SJonas Devlieghere using namespace lldb_private;
1428613242SJonas Devlieghere 
luaopen_lldb(lua_State * L)15bf03e17cSJonas Devlieghere extern "C" int luaopen_lldb(lua_State *L) { return 0; }
16bf03e17cSJonas Devlieghere 
17*692ae97aSAlex Langford llvm::Expected<bool>
LLDBSwigLuaBreakpointCallbackFunction(lua_State * L,lldb::StackFrameSP stop_frame_sp,lldb::BreakpointLocationSP bp_loc_sp,const StructuredDataImpl & extra_args_impl)18*692ae97aSAlex Langford lldb_private::lua::SWIGBridge::LLDBSwigLuaBreakpointCallbackFunction(
19532e4203SPedro Tammela     lua_State *L, lldb::StackFrameSP stop_frame_sp,
2082de8df2SPavel Labath     lldb::BreakpointLocationSP bp_loc_sp,
2182de8df2SPavel Labath     const StructuredDataImpl &extra_args_impl) {
22a0d7406aSPedro Tammela   return false;
23a0d7406aSPedro Tammela }
24a0d7406aSPedro Tammela 
25*692ae97aSAlex Langford llvm::Expected<bool>
LLDBSwigLuaWatchpointCallbackFunction(lua_State * L,lldb::StackFrameSP stop_frame_sp,lldb::WatchpointSP wp_sp)26*692ae97aSAlex Langford lldb_private::lua::SWIGBridge::LLDBSwigLuaWatchpointCallbackFunction(
27e81ba283SSiger Yang     lua_State *L, lldb::StackFrameSP stop_frame_sp, lldb::WatchpointSP wp_sp) {
28e81ba283SSiger Yang   return false;
29e81ba283SSiger Yang }
30e81ba283SSiger Yang 
TEST(LuaTest,RunValid)3128613242SJonas Devlieghere TEST(LuaTest, RunValid) {
3228613242SJonas Devlieghere   Lua lua;
3328613242SJonas Devlieghere   llvm::Error error = lua.Run("foo = 1");
3428613242SJonas Devlieghere   EXPECT_FALSE(static_cast<bool>(error));
3528613242SJonas Devlieghere }
3628613242SJonas Devlieghere 
TEST(LuaTest,RunInvalid)3728613242SJonas Devlieghere TEST(LuaTest, RunInvalid) {
3828613242SJonas Devlieghere   Lua lua;
3928613242SJonas Devlieghere   llvm::Error error = lua.Run("nil = foo");
4028613242SJonas Devlieghere   EXPECT_TRUE(static_cast<bool>(error));
4128613242SJonas Devlieghere   EXPECT_EQ(llvm::toString(std::move(error)),
4228613242SJonas Devlieghere             "[string \"buffer\"]:1: unexpected symbol near 'nil'\n");
4328613242SJonas Devlieghere }
44