[NFC][Coroutines] Use structured binding with llvm::enumerate in CoroSplit (#116879)
[llvm-project.git] / lldb / unittests / ScriptInterpreter / Lua / ScriptInterpreterTests.cpp
blob5f8cd5aef56b6291aa8c16bd4fb1b1a7c8875a63
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 //===----------------------------------------------------------------------===//
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"
18 using namespace lldb_private;
19 using namespace lldb_private::repro;
20 using namespace lldb;
22 namespace {
23 class ScriptInterpreterTest : public ::testing::Test {
24 public:
25 void SetUp() override {
26 FileSystem::Initialize();
27 HostInfo::Initialize();
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));
35 void TearDown() override {
36 platform_linux::PlatformLinux::Terminate();
37 HostInfo::Terminate();
38 FileSystem::Terminate();
41 } // namespace
43 TEST_F(ScriptInterpreterTest, ExecuteOneLine) {
44 DebuggerSP debugger_sp = Debugger::CreateInstance();
45 ASSERT_TRUE(debugger_sp);
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);