xref: /llvm-project/lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp (revision 532e4203c5be909af701df4dedfd36c9b8f85034)
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 #if _MSC_VER
34 #pragma warning (pop)
35 #endif
36 
37 #pragma clang diagnostic pop
38 
39 TEST(LuaTest, RunValid) {
40   Lua lua;
41   llvm::Error error = lua.Run("foo = 1");
42   EXPECT_FALSE(static_cast<bool>(error));
43 }
44 
45 TEST(LuaTest, RunInvalid) {
46   Lua lua;
47   llvm::Error error = lua.Run("nil = foo");
48   EXPECT_TRUE(static_cast<bool>(error));
49   EXPECT_EQ(llvm::toString(std::move(error)),
50             "[string \"buffer\"]:1: unexpected symbol near 'nil'\n");
51 }
52