brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · 1aab13b Raw
62 lines · cpp
1//===- unittests/Driver/GCCVersionTest.cpp --- GCCVersion parser tests ----===//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// Unit tests for Generic_GCC::GCCVersion10//11//===----------------------------------------------------------------------===//12 13#include "../../lib/Driver/ToolChains/Gnu.h"14#include "llvm/Config/llvm-config.h" // for LLVM_BUILD_LLVM_DYLIB, LLVM_BUILD_SHARED_LIBS15#include "gtest/gtest.h"16 17// The Generic_GCC class is hidden in dylib/shared library builds, so18// this test can only be built if neither of those configurations are19// enabled.20#if !defined(LLVM_BUILD_LLVM_DYLIB) && !defined(LLVM_BUILD_SHARED_LIBS)21 22using namespace clang;23using namespace clang::driver;24 25namespace {26 27struct VersionParseTest {28  std::string Text;29 30  int Major, Minor, Patch;31  std::string MajorStr, MinorStr, PatchSuffix;32};33 34const VersionParseTest TestCases[] = {35    {"5", 5, -1, -1, "5", "", ""},36    {"4.4", 4, 4, -1, "4", "4", ""},37    {"4.4-patched", 4, 4, -1, "4", "4", "-patched"},38    {"4.4.0", 4, 4, 0, "4", "4", ""},39    {"4.4.x", 4, 4, -1, "4", "4", ""},40    {"4.4.2-rc4", 4, 4, 2, "4", "4", "-rc4"},41    {"4.4.x-patched", 4, 4, -1, "4", "4", ""},42    {"not-a-version", -1, -1, -1, "", "", ""},43    {"10-win32", 10, -1, -1, "10", "", "-win32"},44};45 46TEST(GCCVersionTest, Parse) {47  for (const auto &TC : TestCases) {48    auto V = toolchains::Generic_GCC::GCCVersion::Parse(TC.Text);49    EXPECT_EQ(V.Text, TC.Text);50    EXPECT_EQ(V.Major, TC.Major);51    EXPECT_EQ(V.Minor, TC.Minor);52    EXPECT_EQ(V.Patch, TC.Patch);53    EXPECT_EQ(V.MajorStr, TC.MajorStr);54    EXPECT_EQ(V.MinorStr, TC.MinorStr);55    EXPECT_EQ(V.PatchSuffix, TC.PatchSuffix);56  }57}58 59} // end anonymous namespace60 61#endif62