Skip to content

Commit

Permalink
Move TestClangConfig into libClangTesting and use it in AST Matchers …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
gribozavr committed Jun 29, 2020
1 parent 973685f commit 339ed1e
Show file tree
Hide file tree
Showing 4 changed files with 944 additions and 423 deletions.
85 changes: 85 additions & 0 deletions clang/include/clang/Testing/TestClangConfig.h
@@ -0,0 +1,85 @@
//===--- TestClangConfig.h ------------------------------------------------===//
//
// 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 LLVM_CLANG_TESTING_TESTCLANGCONFIG_H
#define LLVM_CLANG_TESTING_TESTCLANGCONFIG_H

#include "clang/Testing/CommandLineArgs.h"
#include "llvm/Support/raw_ostream.h"
#include <string>
#include <vector>

namespace clang {

/// A Clang configuration for end-to-end tests that can be converted to
/// command line arguments for the driver.
///
/// The configuration is represented as typed, named values, making it easier
/// and safer to work with compared to an array of string command line flags.
struct TestClangConfig {
TestLanguage Language;

/// 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;
}

bool isCXX11OrLater() const {
return Language == Lang_CXX11 || Language == Lang_CXX14 ||
Language == Lang_CXX17 || Language == Lang_CXX20;
}

bool isCXX14OrLater() const {
return Language == Lang_CXX14 || Language == Lang_CXX17 ||
Language == Lang_CXX20;
}

bool isCXX17OrLater() const {
return Language == Lang_CXX17 || Language == Lang_CXX20;
}

bool supportsCXXDynamicExceptionSpecification() const {
return Language == Lang_CXX03 || Language == Lang_CXX11 ||
Language == Lang_CXX14;
}

bool hasDelayedTemplateParsing() const {
return Target == "x86_64-pc-win32-msvc";
}

std::vector<std::string> getCommandLineArgs() const {
std::vector<std::string> Result = getCommandLineArgsForTesting(Language);
Result.push_back("-target");
Result.push_back(Target);
return Result;
}

std::string toString() const {
std::string Result;
llvm::raw_string_ostream OS(Result);
OS << "{ Language=" << Language << ", Target=" << Target << " }";
return OS.str();
}

friend std::ostream &operator<<(std::ostream &OS,
const TestClangConfig &ClangConfig) {
return OS << ClangConfig.toString();
}
};

} // end namespace clang

#endif

0 comments on commit 339ed1e

Please sign in to comment.