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