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
21using namespace clang;
22using namespace clang::driver;
23
24namespace {
25
26struct VersionParseTest {
27 std::string Text;
28
29 int Major, Minor, Patch;
30 std::string MajorStr, MinorStr, PatchSuffix;
31};
32
33const VersionParseTest TestCases[] = {
34 {.Text: "5", .Major: 5, .Minor: -1, .Patch: -1, .MajorStr: "5", .MinorStr: "", .PatchSuffix: ""},
35 {.Text: "4.4", .Major: 4, .Minor: 4, .Patch: -1, .MajorStr: "4", .MinorStr: "4", .PatchSuffix: ""},
36 {.Text: "4.4-patched", .Major: 4, .Minor: 4, .Patch: -1, .MajorStr: "4", .MinorStr: "4", .PatchSuffix: "-patched"},
37 {.Text: "4.4.0", .Major: 4, .Minor: 4, .Patch: 0, .MajorStr: "4", .MinorStr: "4", .PatchSuffix: ""},
38 {.Text: "4.4.x", .Major: 4, .Minor: 4, .Patch: -1, .MajorStr: "4", .MinorStr: "4", .PatchSuffix: ""},
39 {.Text: "4.4.2-rc4", .Major: 4, .Minor: 4, .Patch: 2, .MajorStr: "4", .MinorStr: "4", .PatchSuffix: "-rc4"},
40 {.Text: "4.4.x-patched", .Major: 4, .Minor: 4, .Patch: -1, .MajorStr: "4", .MinorStr: "4", .PatchSuffix: ""},
41 {.Text: "not-a-version", .Major: -1, .Minor: -1, .Patch: -1, .MajorStr: "", .MinorStr: "", .PatchSuffix: ""},
42 {.Text: "10-win32", .Major: 10, .Minor: -1, .Patch: -1, .MajorStr: "10", .MinorStr: "", .PatchSuffix: "-win32"},
43};
44
45TEST(GCCVersionTest, Parse) {
46 for (const auto &TC : TestCases) {
47 auto V = toolchains::Generic_GCC::GCCVersion::Parse(VersionText: 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

source code of clang/unittests/Driver/GCCVersionTest.cpp