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_private::repro;
20using namespace lldb;
21
22namespace {
23class ScriptInterpreterTest : public ::testing::Test {
24public:
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(force: true, arch: &arch));
34 }
35 void TearDown() override {
36 platform_linux::PlatformLinux::Terminate();
37 HostInfo::Terminate();
38 FileSystem::Terminate();
39 }
40};
41} // namespace
42
43TEST_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_TRUE(result.GetErrorData().starts_with(
52 "error: lua failed attempting to evaluate 'nil = foo'"));
53}
54

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