1 //===- unittests/Driver/GCCVersionTest.cpp --- GCCVersion parser tests ----===//
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
7 //===----------------------------------------------------------------------===//
9 // Unit tests for Generic_GCC::GCCVersion
11 //===----------------------------------------------------------------------===//
13 #include "../../lib/Driver/ToolChains/Gnu.h"
14 #include "gtest/gtest.h"
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
19 #if !defined(LLVM_BUILD_LLVM_DYLIB) && !defined(LLVM_BUILD_SHARED_LIBS)
21 using namespace clang
;
22 using namespace clang::driver
;
26 struct VersionParseTest
{
29 int Major
, Minor
, Patch
;
30 std::string MajorStr
, MinorStr
, PatchSuffix
;
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"},
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
);
58 } // end anonymous namespace