Skip to content

Commit b4b35a5

Browse files
authored
[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.
1 parent 48a5350 commit b4b35a5

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-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: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
using namespace clang;
17+
using namespace clang::driver;
18+
19+
namespace {
20+
21+
struct VersionParseTest {
22+
std::string Text;
23+
24+
int Major, Minor, Patch;
25+
std::string MajorStr, MinorStr, PatchSuffix;
26+
};
27+
28+
const VersionParseTest TestCases[] = {
29+
{"5", 5, -1, -1, "5", "", ""},
30+
{"4.4", 4, 4, -1, "4", "4", ""},
31+
{"4.4-patched", 4, 4, -1, "4", "4", "-patched"},
32+
{"4.4.0", 4, 4, 0, "4", "4", ""},
33+
{"4.4.x", 4, 4, -1, "4", "4", ""},
34+
{"4.4.2-rc4", 4, 4, 2, "4", "4", "-rc4"},
35+
{"4.4.x-patched", 4, 4, -1, "4", "4", ""},
36+
{"not-a-version", -1, -1, -1, "", "", ""},
37+
};
38+
39+
TEST(GCCVersionTest, Parse) {
40+
for (const auto &TC : TestCases) {
41+
auto V = toolchains::Generic_GCC::GCCVersion::Parse(TC.Text);
42+
EXPECT_EQ(V.Text, TC.Text);
43+
EXPECT_EQ(V.Major, TC.Major);
44+
EXPECT_EQ(V.Minor, TC.Minor);
45+
EXPECT_EQ(V.Patch, TC.Patch);
46+
EXPECT_EQ(V.MajorStr, TC.MajorStr);
47+
EXPECT_EQ(V.MinorStr, TC.MinorStr);
48+
EXPECT_EQ(V.PatchSuffix, TC.PatchSuffix);
49+
}
50+
}
51+
52+
} // end anonymous namespace

0 commit comments

Comments
 (0)