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