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