xref: /llvm-project/lldb/unittests/ScriptInterpreter/Lua/ScriptInterpreterTests.cpp (revision 16a6c10bd485979ba2edf4b487d633230a9df01f)
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/Platform/Linux/PlatformLinux.h"
10 #include "Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h"
11 #include "lldb/Core/Debugger.h"
12 #include "lldb/Host/FileSystem.h"
13 #include "lldb/Host/HostInfo.h"
14 #include "lldb/Interpreter/CommandReturnObject.h"
15 #include "lldb/Target/Platform.h"
16 #include "gtest/gtest.h"
17 
18 using namespace lldb_private;
19 using namespace lldb_private::repro;
20 using namespace lldb;
21 
22 namespace {
23 class ScriptInterpreterTest : public ::testing::Test {
24 public:
25   void SetUp() override {
26     FileSystem::Initialize();
27     HostInfo::Initialize();
28 
29     // Pretend Linux is the host platform.
30     platform_linux::PlatformLinux::Initialize();
31     ArchSpec arch("powerpc64-pc-linux");
32     Platform::SetHostPlatform(
33         platform_linux::PlatformLinux::CreateInstance(true, &arch));
34   }
35   void TearDown() override {
36     platform_linux::PlatformLinux::Terminate();
37     HostInfo::Terminate();
38     FileSystem::Terminate();
39   }
40 };
41 } // namespace
42 
43 TEST_F(ScriptInterpreterTest, ExecuteOneLine) {
44   DebuggerSP debugger_sp = Debugger::CreateInstance();
45   ASSERT_TRUE(debugger_sp);
46 
47   ScriptInterpreterLua script_interpreter(*debugger_sp);
48   CommandReturnObject result(/*colors*/ false);
49   EXPECT_TRUE(script_interpreter.ExecuteOneLine("foo = 1", &result));
50   EXPECT_FALSE(script_interpreter.ExecuteOneLine("nil = foo", &result));
51   EXPECT_EQ(result.GetErrorString().find(
52                 "error: lua failed attempting to evaluate 'nil = foo'"),
53             0U);
54 }
55