Skip to content

Commit 339ed1e

Browse files
committed
Move TestClangConfig into libClangTesting and use it in AST Matchers tests
Summary: Previously, AST Matchers tests were using a custom way to run a test with a specific C++ standard version. I'm migrating them to a shared infrastructure to specify a Clang target from libClangTesting. I'm also changing tests for AST Matchers to run in multiple language standards versions, and under multiple triples that have different behavior with regards to templates. To keep the size of the patch manageable, in this patch I'm only migrating one file to get the process started and get feedback on this approach. One caveat is that increasing the number of test configuration does significantly increase the runtime of AST Matchers tests. On my machine, the test runtime increases from 2.0 to 6.0s. I think it is worth the improved test coverage. Reviewers: jdoerfert, ymandel Reviewed By: ymandel Subscribers: gribozavr2, jfb, sstefan1, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D82179
1 parent 973685f commit 339ed1e

File tree

4 files changed

+944
-423
lines changed

4 files changed

+944
-423
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
//===--- TestClangConfig.h ------------------------------------------------===//
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+
#ifndef LLVM_CLANG_TESTING_TESTCLANGCONFIG_H
10+
#define LLVM_CLANG_TESTING_TESTCLANGCONFIG_H
11+
12+
#include "clang/Testing/CommandLineArgs.h"
13+
#include "llvm/Support/raw_ostream.h"
14+
#include <string>
15+
#include <vector>
16+
17+
namespace clang {
18+
19+
/// A Clang configuration for end-to-end tests that can be converted to
20+
/// command line arguments for the driver.
21+
///
22+
/// The configuration is represented as typed, named values, making it easier
23+
/// and safer to work with compared to an array of string command line flags.
24+
struct TestClangConfig {
25+
TestLanguage Language;
26+
27+
/// The argument of the `-target` command line flag.
28+
std::string Target;
29+
30+
bool isC() const { return Language == Lang_C89 || Language == Lang_C99; }
31+
32+
bool isC99OrLater() const { return Language == Lang_C99; }
33+
34+
bool isCXX() const {
35+
return Language == Lang_CXX03 || Language == Lang_CXX11 ||
36+
Language == Lang_CXX14 || Language == Lang_CXX17 ||
37+
Language == Lang_CXX20;
38+
}
39+
40+
bool isCXX11OrLater() const {
41+
return Language == Lang_CXX11 || Language == Lang_CXX14 ||
42+
Language == Lang_CXX17 || Language == Lang_CXX20;
43+
}
44+
45+
bool isCXX14OrLater() const {
46+
return Language == Lang_CXX14 || Language == Lang_CXX17 ||
47+
Language == Lang_CXX20;
48+
}
49+
50+
bool isCXX17OrLater() const {
51+
return Language == Lang_CXX17 || Language == Lang_CXX20;
52+
}
53+
54+
bool supportsCXXDynamicExceptionSpecification() const {
55+
return Language == Lang_CXX03 || Language == Lang_CXX11 ||
56+
Language == Lang_CXX14;
57+
}
58+
59+
bool hasDelayedTemplateParsing() const {
60+
return Target == "x86_64-pc-win32-msvc";
61+
}
62+
63+
std::vector<std::string> getCommandLineArgs() const {
64+
std::vector<std::string> Result = getCommandLineArgsForTesting(Language);
65+
Result.push_back("-target");
66+
Result.push_back(Target);
67+
return Result;
68+
}
69+
70+
std::string toString() const {
71+
std::string Result;
72+
llvm::raw_string_ostream OS(Result);
73+
OS << "{ Language=" << Language << ", Target=" << Target << " }";
74+
return OS.str();
75+
}
76+
77+
friend std::ostream &operator<<(std::ostream &OS,
78+
const TestClangConfig &ClangConfig) {
79+
return OS << ClangConfig.toString();
80+
}
81+
};
82+
83+
} // end namespace clang
84+
85+
#endif

0 commit comments

Comments
 (0)