[clang] [clang][test] add TestLanguage.def to specify all tested language versions (PR #94243)
Julian Schmidt via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 29 07:53:26 PDT 2024
https://github.com/5chmidti updated https://github.com/llvm/llvm-project/pull/94243
>From 1ef1bc0bfebca8ca114a57ea2d5016418e36446d Mon Sep 17 00:00:00 2001
From: Julian Schmidt <git.julian.schmidt at gmail.com>
Date: Sat, 1 Jun 2024 17:38:37 +0200
Subject: [PATCH 1/5] [clang][test] add TestLanguage.def to specify all tested
language versions
Adds a def file to have a single location where tested language versions are
specified. Removes the need to update multiple locations in the testing
infrastructure to add a new language version to be tested.
Test instatiation can now include all languages without needing to
specify them.
This patch also adds pretty printing for instantiated test names.
That means, that a test instantiated with C++23 will have the
name `...TestSuite/TestName/CXX23` instead ending with some number
(index of the argument for instantiation of the test), which improves a
better experience when encountering a test failure with a specific
language version. The suffix will also contain an `_win` if the target
contains `win`.
---
clang/include/clang/Testing/CommandLineArgs.h | 17 +-
clang/include/clang/Testing/TestClangConfig.h | 146 +++++++++++++++---
clang/include/clang/Testing/TestLanguage.def | 39 +++++
clang/lib/Testing/CommandLineArgs.cpp | 119 +++++++-------
clang/unittests/AST/MatchVerifier.h | 37 +----
.../ASTMatchers/ASTMatchersNodeTest.cpp | 18 ++-
.../ASTMatchers/ASTMatchersTraversalTest.cpp | 10 +-
.../Tooling/Syntax/BuildTreeTest.cpp | 8 +-
.../Tooling/Syntax/MutationsTest.cpp | 7 +-
.../Tooling/Syntax/SynthesisTest.cpp | 7 +-
clang/unittests/Tooling/Syntax/TreeTest.cpp | 14 +-
.../unittests/Tooling/Syntax/TreeTestBase.cpp | 7 +-
12 files changed, 280 insertions(+), 149 deletions(-)
create mode 100644 clang/include/clang/Testing/TestLanguage.def
diff --git a/clang/include/clang/Testing/CommandLineArgs.h b/clang/include/clang/Testing/CommandLineArgs.h
index e71907e8bbd0c6..52beac7254fefc 100644
--- a/clang/include/clang/Testing/CommandLineArgs.h
+++ b/clang/include/clang/Testing/CommandLineArgs.h
@@ -21,19 +21,18 @@
namespace clang {
enum TestLanguage {
- Lang_C89,
- Lang_C99,
- Lang_CXX03,
- Lang_CXX11,
- Lang_CXX14,
- Lang_CXX17,
- Lang_CXX20,
- Lang_CXX23,
+#define TESTLANGUAGE(lang, version, std_flag, version_index) \
+ Lang_##lang##version,
+#include "clang/Testing/TestLanguage.def"
+
Lang_OpenCL,
Lang_OBJC,
- Lang_OBJCXX
+ Lang_OBJCXX,
};
+std::vector<TestLanguage> getCOrLater(int MinimumStd);
+std::vector<TestLanguage> getCXXOrLater(int MinimumStd);
+
std::vector<std::string> getCommandLineArgsForTesting(TestLanguage Lang);
std::vector<std::string> getCC1ArgsForTesting(TestLanguage Lang);
diff --git a/clang/include/clang/Testing/TestClangConfig.h b/clang/include/clang/Testing/TestClangConfig.h
index 1b4efca80e9d47..4dd1eb9b6f39a0 100644
--- a/clang/include/clang/Testing/TestClangConfig.h
+++ b/clang/include/clang/Testing/TestClangConfig.h
@@ -27,37 +27,117 @@ struct TestClangConfig {
/// The argument of the `-target` command line flag.
std::string Target;
- bool isC() const { return Language == Lang_C89 || Language == Lang_C99; }
-
- bool isC99OrLater() const { return Language == Lang_C99; }
-
- bool isCXX() const {
- return Language == Lang_CXX03 || Language == Lang_CXX11 ||
- Language == Lang_CXX14 || Language == Lang_CXX17 ||
- Language == Lang_CXX20 || Language == Lang_CXX23;
+ bool isC() const {
+ return false
+#define TESTLANGUAGE
+#define TESTLANGUAGE_C(lang, version, std_flag, version_index) \
+ || Language == Lang_##lang##version
+#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index)
+#include "clang/Testing/TestLanguage.def"
+ ;
}
- bool isCXX11OrLater() const {
- return Language == Lang_CXX11 || Language == Lang_CXX14 ||
- Language == Lang_CXX17 || Language == Lang_CXX20 ||
- Language == Lang_CXX23;
+ bool isCOrLater(int MinimumStdVersion) const {
+ const auto MinimumStdVersionIndex = 0
+#define TESTLANGUAGE
+#define TESTLANGUAGE_C(lang, version, std_flag, version_index) \
+ +(MinimumStdVersion == version ? version_index : 0)
+#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index)
+#include "clang/Testing/TestLanguage.def"
+ ;
+ switch (Language) {
+#define TESTLANGUAGE
+#define TESTLANGUAGE_C(lang, version, std_flag, version_index) \
+ case Lang_##lang##version: \
+ return MinimumStdVersionIndex <= version_index;
+#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index)
+#include "clang/Testing/TestLanguage.def"
+ default:
+ return false;
+ }
}
- bool isCXX14OrLater() const {
- return Language == Lang_CXX14 || Language == Lang_CXX17 ||
- Language == Lang_CXX20 || Language == Lang_CXX23;
+ bool isC99OrLater() const { return isCOrLater(99); }
+
+ bool isCOrEarlier(int MaximumStdVersion) const {
+ const auto MaximumStdVersionIndex = 0
+#define TESTLANGUAGE
+#define TESTLANGUAGE_C(lang, version, std_flag, version_index) \
+ +(MaximumStdVersion == version ? version_index : 0)
+#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index)
+#include "clang/Testing/TestLanguage.def"
+ ;
+ switch (Language) {
+#define TESTLANGUAGE
+#define TESTLANGUAGE_C(lang, version, std_flag, version_index) \
+ case Lang_##lang##version: \
+ return MaximumStdVersionIndex >= version_index;
+#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index)
+#include "clang/Testing/TestLanguage.def"
+ default:
+ return false;
+ }
}
- bool isCXX17OrLater() const {
- return Language == Lang_CXX17 || Language == Lang_CXX20 ||
- Language == Lang_CXX23;
+ bool isCXX() const {
+ return false
+#define TESTLANGUAGE
+#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index) \
+ || Language == Lang_##lang##version
+#define TESTLANGUAGE_C(lang, version, std_flag, version_index)
+#include "clang/Testing/TestLanguage.def"
+ ;
}
- bool isCXX20OrLater() const {
- return Language == Lang_CXX20 || Language == Lang_CXX23;
+ bool isCXXOrLater(int MinimumStdVersion) const {
+ const auto MinimumStdVersionIndex = 0
+#define TESTLANGUAGE
+#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index) \
+ +(MinimumStdVersion == version ? version_index : 0)
+#define TESTLANGUAGE_C(lang, version, std_flag, version_index)
+#include "clang/Testing/TestLanguage.def"
+ ;
+ switch (Language) {
+#define TESTLANGUAGE
+#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index) \
+ case Lang_##lang##version: \
+ return MinimumStdVersionIndex <= version_index;
+#define TESTLANGUAGE_C(lang, version, std_flag, version_index)
+#include "clang/Testing/TestLanguage.def"
+ default:
+ return false;
+ }
}
- bool isCXX23OrLater() const { return Language == Lang_CXX23; }
+ bool isCXX11OrLater() const { return isCXXOrLater(11); }
+
+ bool isCXX14OrLater() const { return isCXXOrLater(14); }
+
+ bool isCXX17OrLater() const { return isCXXOrLater(17); }
+
+ bool isCXX20OrLater() const { return isCXXOrLater(20); }
+
+ bool isCXX23OrLater() const { return isCXXOrLater(23); }
+
+ bool isCXXOrEarlier(int MaximumStdVersion) const {
+ const auto MaximumStdVersionIndex = 0
+#define TESTLANGUAGE
+#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index) \
+ +(MaximumStdVersion == version ? version_index : 0)
+#define TESTLANGUAGE_C(lang, version, std_flag, version_index)
+#include "clang/Testing/TestLanguage.def"
+ ;
+ switch (Language) {
+#define TESTLANGUAGE
+#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index) \
+ case Lang_##lang##version: \
+ return MaximumStdVersionIndex >= version_index;
+#define TESTLANGUAGE_C(lang, version, std_flag, version_index)
+#include "clang/Testing/TestLanguage.def"
+ default:
+ return false;
+ }
+ }
bool supportsCXXDynamicExceptionSpecification() const {
return Language == Lang_CXX03 || Language == Lang_CXX11 ||
@@ -75,6 +155,30 @@ struct TestClangConfig {
return Result;
}
+ std::string toShortString() const {
+ std::string Result;
+ llvm::raw_string_ostream OS(Result);
+ switch (Language) {
+#define TESTLANGUAGE(lang, version, std_flag, version_index) \
+ case Lang_##lang##version: \
+ OS << (#lang #version); \
+ break;
+#include "clang/Testing/TestLanguage.def"
+ case Lang_OpenCL:
+ OS << "OpenCL";
+ break;
+ case Lang_OBJC:
+ OS << "OBJC";
+ break;
+ case Lang_OBJCXX:
+ OS << "OBJCXX";
+ break;
+ }
+
+ OS << (Target.find("win") != std::string::npos ? "_win" : "");
+ return Result;
+ }
+
std::string toString() const {
std::string Result;
llvm::raw_string_ostream OS(Result);
diff --git a/clang/include/clang/Testing/TestLanguage.def b/clang/include/clang/Testing/TestLanguage.def
new file mode 100644
index 00000000000000..88155a3e3d9204
--- /dev/null
+++ b/clang/include/clang/Testing/TestLanguage.def
@@ -0,0 +1,39 @@
+
+//===-- TestLanguage.def - Language Versions for Testing --------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef TESTLANGUAGE
+#error "TESTLANGUAGE must be defined before including this file"
+#endif
+
+#ifndef TESTLANGUAGE_C
+#define TESTLANGUAGE_C TESTLANGUAGE
+#endif
+
+#ifndef TESTLANGUAGE_CXX
+#define TESTLANGUAGE_CXX TESTLANGUAGE
+#endif
+
+TESTLANGUAGE_C(C, 89, c89, 0)
+TESTLANGUAGE_C(C, 99, c99, 1)
+TESTLANGUAGE_C(C, 11, c11, 2)
+TESTLANGUAGE_C(C, 17, c17, 3)
+TESTLANGUAGE_C(C, 23, c23, 4)
+
+// TESTLANGUAGE_CXX(CXX, 98, c++98, 0)
+TESTLANGUAGE_CXX(CXX, 03, c++03, 1)
+TESTLANGUAGE_CXX(CXX, 11, c++11, 2)
+TESTLANGUAGE_CXX(CXX, 14, c++14, 3)
+TESTLANGUAGE_CXX(CXX, 17, c++17, 4)
+TESTLANGUAGE_CXX(CXX, 20, c++20, 5)
+TESTLANGUAGE_CXX(CXX, 23, c++23, 6)
+TESTLANGUAGE_CXX(CXX, 26, c++26, 7)
+
+#undef TESTLANGUAGE_CXX
+#undef TESTLANGUAGE_C
+#undef TESTLANGUAGE
diff --git a/clang/lib/Testing/CommandLineArgs.cpp b/clang/lib/Testing/CommandLineArgs.cpp
index 3abc689b93e8d0..15d5ad2bdc2877 100644
--- a/clang/lib/Testing/CommandLineArgs.cpp
+++ b/clang/lib/Testing/CommandLineArgs.cpp
@@ -11,99 +11,84 @@
#include "llvm/Support/ErrorHandling.h"
namespace clang {
+std::vector<TestLanguage> getCOrLater(const int MinimumStd) {
+ std::vector<TestLanguage> Result{};
+
+#define TESTLANGUAGE(lang, version, std_flag, version_index)
+#define TESTLANGUAGE_C(lang, version, std_flag, version_index) \
+ if (version >= MinimumStd) \
+ Result.push_back(Lang_##lang##version);
+#include "clang/Testing/TestLanguage.def"
+
+ return Result;
+}
+std::vector<TestLanguage> getCXXOrLater(const int MinimumStd) {
+ std::vector<TestLanguage> Result{};
+
+#define TESTLANGUAGE(lang, version, std_flag, version_index)
+#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index) \
+ if (version >= MinimumStd) \
+ Result.push_back(Lang_##lang##version);
+#include "clang/Testing/TestLanguage.def"
+
+ return Result;
+}
std::vector<std::string> getCommandLineArgsForTesting(TestLanguage Lang) {
- std::vector<std::string> Args;
// Test with basic arguments.
switch (Lang) {
- case Lang_C89:
- Args = {"-x", "c", "-std=c89"};
- break;
- case Lang_C99:
- Args = {"-x", "c", "-std=c99"};
- break;
- case Lang_CXX03:
- Args = {"-std=c++03", "-frtti"};
- break;
- case Lang_CXX11:
- Args = {"-std=c++11", "-frtti"};
- break;
- case Lang_CXX14:
- Args = {"-std=c++14", "-frtti"};
- break;
- case Lang_CXX17:
- Args = {"-std=c++17", "-frtti"};
- break;
- case Lang_CXX20:
- Args = {"-std=c++20", "-frtti"};
- break;
- case Lang_CXX23:
- Args = {"-std=c++23", "-frtti"};
- break;
+#define TESTLANGUAGE
+#define TESTLANGUAGE_C(lang, version, std_flag, version_index) \
+ case Lang_##lang##version: \
+ return { "-x", "c", "-std=" #std_flag };
+#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index) \
+ case Lang_##lang##version: \
+ return { "-std=" #std_flag, "-frtti" };
+#include "clang/Testing/TestLanguage.def"
+
case Lang_OBJC:
- Args = {"-x", "objective-c", "-frtti", "-fobjc-nonfragile-abi"};
- break;
+ return {"-x", "objective-c", "-frtti", "-fobjc-nonfragile-abi"};
case Lang_OBJCXX:
- Args = {"-x", "objective-c++", "-frtti"};
- break;
+ return {"-x", "objective-c++", "-frtti"};
case Lang_OpenCL:
llvm_unreachable("Not implemented yet!");
}
- return Args;
+ llvm_unreachable("Not implemented yet!");
}
std::vector<std::string> getCC1ArgsForTesting(TestLanguage Lang) {
- std::vector<std::string> Args;
switch (Lang) {
- case Lang_C89:
- Args = {"-xc", "-std=c89"};
- break;
- case Lang_C99:
- Args = {"-xc", "-std=c99"};
- break;
- case Lang_CXX03:
- Args = {"-std=c++03"};
- break;
- case Lang_CXX11:
- Args = {"-std=c++11"};
- break;
- case Lang_CXX14:
- Args = {"-std=c++14"};
- break;
- case Lang_CXX17:
- Args = {"-std=c++17"};
- break;
- case Lang_CXX20:
- Args = {"-std=c++20"};
- break;
- case Lang_CXX23:
- Args = {"-std=c++23"};
- break;
+#define TESTLANGUAGE
+#define TESTLANGUAGE_C(lang, version, std_flag, version_index) \
+ case Lang_##lang##version: \
+ return { "-xc", "-std=" #std_flag };
+#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index) \
+ case Lang_##lang##version: \
+ return { "-std=" #std_flag };
+#include "clang/Testing/TestLanguage.def"
+
case Lang_OBJC:
- Args = {"-xobjective-c"};
+ return {"-xobjective-c"};
break;
case Lang_OBJCXX:
- Args = {"-xobjective-c++"};
+ return {"-xobjective-c++"};
break;
case Lang_OpenCL:
llvm_unreachable("Not implemented yet!");
}
- return Args;
+ llvm_unreachable("Not implemented yet!");
}
StringRef getFilenameForTesting(TestLanguage Lang) {
switch (Lang) {
- case Lang_C89:
- case Lang_C99:
+#define TESTLANGUAGE
+#define TESTLANGUAGE_C(lang, version, std_flag, version_index) \
+ case Lang_##lang##version: \
return "input.c";
-
- case Lang_CXX03:
- case Lang_CXX11:
- case Lang_CXX14:
- case Lang_CXX17:
- case Lang_CXX20:
- case Lang_CXX23:
+#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index) \
+ case Lang_##lang##version: \
return "input.cc";
+#include "clang/Testing/TestLanguage.def"
case Lang_OpenCL:
return "input.cl";
diff --git a/clang/unittests/AST/MatchVerifier.h b/clang/unittests/AST/MatchVerifier.h
index 60bb4a8716ae8c..e28946977de88d 100644
--- a/clang/unittests/AST/MatchVerifier.h
+++ b/clang/unittests/AST/MatchVerifier.h
@@ -88,38 +88,13 @@ MatchVerifier<NodeType>::match(const std::string &Code,
StringRef FileName;
switch (L) {
- case Lang_C89:
- Args.push_back("-std=c89");
- FileName = "input.c";
- break;
- case Lang_C99:
- Args.push_back("-std=c99");
- FileName = "input.c";
- break;
- case Lang_CXX03:
- Args.push_back("-std=c++03");
- FileName = "input.cc";
- break;
- case Lang_CXX11:
- Args.push_back("-std=c++11");
- FileName = "input.cc";
- break;
- case Lang_CXX14:
- Args.push_back("-std=c++14");
- FileName = "input.cc";
- break;
- case Lang_CXX17:
- Args.push_back("-std=c++17");
- FileName = "input.cc";
- break;
- case Lang_CXX20:
- Args.push_back("-std=c++20");
- FileName = "input.cc";
- break;
- case Lang_CXX23:
- Args.push_back("-std=c++23");
- FileName = "input.cc";
+#define TESTLANGUAGE(lang, version, std_flag, version_index) \
+ case Lang_##lang##version: \
+ Args.push_back("-std=" #std_flag); \
+ FileName = getFilenameForTesting(Lang_##lang##version); \
break;
+#include "clang/Testing/TestLanguage.def"
+
case Lang_OpenCL:
Args.push_back("-cl-no-stdinc");
FileName = "input.cl";
diff --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
index f2eaf19d61402a..3295ad1e21455f 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1224,7 +1224,7 @@ TEST_P(ASTMatchersTest, CastExpression_MatchesImplicitCasts) {
}
TEST_P(ASTMatchersTest, CastExpr_DoesNotMatchNonCasts) {
- if (GetParam().Language == Lang_C89 || GetParam().Language == Lang_C99) {
+ if (GetParam().isC()) {
// This does have a cast in C
EXPECT_TRUE(matches("char c = '0';", implicitCastExpr()));
} else {
@@ -1678,7 +1678,7 @@ TEST_P(ASTMatchersTest, FunctionProtoType) {
}
TEST_P(ASTMatchersTest, FunctionProtoType_C) {
- if (!GetParam().isC()) {
+ if (!GetParam().isCOrEarlier(17)) {
return;
}
EXPECT_TRUE(notMatches("void f();", functionProtoType()));
@@ -2745,8 +2745,11 @@ TEST(MatchFinderAPI, MatchesDynamic) {
static std::vector<TestClangConfig> allTestClangConfigs() {
std::vector<TestClangConfig> all_configs;
- for (TestLanguage lang : {Lang_C89, Lang_C99, Lang_CXX03, Lang_CXX11,
- Lang_CXX14, Lang_CXX17, Lang_CXX20, Lang_CXX23}) {
+ for (TestLanguage lang : {
+#define TESTLANGUAGE(lang, version, std_flag, version_index) \
+ Lang_##lang##version,
+#include "clang/Testing/TestLanguage.def"
+ }) {
TestClangConfig config;
config.Language = lang;
@@ -2770,8 +2773,11 @@ static std::vector<TestClangConfig> allTestClangConfigs() {
return all_configs;
}
-INSTANTIATE_TEST_SUITE_P(ASTMatchersTests, ASTMatchersTest,
- testing::ValuesIn(allTestClangConfigs()));
+INSTANTIATE_TEST_SUITE_P(
+ ASTMatchersTests, ASTMatchersTest, testing::ValuesIn(allTestClangConfigs()),
+ [](const testing::TestParamInfo<TestClangConfig> &Info) {
+ return Info.param.toShortString();
+ });
} // namespace ast_matchers
} // namespace clang
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
index 028392f499da3b..8a62358a71f0bf 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -3082,10 +3082,13 @@ B func1() { return 42; }
auto M = expr(unless(integerLiteral(equals(24)))).bind("intLit");
EXPECT_TRUE(matchAndVerifyResultTrue(
Code, traverse(TK_AsIs, M),
- std::make_unique<VerifyIdIsBoundTo<Expr>>("intLit", 6)));
+ std::make_unique<VerifyIdIsBoundTo<Expr>>("intLit", 6),
+ {"-std=c++11"}));
+
EXPECT_TRUE(matchAndVerifyResultTrue(
Code, traverse(TK_IgnoreUnlessSpelledInSource, M),
- std::make_unique<VerifyIdIsBoundTo<Expr>>("intLit", 1)));
+ std::make_unique<VerifyIdIsBoundTo<Expr>>("intLit", 1),
+ {"-std=c++11"}));
}
{
auto M =
@@ -3128,7 +3131,8 @@ B func1() { return 42; }
auto M = expr().bind("allExprs");
EXPECT_TRUE(matchAndVerifyResultTrue(
Code, traverse(TK_AsIs, M),
- std::make_unique<VerifyIdIsBoundTo<Expr>>("allExprs", 6)));
+ std::make_unique<VerifyIdIsBoundTo<Expr>>("allExprs", 6),
+ {"-std=c++11"}));
EXPECT_TRUE(matchAndVerifyResultTrue(
Code, traverse(TK_IgnoreUnlessSpelledInSource, M),
std::make_unique<VerifyIdIsBoundTo<Expr>>("allExprs", 1)));
diff --git a/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp b/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
index 37e3546dc90876..4ff5e8b65a686d 100644
--- a/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
+++ b/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
@@ -88,8 +88,12 @@ class BuildSyntaxTreeTest : public SyntaxTreeTest {
}
};
-INSTANTIATE_TEST_SUITE_P(SyntaxTreeTests, BuildSyntaxTreeTest,
- testing::ValuesIn(allTestClangConfigs()) );
+INSTANTIATE_TEST_SUITE_P(
+ SyntaxTreeTests, BuildSyntaxTreeTest,
+ testing::ValuesIn(allTestClangConfigs()),
+ [](const testing::TestParamInfo<TestClangConfig> &Info) {
+ return Info.param.toShortString();
+ });
TEST_P(BuildSyntaxTreeTest, Simple) {
EXPECT_TRUE(treeDumpEqual(
diff --git a/clang/unittests/Tooling/Syntax/MutationsTest.cpp b/clang/unittests/Tooling/Syntax/MutationsTest.cpp
index 1c3d6aac7183b6..35692fd52181ac 100644
--- a/clang/unittests/Tooling/Syntax/MutationsTest.cpp
+++ b/clang/unittests/Tooling/Syntax/MutationsTest.cpp
@@ -54,8 +54,11 @@ class MutationTest : public SyntaxTreeTest {
};
};
-INSTANTIATE_TEST_SUITE_P(SyntaxTreeTests, MutationTest,
- ::testing::ValuesIn(allTestClangConfigs()) );
+INSTANTIATE_TEST_SUITE_P(
+ SyntaxTreeTests, MutationTest, ::testing::ValuesIn(allTestClangConfigs()),
+ [](const testing::TestParamInfo<TestClangConfig> &Info) {
+ return Info.param.toShortString();
+ });
TEST_P(MutationTest, RemoveStatement_InCompound) {
CheckTransformation(RemoveStatement, "void test() { [[100+100;]] test(); }",
diff --git a/clang/unittests/Tooling/Syntax/SynthesisTest.cpp b/clang/unittests/Tooling/Syntax/SynthesisTest.cpp
index be8851267532ca..ccfdcd05c78482 100644
--- a/clang/unittests/Tooling/Syntax/SynthesisTest.cpp
+++ b/clang/unittests/Tooling/Syntax/SynthesisTest.cpp
@@ -38,8 +38,11 @@ class SynthesisTest : public SyntaxTreeTest {
}
};
-INSTANTIATE_TEST_SUITE_P(SynthesisTests, SynthesisTest,
- ::testing::ValuesIn(allTestClangConfigs()) );
+INSTANTIATE_TEST_SUITE_P(
+ SynthesisTests, SynthesisTest, ::testing::ValuesIn(allTestClangConfigs()),
+ [](const testing::TestParamInfo<TestClangConfig> &Info) {
+ return Info.param.toShortString();
+ });
TEST_P(SynthesisTest, Leaf_Punctuation) {
buildTree("", GetParam());
diff --git a/clang/unittests/Tooling/Syntax/TreeTest.cpp b/clang/unittests/Tooling/Syntax/TreeTest.cpp
index 44cf42fa944a2b..b553f704ae00cd 100644
--- a/clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -103,8 +103,11 @@ class TreeTest : public SyntaxTreeTest {
}
};
-INSTANTIATE_TEST_SUITE_P(TreeTests, TreeTest,
- ::testing::ValuesIn(allTestClangConfigs()) );
+INSTANTIATE_TEST_SUITE_P(
+ TreeTests, TreeTest, ::testing::ValuesIn(allTestClangConfigs()),
+ [](const testing::TestParamInfo<TestClangConfig> &Info) {
+ return Info.param.toShortString();
+ });
TEST_P(TreeTest, FirstLeaf) {
buildTree("", GetParam());
@@ -221,8 +224,11 @@ class ListTest : public SyntaxTreeTest {
}
};
-INSTANTIATE_TEST_SUITE_P(TreeTests, ListTest,
- ::testing::ValuesIn(allTestClangConfigs()) );
+INSTANTIATE_TEST_SUITE_P(
+ TreeTests, ListTest, ::testing::ValuesIn(allTestClangConfigs()),
+ [](const testing::TestParamInfo<TestClangConfig> &Info) {
+ return Info.param.toShortString();
+ });
/// "a, b, c" <=> [("a", ","), ("b", ","), ("c", null)]
TEST_P(ListTest, List_Separated_WellFormed) {
diff --git a/clang/unittests/Tooling/Syntax/TreeTestBase.cpp b/clang/unittests/Tooling/Syntax/TreeTestBase.cpp
index f387b503f33681..14c446c199906e 100644
--- a/clang/unittests/Tooling/Syntax/TreeTestBase.cpp
+++ b/clang/unittests/Tooling/Syntax/TreeTestBase.cpp
@@ -48,8 +48,11 @@ ArrayRef<syntax::Token> tokens(syntax::Node *N,
std::vector<TestClangConfig> clang::syntax::allTestClangConfigs() {
std::vector<TestClangConfig> all_configs;
- for (TestLanguage lang : {Lang_C89, Lang_C99, Lang_CXX03, Lang_CXX11,
- Lang_CXX14, Lang_CXX17, Lang_CXX20}) {
+ for (TestLanguage lang : {
+#define TESTLANGUAGE(lang, version, std_flag, version_index) \
+ Lang_##lang##version,
+#include "clang/Testing/TestLanguage.def"
+ }) {
TestClangConfig config;
config.Language = lang;
config.Target = "x86_64-pc-linux-gnu";
>From d6613969cf5e893b4677c30236618f616a83e420 Mon Sep 17 00:00:00 2001
From: Julian Schmidt <git.julian.schmidt at gmail.com>
Date: Fri, 12 Jul 2024 23:19:33 +0200
Subject: [PATCH 2/5] add macro description
---
clang/include/clang/Testing/TestLanguage.def | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/clang/include/clang/Testing/TestLanguage.def b/clang/include/clang/Testing/TestLanguage.def
index 88155a3e3d9204..7f033eb441ae96 100644
--- a/clang/include/clang/Testing/TestLanguage.def
+++ b/clang/include/clang/Testing/TestLanguage.def
@@ -7,6 +7,13 @@
//
//===----------------------------------------------------------------------===//
+// The TESTLANGUAGE(-C/-CXX) macros have four parameters:
+// the language, the standard version, the corresponding compile-flag,
+// and an index of the language version for each language.
+// The standard version is used to compare a standard version numerically,
+// and the index is used to impose ordering for the language versions
+// with respect to each language.
+
#ifndef TESTLANGUAGE
#error "TESTLANGUAGE must be defined before including this file"
#endif
>From 4da7732ebb70e76a2a604e04ee75d93395a92bd8 Mon Sep 17 00:00:00 2001
From: Julian Schmidt <git.julian.schmidt at gmail.com>
Date: Fri, 12 Jul 2024 23:20:28 +0200
Subject: [PATCH 3/5] add c2y
---
clang/include/clang/Testing/TestLanguage.def | 1 +
1 file changed, 1 insertion(+)
diff --git a/clang/include/clang/Testing/TestLanguage.def b/clang/include/clang/Testing/TestLanguage.def
index 7f033eb441ae96..2b7020a1c8c5d1 100644
--- a/clang/include/clang/Testing/TestLanguage.def
+++ b/clang/include/clang/Testing/TestLanguage.def
@@ -31,6 +31,7 @@ TESTLANGUAGE_C(C, 99, c99, 1)
TESTLANGUAGE_C(C, 11, c11, 2)
TESTLANGUAGE_C(C, 17, c17, 3)
TESTLANGUAGE_C(C, 23, c23, 4)
+TESTLANGUAGE_C(C, 26, c2y, 5)
// TESTLANGUAGE_CXX(CXX, 98, c++98, 0)
TESTLANGUAGE_CXX(CXX, 03, c++03, 1)
>From cca6b150f39995b1e325b26a3459b5e29fc25bda Mon Sep 17 00:00:00 2001
From: Julian Schmidt <git.julian.schmidt at gmail.com>
Date: Thu, 29 Aug 2024 16:51:20 +0200
Subject: [PATCH 4/5] Update clang/include/clang/Testing/TestLanguage.def
Co-authored-by: Sirraide <aeternalmail at gmail.com>
---
clang/include/clang/Testing/TestLanguage.def | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/clang/include/clang/Testing/TestLanguage.def b/clang/include/clang/Testing/TestLanguage.def
index 2b7020a1c8c5d1..ac62b176a0b87a 100644
--- a/clang/include/clang/Testing/TestLanguage.def
+++ b/clang/include/clang/Testing/TestLanguage.def
@@ -15,15 +15,15 @@
// with respect to each language.
#ifndef TESTLANGUAGE
-#error "TESTLANGUAGE must be defined before including this file"
+# define TESTLANGUAGE(...)
#endif
#ifndef TESTLANGUAGE_C
-#define TESTLANGUAGE_C TESTLANGUAGE
+# define TESTLANGUAGE_C(...) TESTLANGUAGE(__VA_ARGS__)
#endif
#ifndef TESTLANGUAGE_CXX
-#define TESTLANGUAGE_CXX TESTLANGUAGE
+# define TESTLANGUAGE_CXX(...) TESTLANGUAGE(__VA_ARGS__)
#endif
TESTLANGUAGE_C(C, 89, c89, 0)
>From 288fe931de288c58f74ca5ec1b49c2c2fa1202ba Mon Sep 17 00:00:00 2001
From: Julian Schmidt <git.julian.schmidt at gmail.com>
Date: Thu, 29 Aug 2024 16:53:16 +0200
Subject: [PATCH 5/5] Update clang/include/clang/Testing/TestClangConfig.h
Co-authored-by: Sirraide <aeternalmail at gmail.com>
---
clang/include/clang/Testing/TestClangConfig.h | 2 --
1 file changed, 2 deletions(-)
diff --git a/clang/include/clang/Testing/TestClangConfig.h b/clang/include/clang/Testing/TestClangConfig.h
index 4dd1eb9b6f39a0..c776548829fc4d 100644
--- a/clang/include/clang/Testing/TestClangConfig.h
+++ b/clang/include/clang/Testing/TestClangConfig.h
@@ -29,10 +29,8 @@ struct TestClangConfig {
bool isC() const {
return false
-#define TESTLANGUAGE
#define TESTLANGUAGE_C(lang, version, std_flag, version_index) \
|| Language == Lang_##lang##version
-#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index)
#include "clang/Testing/TestLanguage.def"
;
}
More information about the cfe-commits
mailing list