llvm/lldb/unittests/Host/HostInfoTest.cpp

//===-- HostInfoTest.cpp --------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "lldb/Host/HostInfo.h"
#include "TestingSupport/SubsystemRAII.h"
#include "TestingSupport/TestUtilities.h"
#include "lldb/Host/FileSystem.h"
#include "lldb/lldb-defines.h"
#include "llvm/TargetParser/Host.h"
#include "gtest/gtest.h"

usingnamespacelldb_private;
usingnamespacellvm;

namespace {
class HostInfoTest : public ::testing::Test {};
} // namespace

TEST_F(HostInfoTest, GetAugmentedArchSpec) {}

TEST_F(HostInfoTest, GetHostname) {}

#if defined(__APPLE__)
TEST_F(HostInfoTest, GetXcodeSDK) {
  auto get_sdk = [](std::string sdk, bool error = false) -> llvm::StringRef {
    auto sdk_path_or_err =
        HostInfo::GetSDKRoot(HostInfo::SDKOptions{XcodeSDK(std::move(sdk))});
    if (!error) {
      EXPECT_TRUE((bool)sdk_path_or_err);
      return *sdk_path_or_err;
    }
    EXPECT_FALSE((bool)sdk_path_or_err);
    llvm::consumeError(sdk_path_or_err.takeError());
    return {};
  };
  EXPECT_FALSE(get_sdk("MacOSX.sdk").empty());
  // These are expected to fall back to an available version.
  EXPECT_FALSE(get_sdk("MacOSX9999.sdk").empty());
  // This is expected to fail.
  EXPECT_TRUE(get_sdk("CeciNestPasUnOS.sdk", true).empty());
}

TEST_F(HostInfoTest, FindSDKTool) {
  auto find_tool = [](std::string sdk, llvm::StringRef tool,
                      bool error = false) -> llvm::StringRef {
    auto sdk_path_or_err =
        HostInfo::FindSDKTool(XcodeSDK(std::move(sdk)), tool);
    if (!error) {
      EXPECT_TRUE((bool)sdk_path_or_err);
      return *sdk_path_or_err;
    }
    EXPECT_FALSE((bool)sdk_path_or_err);
    llvm::consumeError(sdk_path_or_err.takeError());
    return {};
  };
  EXPECT_FALSE(find_tool("MacOSX.sdk", "clang").empty());
  EXPECT_TRUE(find_tool("MacOSX.sdk", "CeciNestPasUnOutil").empty());
}
#endif

TEST(HostInfoTestInitialization, InitTwice) {}