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 "llvm/Config/llvm-config.h" // for LLVM_BUILD_LLVM_DYLIB, LLVM_BUILD_SHARED_LIBS
15#include "gtest/gtest.h"
16
17// The Generic_GCC class is hidden in dylib/shared library builds, so
18// this test can only be built if neither of those configurations are
19// 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 {.Text: "5", .Major: 5, .Minor: -1, .Patch: -1, .MajorStr: "5", .MinorStr: "", .PatchSuffix: ""},
36 {.Text: "4.4", .Major: 4, .Minor: 4, .Patch: -1, .MajorStr: "4", .MinorStr: "4", .PatchSuffix: ""},
37 {.Text: "4.4-patched", .Major: 4, .Minor: 4, .Patch: -1, .MajorStr: "4", .MinorStr: "4", .PatchSuffix: "-patched"},
38 {.Text: "4.4.0", .Major: 4, .Minor: 4, .Patch: 0, .MajorStr: "4", .MinorStr: "4", .PatchSuffix: ""},
39 {.Text: "4.4.x", .Major: 4, .Minor: 4, .Patch: -1, .MajorStr: "4", .MinorStr: "4", .PatchSuffix: ""},
40 {.Text: "4.4.2-rc4", .Major: 4, .Minor: 4, .Patch: 2, .MajorStr: "4", .MinorStr: "4", .PatchSuffix: "-rc4"},
41 {.Text: "4.4.x-patched", .Major: 4, .Minor: 4, .Patch: -1, .MajorStr: "4", .MinorStr: "4", .PatchSuffix: ""},
42 {.Text: "not-a-version", .Major: -1, .Minor: -1, .Patch: -1, .MajorStr: "", .MinorStr: "", .PatchSuffix: ""},
43 {.Text: "10-win32", .Major: 10, .Minor: -1, .Patch: -1, .MajorStr: "10", .MinorStr: "", .PatchSuffix: "-win32"},
44};
45
46TEST(GCCVersionTest, Parse) {
47 for (const auto &TC : TestCases) {
48 auto V = toolchains::Generic_GCC::GCCVersion::Parse(VersionText: 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 namespace
60
61#endif
62

Provided by KDAB

Privacy Policy
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more

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