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 
LLDBSwigLuaBreakpointCallbackFunction(lua_State * L,lldb::StackFrameSP stop_frame_sp,lldb::BreakpointLocationSP bp_loc_sp,const StructuredDataImpl & extra_args_impl)17a52af6d3SPavel Labath llvm::Expected<bool> lldb_private::LLDBSwigLuaBreakpointCallbackFunction(
18532e4203SPedro Tammela     lua_State *L, lldb::StackFrameSP stop_frame_sp,
19*82de8df2SPavel Labath     lldb::BreakpointLocationSP bp_loc_sp,
20*82de8df2SPavel Labath     const StructuredDataImpl &extra_args_impl) {
21a0d7406aSPedro Tammela   return false;
22a0d7406aSPedro Tammela }
23a0d7406aSPedro Tammela 
LLDBSwigLuaWatchpointCallbackFunction(lua_State * L,lldb::StackFrameSP stop_frame_sp,lldb::WatchpointSP wp_sp)24a52af6d3SPavel Labath llvm::Expected<bool> lldb_private::LLDBSwigLuaWatchpointCallbackFunction(
25e81ba283SSiger Yang     lua_State *L, lldb::StackFrameSP stop_frame_sp, lldb::WatchpointSP wp_sp) {
26e81ba283SSiger Yang   return false;
27e81ba283SSiger Yang }
28e81ba283SSiger Yang 
TEST(LuaTest,RunValid)2928613242SJonas Devlieghere TEST(LuaTest, RunValid) {
3028613242SJonas Devlieghere   Lua lua;
3128613242SJonas Devlieghere   llvm::Error error = lua.Run("foo = 1");
3228613242SJonas Devlieghere   EXPECT_FALSE(static_cast<bool>(error));
3328613242SJonas Devlieghere }
3428613242SJonas Devlieghere 
TEST(LuaTest,RunInvalid)3528613242SJonas Devlieghere TEST(LuaTest, RunInvalid) {
3628613242SJonas Devlieghere   Lua lua;
3728613242SJonas Devlieghere   llvm::Error error = lua.Run("nil = foo");
3828613242SJonas Devlieghere   EXPECT_TRUE(static_cast<bool>(error));
3928613242SJonas Devlieghere   EXPECT_EQ(llvm::toString(std::move(error)),
4028613242SJonas Devlieghere             "[string \"buffer\"]:1: unexpected symbol near 'nil'\n");
4128613242SJonas Devlieghere }
42