brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.0 KiB · dce79b2 Raw
61 lines · cpp
1//===- llvm/unittest/Support/CommandLineInit/CommandLineInitTest.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-exception6//7//===----------------------------------------------------------------------===//8//9/// \file10/// Check if preset options in libSupport -- e.g., "help", "version", etc. --11/// are correctly initialized and registered before getRegisteredOptions is12/// invoked.13///14/// Most code here comes from llvm/utils/unittest/UnitTestMain/TestMain.cpp,15/// except that llvm::cl::ParseCommandLineOptions() call is removed.16//17//===----------------------------------------------------------------------===//18 19#include "llvm/Support/CommandLine.h"20#include "gtest/gtest.h"21 22#if defined(_WIN32)23#include <windows.h>24#if defined(_MSC_VER)25#include <crtdbg.h>26#endif27#endif28 29using namespace llvm;30 31int main(int argc, char **argv) {32  testing::InitGoogleTest(&argc, argv);33 34#if defined(_WIN32)35  // Disable all of the possible ways Windows conspires to make automated36  // testing impossible.37  ::SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);38#if defined(_MSC_VER)39  ::_set_error_mode(_OUT_TO_STDERR);40  _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);41  _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);42  _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);43  _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);44  _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);45  _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);46#endif47#endif48 49  return RUN_ALL_TESTS();50}51 52TEST(CommandLineInitTest, GetPresetOptions) {53  StringMap<cl::Option *> &Map =54      cl::getRegisteredOptions(cl::SubCommand::getTopLevel());55 56  for (auto *Str :57       {"help", "help-hidden", "help-list", "help-list-hidden", "version"})58    EXPECT_EQ(Map.count(Str), (size_t)1)59        << "Could not get preset option `" << Str << '`';60}61