[all-commits] [llvm/llvm-project] a7691d: [Testing] TestAST, a helper for writing straight-l...
Sam McCall via All-commits
all-commits at lists.llvm.org
Thu Apr 21 12:47:02 PDT 2022
Author: Sam McCall <sam.mccall at gmail.com>
Date: 2022-04-21 (Thu, 21 Apr 2022)
[Testing] TestAST, a helper for writing straight-line AST tests
Tests that need ASTs have to deal with the awkward control flow of
FrontendAction in some way. There are a few idioms used:
- don't bother with unit tests, use clang -dump-ast
- create an ASTConsumer by hand, which is bulky
- use ASTMatchFinder - works pretty well if matchers are actually
needed, very strange if they are not
- use ASTUnit - this yields nice straight-line code, but ASTUnit is a
terrifically complicated library not designed for this purpose
TestAST provides a very simple way to write straight-line tests: specify
the code/flags and it provides an AST that is kept alive until the
object is destroyed.
It's loosely modeled after TestTU in clangd, which we've successfully
used for a variety of tests.
I've updated a couple of clang tests to use this helper, IMO they're clearer.
Differential Revision: https://reviews.llvm.org/D123668
More information about the All-commits