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

source code of lldb/unittests/ScriptInterpreter/Lua/ScriptInterpreterTests.cpp