Skip to content

Commit 538b7ba

Browse files
committed
Reland [clang] [unittest] Add a test for Generic_GCC::GCCVersion::Parse (#69078)
This adds actual test cases for all the cases that are listed in a code comment in the implementation of this function; having such test coverage eases doing further modifications to the function. This relands b4b35a5. This time, the new test is excluded if building with dylibs or shared libraries enabled, as the clang::toolchains::Generic_GCC class is marked LLVM_LIBRARY_VISIBILITY, giving it hidden visibility in such builds, making it unreferencable outside of the dylib/shared library.
1 parent 09ec000 commit 538b7ba

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

clang/unittests/Driver/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ set(LLVM_LINK_COMPONENTS
99
add_clang_unittest(ClangDriverTests
1010
DistroTest.cpp
1111
DXCModeTest.cpp
12+
GCCVersionTest.cpp
1213
ToolChainTest.cpp
1314
ModuleCacheTest.cpp
1415
MultilibBuilderTest.cpp
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
};
43+
44+
TEST(GCCVersionTest, Parse) {
45+
for (const auto &TC : TestCases) {
46+
auto V = toolchains::Generic_GCC::GCCVersion::Parse(TC.Text);
47+
EXPECT_EQ(V.Text, TC.Text);
48+
EXPECT_EQ(V.Major, TC.Major);
49+
EXPECT_EQ(V.Minor, TC.Minor);
50+
EXPECT_EQ(V.Patch, TC.Patch);
51+
EXPECT_EQ(V.MajorStr, TC.MajorStr);
52+
EXPECT_EQ(V.MinorStr, TC.MinorStr);
53+
EXPECT_EQ(V.PatchSuffix, TC.PatchSuffix);
54+
}
55+
}
56+
57+
} // end anonymous namespace
58+
59+
#endif

0 commit comments

Comments
 (0)